
are different. Windows will send the space character
0 20 after the ~ in the second e ample. From within a
program, it’s sometimes desirable to use write(port, str,
strlen(str)) instead of fprintf() which will buffer the
output string.
3. Again, only one port can “listen” at a time. You may
transmit simultaneously to multiple ports.
Communicatin from
Communicatin from Communicatin from
Communicatin from Pro rams
Pro ramsPro rams
Pro rams
In Windows, you can configure a serial port using the mode
command in a system() function call:
system( "mode com1: baud 9600 parity n data 8
stop 1" )
Type mode /? in at command line prompt for full
details. Once a port is set up, a com port can be
opened as a stream I/O device using stdio:
char menuresponse[128] ;
FILE* portfp fopen( "com1:", "w+" ) ;
fprintf( portfp, "~" ) ; /*send tilde */
Delay (500); /* wait 500ms */
fprintf( portfp, "~" ) ; /*send second tilde */
fgets( menuresponse, sizeof( response ), portfp ) ;
/* you’re in to the menu, send commands next */
printf( menuresponse ) ;
You can also use C++ fstream I/O. The Win32 API has
comprehensive low level functions for serial I/O, but the
simpler stdio function works for many applications. For
information on W32 serial communications, see:
http://msdn.microsoft.com/library/default.asp?url=/library/en
-us/dnfiles/html/msdn_serial.asp
For Linu serial communications, try:
http://www.atnf.csiro.au/people/rgooch/linu /docs/devfs.html