Mail Archives: cygwin/1997/05/23/21:12:02
On 21 May 97 at 14:09, Bart Anderson wrote:
> With this mixed bag of unix/dos/win calls, how should/may the serial
> ports be accessed. I've tried /dev/cua0 and com1 and com1:. I've
> tried using mount with bash to get com1: seen as /dev/cua0. Any help
> would be appreciated. If there are 2 methods with different library
> calls, I'd appreciate both just to see how it's done.
At least for WIN32 API it is done as follows:
8.4. Work with serial lines.
8.4.1. Initialzation.
#ifndef WIN32
serial_port = open("/dev/tty00", O_RDWR);
/* ------------------- Set paprameters for serial port /dev/tty00 -------- */
rc = system("stty -f /dev/tty00 tab0 bs0 vt0 ff0 -isig -icanon -iexten");
rc = system("stty -f /dev/tty00 -echo -echoe -echok -echonl -noflsh");
#else
/* ------------------- Set paprameters for serial port com2 -------- */
{
DCB Com2Dcb;
COMMTIMEOUTS TimeOut;
int exterr;
serial_port = CreateFile("com2:", // pointer to name of the file
GENERIC_READ | GENERIC_WRITE, // access (read-write) mode
0, // share mode
NULL, // pointer to security descriptor
OPEN_EXISTING, // how to create
FILE_FLAG_NO_BUFFERING, // file attributes
NULL // handle to file with attributes to copy
);
if ( serial_port == INVALID_HANDLE_VALUE) {
exterr = GetLastError();
printf(" Can not open com port . err code= %x \n", exterr);
return exterr;
}
GetCommState(serial_port, &Com2Dcb);
if (Com2Dcb.BaudRate != 9600)
Com2Dcb.BaudRate = 9600; // current baud rate
if (Com2Dcb.Parity)
Com2Dcb.Parity = NOPARITY; // 0-4=no,odd,even,mark,space
if (Com2Dcb.StopBits != 1)
Com2Dcb.StopBits = ONESTOPBIT; // 0,1,2 = 1, 1.5, 2
if (Com2Dcb.ByteSize != 8)
Com2Dcb.ByteSize = 8; // number of bits/byte, 4-8
SetCommState(serial_port, &Com2Dcb);
// Timeout = (MULTIPLIER * number_of_bytes) + CONSTANT
TimeOut.ReadIntervalTimeout = 0;
TimeOut.ReadTotalTimeoutMultiplier = 0;
TimeOut.ReadTotalTimeoutConstant = 0;
TimeOut.WriteTotalTimeoutMultiplier = 0;
TimeOut.WriteTotalTimeoutConstant = 0;
SetCommTimeouts(serial_port, &TimeOut);
}
rc = 0;
#endif
8.4.2. Error handling
If ReadFile/WriteFile WIN32 API return the code TRUE
and the nBytesToBeSent (3d par) is more the nByteSent
(4th par)this means the Time Out event has been occured.
ZERO TimeOut value means "No Time Out Events"
=================================================================
Dr. Valery Fine Telex : 911621 dubna su
-----------
LCTA/Joint Inst.for NuclearRes Phone : +7 09621 6 40 80
141980 Dubna, Moscow region Fax : +7 09621 6 51 45
Russia mailto:fine AT main1 DOT jinr DOT dubna DOT su
Dr. Valeri Faine
------------ Phone: +41 22 767 6468
CERN FAX : +41 22 767 7910
CH-1211 Geneva, 23 mailto:fine AT mail DOT cern DOT ch
Switzerland http://nicewww.cern.ch/~fine
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request AT cygnus DOT com" with one line of text: "help".
- Raw text -