cygwin 1.5.23-2 : CREAD termios option don't work

2007-01-11 Thread Florent Morin

Hello,

I actually develop a program in C for reading and writing data on
serial port. It works fine on GNU/Linux. I now test it with cygwin
(Windows XP).

I begin to set the port options, then I read/write information and
restore port settings. I can write on serial port but can't read.

For testing, I have tried with a working program : stty. It works fine
with all options, but not with CREAD.

$ stty cread < /dev/ttyS0
stty: /dev/ttyS0: unable to perform all requested operations

Can someone explain this ?

I use cygwin 1.5.23-2 on Windows XP SP2.

Thanks,

Florent

--
Unsubscribe info:  http://cygwin.com/ml/#unsubscribe-simple
Problem reports:   http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ:   http://cygwin.com/faq/



Re: cygwin 1.5.23-2 : CREAD termios option don't work

2007-01-17 Thread Florent Morin

Hello,

Like you say, CREAD isn't the real problem.

I use select() to read/write socket and read/write serial. But, after
writing the content of socket on serial port, I can't read serial port
(access denied).

This is an extract of my source code :

 CODE -

   int serial_fd;
   int max_fd;

   unsigned char buffer[MAX_CANON];
   int size;
   int converted_size;

   unsigned char buffer2[MAX_CANON];
   int size2;

   fd_set read_set;
   fd_set write_set;

   nice(15);

   /* opening serial port read/write, non-block */
   serial_fd = open ( port_settings->device,
  O_NONBLOCK | O_RDWR | O_NOCTTY);

   max_fd = socket_fd < serial_fd ? serial_fd : socket_fd;

   alarm(ALARM_TIMEOUT);

   while (1) {
   FD_ZERO(&read_set);
   FD_SET(socket_fd, &read_set);
   FD_SET(serial_fd, &read_set);

   FD_ZERO(&write_set);
   FD_SET(socket_fd, &write_set);
   FD_SET(serial_fd, &write_set);

   if ( select(max_fd + 1,
   &read_set,
   &write_set,
   NULL,
   NULL) < 0)
   perror("select");

   if (FD_ISSET(socket_fd, &read_set)
&& !FD_ISSET(serial_fd, &read_set)
&& FD_ISSET(serial_fd, &write_set)) {
   alarm(0);
   memset(&buffer, 0, MAX_CANON);
   size = read(socket_fd, buffer, MAX_CANON - 1);
   converted_size = convert_telnet(&buffer, size);
   while (write(serial_fd, buffer, converted_size) < 0) {
   if (errno == EAGAIN) {
   error("write", 0);
   sleep(1);
   } else
   error("write", 1);
   }
   alarm(ALARM_TIMEOUT);
   }

   if (FD_ISSET(serial_fd, &read_set)
&& FD_ISSET(socket_fd, &write_set)) {
   alarm(0);
   memset(&buffer2, 0, MAX_CANON);
   printf("read serial");
   size2 = read(serial_fd, buffer2, MAX_CANON - 1);
   if (size2 > 0) {
   while (write(socket_fd, buffer2, size2) < 0) {
   if (errno == EAGAIN) {
   error("write", 0);
   sleep(1);
   } else
   error("write", 1);
   }
   }
   alarm(ALARM_TIMEOUT);
   }

   sleep(1);

   }

   close(serial_fd);

 /CODE -

I have tested it on Linux. It works fine. When I send data throw
telnet protocol, the data are received by the peripheral connected to
serial and vice-versa.

Perhaps I don't use the functions very well. So, if you can help me, thanks.

Florent Morin.


2007/1/12, Brian Ford <[EMAIL PROTECTED]>:

On Fri, 12 Jan 2007, Corinna Vinschen wrote:
> On Jan 11 16:53, Florent Morin wrote:
> > For testing, I have tried with a working program : stty. It works fine
> > with all options, but not with CREAD.
> >
> > $ stty cread < /dev/ttyS0
> > stty: /dev/ttyS0: unable to perform all requested operations
> >
> > Can someone explain this ?
>
> Please consider to debug this yourself.  Cygwin has no volunteer which
> is fluent with serial I/O right now.

This is not a regression from 1.5.18, which I know worked fine with serial
I/O.  I will try to test 1.5.23 when I get a chance, but I have no reason
to suspect it is broken.

CREAD appears to always be enabled but not indicated by tcgetattr or
controllable via tcsetattr right now.  So, the test case above is not
indicative of the original problem.

To the OP, posting your code might be informative.

--
Brian Ford
Lead Realtime Software Engineer
VITAL - Visual Simulation Systems
FlightSafety International
the best safety device in any aircraft is a well-trained crew...



--
Unsubscribe info:  http://cygwin.com/ml/#unsubscribe-simple
Problem reports:   http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ:   http://cygwin.com/faq/




--
Unsubscribe info:  http://cygwin.com/ml/#unsubscribe-simple
Problem reports:   http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ:   http://cygwin.com/faq/



Re: cygwin 1.5.23-2 : CREAD termios option don't work

2007-01-18 Thread Florent Morin

It compiles but it don't work fine. I want it to works with pseudo-terminals.

2007/1/17, Dave Korn <[EMAIL PROTECTED]>:

On 17 January 2007 14:38, Florent Morin wrote:


> I use select() to read/write socket and read/write serial. But, after
> writing the content of socket on serial port, I can't read serial port
> (access denied).


> I have tested it on Linux. It works fine. When I send data throw
> telnet protocol, the data are received by the peripheral connected to
> serial and vice-versa.
>
> Perhaps I don't use the functions very well. So, if you can help me, thanks.


  :)  ser2net compiles on cygwin OOTB.


cheers,
  DaveK
--
Can't think of a witty .sigline today


--
Unsubscribe info:  http://cygwin.com/ml/#unsubscribe-simple
Problem reports:   http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ:   http://cygwin.com/faq/




--
Unsubscribe info:  http://cygwin.com/ml/#unsubscribe-simple
Problem reports:   http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ:   http://cygwin.com/faq/



cygwin 1.5.23-2 : I can't use select() with serial device and socket

2007-01-18 Thread Florent Morin

Hello,

I have a problem using cygwin. My program does this :
- It accept a socket connection,
- it listen on it,
- it open serial device read/write (O_RDWR),
- it create 2 fd_sets,
- listening loop :
 - adding file descriptors to sets,
 - call select(),
 - if something is on serial port, I write it to socket,
 - if something is on socket, i write it to serial

It works fine on Linux.

With windows, only read or write works fine.

If I begin on reading on serial, I can't write after (access denied).
If I begin on writing on serial, I can't read after (access denied).

If someone have a solution, thanks to help me, please...

--
Unsubscribe info:  http://cygwin.com/ml/#unsubscribe-simple
Problem reports:   http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ:   http://cygwin.com/faq/



Re: cygwin 1.5.23-2 : I can't use select() with serial device and socket

2007-01-18 Thread Florent Morin

I use unix names. I will post an example code tomorrow.

2007/1/18, Brian Dessent <[EMAIL PROTECTED]>:

Florent Morin wrote:

> I have a problem using cygwin. My program does this :
> - It accept a socket connection,
> - it listen on it,
> - it open serial device read/write (O_RDWR),
> - it create 2 fd_sets,
> - listening loop :
>   - adding file descriptors to sets,
>   - call select(),
>   - if something is on serial port, I write it to socket,
>   - if something is on socket, i write it to serial
>
> It works fine on Linux.
>
> With windows, only read or write works fine.
>
> If I begin on reading on serial, I can't write after (access denied).
> If I begin on writing on serial, I can't read after (access denied).

There's probably not enough information here to help.  It would be
easier if you provided a simplified standalone testcase that we can
compile and run.  Are you opening the serial device using the standard
unix name (/dev/ttyS0) and not the DOS name ("COM1")?  The latter will
succeed but probably not work with things like ioctl or select, because
in order to emulate those APIs Cygwin has to know to treat the handle
specifically as a serial device, which it only does if you open it using
the unix form.

Brian

--
Unsubscribe info:  http://cygwin.com/ml/#unsubscribe-simple
Problem reports:   http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ:   http://cygwin.com/faq/




--
Unsubscribe info:  http://cygwin.com/ml/#unsubscribe-simple
Problem reports:   http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ:   http://cygwin.com/faq/



Re: cygwin 1.5.23-2 : I can't use select() with serial device and socket

2007-01-19 Thread Florent Morin

This code works fine on Linux and Cygwin (Windows XP SP2) :

--- CODE

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

#define BUFFER_SIZE 256
#define DEVICE  "/dev/ttyS0"
#define TO_WRITE"test communication"

int main (void)
{
   char buffer_read[BUFFER_SIZE];
   int data_read;

   char buffer_write[BUFFER_SIZE] = TO_WRITE;
   int data_write;

   int serial_fd;

   serial_fd = open(DEVICE, O_NONBLOCK | O_NOCTTY | O_RDWR);

   if (serial_fd < 0) {
   perror("open");
   return EXIT_FAILURE;
   } else
   printf("Serial port opened.\n");


   printf("Begin writing %s...\n", buffer_write);

   data_write = write(serial_fd, buffer_write, strlen(buffer_write));

   if (data_write < 0)
   perror("write");
   else
   printf("%d caracters written.\n", data_write);

   memset(&buffer_read, 0, BUFFER_SIZE);

   printf("Begin reading...\n");

   while ((data_read = read(serial_fd,
buffer_read,
BUFFER_SIZE - 1)) < 0) {
   if (errno == EAGAIN)
   memset(&buffer_read, 0, BUFFER_SIZE);
   else {
   perror("read");
   return EXIT_FAILURE;
   }
   }

   if (data_read < 0)
   perror("read");
   else
   printf("Data readed (%d) : %s\n", data_read, buffer_read);


   close(serial_fd);

   return EXIT_SUCCESS;
}

-- /CODE


This code works fine on Linux but doesn't work on Cygwin :

-- CODE
---

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

#define BUFFER_SIZE 256
#define DEVICE  "/dev/ttyS0"
#define TO_WRITE"test communication"

int main (void)
{
   char buffer_read[BUFFER_SIZE];
   int data_read;

   char buffer_write[BUFFER_SIZE] = TO_WRITE;
   int data_write;

   int serial_fd;

   serial_fd = open(DEVICE, O_NONBLOCK | O_NOCTTY | O_RDWR);

   if (serial_fd < 0) {
   perror("open");
   return EXIT_FAILURE;
   } else
   printf("Serial port opened.\n");


   printf("Begin writing %s...\n", buffer_write);

   data_write = write(serial_fd, buffer_write, strlen(buffer_write));

   if (data_write < 0)
   perror("write");
   else
   printf("%d caracters written.\n", data_write);

   memset(&buffer_read, 0, BUFFER_SIZE);

   printf("Begin reading...\n");

   while ((data_read = read(serial_fd,
buffer_read,
BUFFER_SIZE - 1)) < 0) {
   if (errno == EAGAIN)
   memset(&buffer_read, 0, BUFFER_SIZE);
   else {
   perror("read");
   return EXIT_FAILURE;
   }
   }

   if (data_read < 0)
   perror("read");
   else
   printf("Data readed (%d) : %s\n", data_read, buffer_read);


   close(serial_fd);

   return EXIT_SUCCESS;
}



-------- /CODE
--

The second code write on socket, but it says that serial port isn't
ready to read.

Can someone explain it to me ?

Thanks.

Florent.

2007/1/18, Florent Morin <[EMAIL PROTECTED]>:

I use unix names. I will post an example code tomorrow.

2007/1/18, Brian Dessent <[EMAIL PROTECTED]>:
> Florent Morin wrote:
>
> > I have a problem using cygwin. My program does this :
> > - It accept a socket connection,
> > - it listen on it,
> > - it open serial device read/write (O_RDWR),
> > - it create 2 fd_sets,
> > - listening loop :
> >   - adding file descriptors to sets,
> >   - call select(),
> >   - if something is on serial port, I write it to socket,
> >   - if something is on socket, i write it to serial
> >
> > It works fine on Linux.
> >
> > With windows, only read or write works fine.
> >
> > If I begin on reading on serial, I can't write after (access denied).
> > If I begin on writing on serial, I can't read after (access denied).
>
> There's probably not enough information here to help.  It would be
> easier if you provided a simplified standalone testcase that we can
> compile and run.  Are you opening the serial device using the standard
> unix name (/dev/ttyS0) and not the DOS name ("COM1")?  The latter will
> succeed but probably not work with things like ioctl or select, because
> in order to emulate those APIs Cygwin has to know to treat the handle
> specifically as a se

Re: cygwin 1.5.23-2 : I can't use select() with serial device and socket

2007-01-19 Thread Florent Morin

Excuse me, this is my second code :

- CODE
--

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

#define BUFFER_SIZE 256
#define DEVICE  "/dev/ttyS0"
#define TO_WRITE"test communication\n"

int main (void)
{
   char buffer_read[BUFFER_SIZE];
   int data_read;

   char buffer_write[BUFFER_SIZE] = TO_WRITE;
   int data_write;

   int serial_fd;

   fd_set read_set;
   fd_set write_set;

   int written = 0;

   serial_fd = open(DEVICE, O_NONBLOCK | O_NOCTTY | O_RDWR);

   if (serial_fd < 0) {
   perror("open");
   return EXIT_FAILURE;
   } else
   printf("Serial port opened.\n");

   while (1) {
   FD_ZERO(&read_set);
   FD_SET(serial_fd, &read_set);

   FD_ZERO(&write_set);
   FD_SET(serial_fd, &write_set);

   if (select(serial_fd + 1,
  &read_set,
  &write_set,
  NULL,
  NULL) < 0) {
   perror("select");
   return EXIT_FAILURE;
   }

   if (FD_ISSET(serial_fd, &read_set)) {

   memset(&buffer_read, 0, BUFFER_SIZE);

   printf("Begin reading...\n");

   while ((data_read = read(serial_fd,
buffer_read,
BUFFER_SIZE - 1)) < 0) {
   if (errno == EAGAIN)
   memset(&buffer_read, 0, BUFFER_SIZE);
   else {
   perror("read");
   return EXIT_FAILURE;
   }
   }

   if (data_read < 0)
   perror("read");
   else
   printf("Data readed (%d) : %s\n", data_read, buffer_read);
   } else
   printf("Serial port not ready to read.\n");

   if ((FD_ISSET(serial_fd, &write_set)) && (written == 0)) {
   printf("Begin writing %s...\n", buffer_write);
   written = 1;
   data_write = write(serial_fd, buffer_write, strlen(buffer_write));
   if (data_write < 0)
   perror("write");
   else
   printf("%d caracters written.\n", data_write);
   } else {
   if (FD_ISSET(serial_fd, &write_set))
   printf("Serial port ready to write but no.\n");
   else
   printf("Serial port not ready to write.\n");
   }

   printf("\n-\n");
   sleep(1);
   }

   close(serial_fd);

   return EXIT_SUCCESS;
}


--- /CODE
-

Thanks,

Florent

--
Unsubscribe info:  http://cygwin.com/ml/#unsubscribe-simple
Problem reports:   http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ:   http://cygwin.com/faq/