serial port communication!

Started by
3 comments, last by Vasialek 18 years, 4 months ago
how to communicate the port in API?
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.
See General Terminal Interface
Free Mac Mini (I know, I'm a tool)
thank you ,my operational system is winXP
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 controldcb.fOutxDsrFlow = 0;			// No DSR output flow controlct.ReadIntervalTimeout = 10;		// Timeout between 2 bytesct.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 ACKCloseHandle( port );


Lekha

This topic is closed to new replies.

Advertisement