From: Valeri DOT Faine AT cern DOT ch ("Valery Fine") Subject: Re: serial access 23 May 1997 21:12:02 -0700 Sender: mail AT cygnus DOT com Approved: cygnus DOT gnu-win32 AT cygnus DOT com Distribution: cygnus Message-ID: <199705221301.PAA99020.cygnus.gnu-win32@sp063.cern.ch> Reply-To: Valeri DOT Faine AT cern DOT ch Comments: Authenticated sender is Original-To: Bart Anderson , banders AT switch DOT rockwell DOT com, gnu-win32 AT cygnus DOT com X-Confirm-Reading-To: fine AT mail DOT cern DOT ch X-pmrqc: 1 In-reply-to: <3383486E.6781@switch.rockwell.com> X-mailer: Pegasus Mail for Win32 (v2.53/R1) Original-Sender: owner-gnu-win32 AT cygnus DOT com 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".