comp.lang.ada
 help / color / mirror / Atom feed
* Could someone teach me how to use windows API serial port calls.
@ 2002-04-12 19:47 Jamie
  2002-04-12 22:22 ` Dan Andreatta
  0 siblings, 1 reply; 3+ messages in thread
From: Jamie @ 2002-04-12 19:47 UTC (permalink / raw)


Hi, there:

I'm doing a project that needs an ada program under win2000 to control
a machine over RS232 serial line. I wonder if there are someone would
like teach me how to use windows API serial port calls to do it. since
i'm a beginner of programing, i think I need some detailed examples if
you could provide.

Thanks in advance.



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Could someone teach me how to use windows API serial port calls.
  2002-04-12 19:47 Could someone teach me how to use windows API serial port calls Jamie
@ 2002-04-12 22:22 ` Dan Andreatta
  2002-04-12 22:31   ` [OT] Serial comm in Win using C [Re: Could someone teach me how to use windows API serial port calls.] Dan Andreatta
  0 siblings, 1 reply; 3+ messages in thread
From: Dan Andreatta @ 2002-04-12 22:22 UTC (permalink / raw)


kz105@student.cs.york.ac.uk (Jamie) wrote in 
news:ba071575.0204121147.71bee262@posting.google.com:

> Hi, there:
> 
> I'm doing a project that needs an ada program under win2000 to control
> a machine over RS232 serial line. I wonder if there are someone would
> like teach me how to use windows API serial port calls to do it. since
> i'm a beginner of programing, i think I need some detailed examples if
> you could provide.
> 
> Thanks in advance.
> 

http://msdn.microsoft.com/library/default.asp?url=/library/en-
us/dnwbgen/html/msdn_serial.asp



^ permalink raw reply	[flat|nested] 3+ messages in thread

* [OT] Serial comm in Win using C [Re: Could someone teach me how to use windows API serial port calls.]
  2002-04-12 22:22 ` Dan Andreatta
@ 2002-04-12 22:31   ` Dan Andreatta
  0 siblings, 0 replies; 3+ messages in thread
From: Dan Andreatta @ 2002-04-12 22:31 UTC (permalink / raw)


Dan Andreatta <andreatta@mail.chem.sc.edu.REMOVEME> wrote in 
news:Xns91EEB1107559Eandreattamailchemsce@12.252.202.62:

> kz105@student.cs.york.ac.uk (Jamie) wrote in 
> news:ba071575.0204121147.71bee262@posting.google.com:
> 
>> Hi, there:
>> 
>> I'm doing a project that needs an ada program under win2000 to control
>> a machine over RS232 serial line. I wonder if there are someone would
>> like teach me how to use windows API serial port calls to do it. since
>> i'm a beginner of programing, i think I need some detailed examples if
>> you could provide.
>> 
>> Thanks in advance.
>> 
> 
> http://msdn.microsoft.com/library/default.asp?url=/library/en-
> us/dnwbgen/html/msdn_serial.asp

OK, I feel generous. These are quick hacks in C I used to test the 
instrument. Compiled w/ MinGW GNU/C 2.8.1 (coming with GNAT 3.13p)

// Writes to COM3 and waits an answer

#include <windows.h>
#include <stdlib.h>
#include <stdio.h>

int main()
{
	HANDLE hCom;
	DCB dcb;
	DWORD dwBytes,dwEvent;
	COMMTIMEOUTS old_ct,new_ct = {100,0,0,0};
	COMMPROP cp;
	char wbuf[] = "DT0.9;DT;";
	char rbuf[10] = "\0\0\0\0\0\0\0\0\0\0";
	
	hCom = CreateFile(
			"COM3",
			GENERIC_READ | GENERIC_WRITE,
			0,
			NULL,
			OPEN_EXISTING,
			0,
			NULL );

	GetCommState(hCom, &dcb);
	dcb.BaudRate = 9600;
	dcb.ByteSize = 8;
	dcb.Parity = NOPARITY;
	dcb.StopBits = ONESTOPBIT;
	dcb.fDtrControl = 1;
	dcb.fRtsControl = 1;
	SetCommState(hCom, &dcb);
	GetCommState(hCom, &dcb);

	//GetCommTimeouts(hCom,&old_ct);
	//SetCommTimeouts(hCom,&new_ct);
	
	//SetupComm(hCom,128,128);

	WriteFile(
			hCom,
			wbuf,
			9,
			&dwBytes,
			NULL );

	puts("Wrote DATA\n");
	Sleep(500);

	ReadFile(
			hCom,
			rbuf,
			10,
			&dwBytes,
			NULL );
	
	printf("Read %u bytes : '%s'\n",dwBytes,rbuf);

	CloseHandle(hCom);

	return EXIT_SUCCESS;
}

// Dumps the status on a serial port

#include <windows.h>
#include <stdlib.h>
#include <stdio.h>

int main()
{
	HANDLE hCom;
	DCB dcb;
	COMMPROP commprop;
	COMMTIMEOUTS timeouts;
	FILE *f;

	f=fopen("COM.txt","w");
	
	hCom = CreateFile(
			"COM1",
			GENERIC_READ | GENERIC_WRITE,
			0,
			NULL,
			OPEN_EXISTING,
			0,
			NULL );

	GetCommState(hCom, &dcb);
	GetCommTimeouts(hCom, &timeouts);
	GetCommProperties(hCom, &commprop);

	fprintf(f,"DCB Structure:\n\
	DWORD DCBlength           = %u\n\
	DWORD BaudRate            = %u\n\
	DWORD fBinary:1           = %u\n\
	DWORD fParity:1           = %u\n\
	DWORD fOutxCtsFlow:1      = %u\n\
	DWORD fOutxDsrFlow:1      = %u\n\
	DWORD fDtrControl:2       = %u\n\
	DWORD fDsrSensitivity:1   = %u\n\
	DWORD fTXContinueOnXoff:1 = %u\n\
	DWORD fOutX:1             = %u\n\
	DWORD fInX:1              = %u\n\
	DWORD fErrorChar:1        = %u\n\
	DWORD fNull:1             = %u\n\
	DWORD fRtsControl:2       = %u\n\
	DWORD fAbortOnError:1     = %u\n\
	DWORD fDummy2:17          = %u\n\
	WORD wReserved            = %u\n\
	WORD XonLim               = %u\n\
	WORD XoffLim              = %u\n\
	BYTE ByteSize             = %u\n\
	BYTE Parity               = %u\n\
	BYTE StopBits             = %u\n\
	char XonChar              = %u\n\
	char XoffChar             = %u\n\
	char ErrorChar            = %u\n\
	char EofChar              = %u\n\
	char EvtChar              = %u\n\
	WORD wReserved1;          = %u\n",
		dcb.DCBlength,
		dcb.BaudRate,            // current baud rate 
		dcb.fBinary,          // binary mode, no EOF check 
		dcb.fParity,          // enable parity checking 
		dcb.fOutxCtsFlow,      // CTS output flow control 
		dcb.fOutxDsrFlow,      // DSR output flow control 
		dcb.fDtrControl,       // DTR flow control type 
		dcb.fDsrSensitivity,   // DSR sensitivity 
		dcb.fTXContinueOnXoff, // XOFF continues Tx 
		dcb.fOutX,        // XON/XOFF out flow control 
		dcb.fInX,         // XON/XOFF in flow control 
		dcb.fErrorChar,   // enable error replacement 
		dcb.fNull,        // enable null stripping 
		dcb.fRtsControl,   // RTS flow control 
		dcb.fAbortOnError, // abort reads/writes on error 
		dcb.fDummy2,      // reserved 
		dcb.wReserved,        // not currently used 
		dcb.XonLim,           // transmit XON threshold 
		dcb.XoffLim,          // transmit XOFF threshold 
		dcb.ByteSize,         // number of bits/byte, 4-8 
		dcb.Parity,           // 0-4=no,odd,even,mark,space 
		dcb.StopBits,         // 0,1,2 = 1, 1.5, 2 
		dcb.XonChar,          // Tx and Rx XON character 
		dcb.XoffChar,         // Tx and Rx XOFF character 
		dcb.ErrorChar,        // error replacement character 
		dcb.EofChar,          // end of input character 
		dcb.EvtChar,          // received event character 
		dcb.wReserved1);       // reserved; do not use 

	fprintf(f,"\nCOMMPROP Structure:\n\
    WORD  wPacketLength       = %u
    WORD  wPacketVersion      = %u
    DWORD dwServiceMask       = %u
    DWORD dwReserved1         = %u
    DWORD dwMaxTxQueue        = %u 
    DWORD dwMaxRxQueue        = %u
    DWORD dwMaxBaud           = %u
    DWORD dwProvSubType       = %u
    DWORD dwProvCapabilities  = %u
    DWORD dwSettableParams    = %u
    DWORD dwSettableBaud      = %u
    WORD  wSettableData       = %u
    WORD  wSettableStopParity = %u
    DWORD dwCurrentTxQueue    = %u
    DWORD dwCurrentRxQueue    = %u
    DWORD dwProvSpec1         = %u
    DWORD dwProvSpec2         = %u
    WCHAR wcProvChar[1]       = %u",
    commprop.wPacketLength,
    commprop.wPacketVersion,
    commprop.dwServiceMask,
    commprop.dwReserved1,
    commprop.dwMaxTxQueue,
    commprop.dwMaxRxQueue,
    commprop.dwMaxBaud,
    commprop.dwProvSubType,
    commprop.dwProvCapabilities,
    commprop.dwSettableParams,
    commprop.dwSettableBaud,
    commprop.wSettableData,
    commprop.wSettableStopParity,
    commprop.dwCurrentTxQueue,
    commprop.dwCurrentRxQueue,
    commprop.dwProvSpec1,
    commprop.dwProvSpec2,
    commprop.wcProvChar[1]);

	printf("\
DTR_CONTROL_DISABLE   : %d\n\
DTR_CONTROL_ENABLE    : %d\n\
DTR_CONTROL_HANDSHAKE : %d\n", 
	DTR_CONTROL_DISABLE, DTR_CONTROL_ENABLE, DTR_CONTROL_HANDSHAKE);

	printf("\
RTS_CONTROL_DISABLE   : %d
RTS_CONTROL_ENABLE    : %d
RTS_CONTROL_HANDSHAKE : %d 
RTS_CONTROL_TOGGLE    : %d\n",
	RTS_CONTROL_DISABLE, RTS_CONTROL_ENABLE, 
	RTS_CONTROL_HANDSHAKE, RTS_CONTROL_TOGGLE);

	CloseHandle(hCom);
	fclose(f);
	return EXIT_SUCCESS;
}




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2002-04-12 22:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-04-12 19:47 Could someone teach me how to use windows API serial port calls Jamie
2002-04-12 22:22 ` Dan Andreatta
2002-04-12 22:31   ` [OT] Serial comm in Win using C [Re: Could someone teach me how to use windows API serial port calls.] Dan Andreatta

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox