I want to send/receive data from my Arduino board with a Python script. I would like to do it using Python and its pySerial module which seems to fit my needs. So I installed Python and pySerial within cygwin (windows XP behind).
The Python script is rather straightforward:
$ cat example.py
#print "testing my COM26 port using python"
import serial
ser = serial.Serial()
ser.baudrate = 9600
ser.port = 26
ser
ser.open()
ser.isOpen()
However at runtime I get the following error.
$ python example.py
Traceback (most recent call last):
File "example.py", line 9, in <module>
ser.open()
File "/usr/lib/python2.5/site-packages/serial/serialposix.py", line 276, in open
raise SerialException("could not open port %s: %s" % (self._port, msg))
serial.serialutil.SerialException: could not open port 26: [Errno 2] No such file or directory: '/dev/com27'
Could not open port 26: [Errno 2] No such file or directory: '/dev/com27'
How do I know my Arduino is connected to port COM27?
Well, it's simple. The Arduino IDE says so, I can send and receive data from the Serial Port Monitor tool for the IDE using that port. Besides, I managed to get the hyperterminal working using that port too.
However, it seems Cygwin is not aware of such USB and COM ports:
$ ls -lah /dev
total 4,0K
.
..
fd -> /proc/self/fd
mqueue
shm
stderr -> /proc/self/fd/2
stdin -> /proc/self/fd/0
stdout -> /proc/self/fd/1
It should be mentioned that I am running this on a Dell laptop that has no classic serial COM port, just USB ports. (So I guess it's plain normal for instance that /dev/com1
does not exist.)
I don't know if I'm asking correctly, but my question is: how can I configure Cygwin so that it becomes aware of this COM27 port?
If Hyperterminal can access it, then it's installed as a "virtual COM port". Cygwin will let you access it as /dev/ttyS26 (called COM27 by Windows). You may still have an issue with the input blocking until a CR is received--I do. (Trying to solve that, is how I found this.)