• Advertisement
Sign in to follow this  

serial port communication!

This topic is 4446 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
Which OS? Under WIndows you would use CreateFile for opening the port and WriteFile/ReadFile for sending and receiving data.
Otherwise you would use the standard file functions like _open, _read and _write.

HTH,
Pat.

Share this post


Link to post
Share on other sites
It is simple, working example, but read little more about COM, sometimes it is rather strange device :)


DCB dcb;
COMMTIMEOUTS ct;
HANDLE port;

dcb.DCBlength = sizeof( DCB );
BuildCommDCB( "baud=9600 parity=N data=8 stop=1", &dcb );
dcb.fNull = TRUE;
dcb.fOutxCtsFlow = 0; // No CTS output flow control
dcb.fOutxDsrFlow = 0; // No DSR output flow control

ct.ReadIntervalTimeout = 10; // Timeout between 2 bytes
ct.ReadTotalTimeoutMultiplier = ct.ReadTotalTimeoutConstant = 0;
ct.WriteTotalTimeoutMultiplier = ct.WriteTotalTimeoutConstant = 0;

port = CreateFile( "COM1", GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL );

SetCommState( port, &dcb );
SetCommTimeouts( port, &ct );

WriteFile( port, "XEP", 3, &bc, NULL );
ReadFile( port, buffer, 1, &bc, NULL ); // Eat ACK

CloseHandle( port );



Lekha

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement