Problem with program doing serial communication under Cygwin

Problem with program doing serial communication under Cygwin

Post by Arvind Nath Rapk » Thu, 10 Jul 2003 01:16:36



Dear colleages,

I have written a command-line program that uses the serial port (TTYS0) for
communication with an embedded device.

I need to port this program to Windows, so I tried to compile it under the
Cygwin environment. I changed the name of the serial port from '/dev/TTYS0'
to 'COM1:'.

The program compiles well, but when I start it, it terminates with an error
on the function tcgetattr(), although it goes well over opening the serial
port (see listing below). I'm getting error #25 "Not a typewriter".

Does anybody know why this is happening and can provide a solution?

Thank you very much in advance
ar

  if( (fhSerial = open(szSerialFileN,O_RDONLY)) == -1 ){
    BailOut("Unable to open the serial port!\n");
  }
  if( val == S_SET ){
    if( tcgetattr(fhSerial,&OldSerialMode) != 0 ){
/*DEBUG*/     printf("'%s' %i",strerror(errno),errno);
      BailOut("Unable to read the serial port settings!\n");
    }

 
 
 

Problem with program doing serial communication under Cygwin

Post by Lew Pitche » Fri, 11 Jul 2003 09:27:25


Without hesitation, Arvind Nath Rapka asserted (on or about 07/08/03
12:16) that:

Quote:> Dear colleages,

> I have written a command-line program that uses the serial port (TTYS0) for
> communication with an embedded device.

> I need to port this program to Windows, so I tried to compile it under the
> Cygwin environment. I changed the name of the serial port from '/dev/TTYS0'
> to 'COM1:'.

> The program compiles well, but when I start it, it terminates with an error
> on the function tcgetattr(), although it goes well over opening the serial
> port (see listing below). I'm getting error #25 "Not a typewriter".

> Does anybody know why this is happening and can provide a solution?

While Cygwin provides a Unix-like environment under Microsoft Windows,
Cygwin is neither Linux nor is it Unix. This means that your question is
misplaced when posted here.

However, if you think about it, my observation above and your observation
wrt the error tells you all you need to know.

Given that

a) Cygwin under MSWindows is not a Unix environment, and

b) When you use a terminal ioctl() on the Cygwin "COM1" device, you get the
    standard Unix error for "device does not implement terminal ioctl()
    functions" (i.e. "Not a typewriter")

we can conclude that Cygwin under MSWindows /does not/ implement enough of a
Unixish environment to permit MSWindows COM1: to be interpreted as a
character special file supporting terminal ioctl() calls.

So, your problem is with Cygwin and MSWindows. Either Cygwin doesn't
implement something correctly, or MSWindows prevents the proper implementation.

So, you can now take your question to the proper forum for answering.

--
Lew Pitcher

Master Codewright and JOAT-in-training
Registered Linux User #112576 (http://counter.li.org/)
Slackware - Because I know what I'm doing.