4
votes

I am trying to get data from a USB serial port that is connected to an Arduino. I am using Cygwin and I write

cat /dev/ttyS4

to output the data in the shell.

When I stop the process, I am given

Access Denied

when I try to access it again. I have to close Cygwin, open it again and type in the same command to get the output to the shell.

I have noticed that I am able to read the serial port from only one program. For example, if I read the data from the serial port in the Arduino Software, I can't access it in Cygwin.

Is there a way I can access the serial port data as many times as I want in Cygwin without having to have to close the program, open it again and write in the same command?

1
Under Windows a serial port accessed from a process cannot then be accessed from another process until it it closed (even if the second process is a child process of the first). This isn't the case on Unix-based systems. This suggests that stopping (Ctrl+C?) the cat /dev/ttyS4 command isn't closing the serial port...Matthew Murdoch
Is there any other way I can access the serial port multiple times without having to shut my programs, e.g. with the regular windows shell?l3win
Perhaps try within a virtual machine running some distro of Linux e.g. Ubuntu running inside VirtualBoxDavid K

1 Answers

0
votes

It appears that the statement cat /dev/ttyS4 would echo characters from the serial port until the end of the file is reached. Only, by nature, a serial port never reaches the end. So, you would need to arrange for the input to "end". One way would be to have the Arduino put an end of file character (control-D) into the output stream. The other way would be to use the so-called "heredoc" by which you tell it to look for a string to end on, as detailed in this question.

There are still a number of problems with this, though. One is, it seems wrong that control-C wouldn't close the access to the serial port. The other is, I tried this on my machine, and I can't get it to produce the problem you asked about. So, that's as much as I can offer.