Python serial link
Posted: Wed Jan 30, 2013 1:56 am
I'm trying to read serial data from my ARMmite from Python...
I use BASICtools to load the led.BAS (below)
Sample test prog :
for i=1 to 3
print i
io(15)=i and 1 ' toggle the LED
wait (1000)
next i
I then run test.py (below) from a DOS box, and I get the following:
E:\Program Files\Coridium\Python>python test.py
0 à
1
2 à
3 à à à
4 à
5 à à
6 à
7 à à
8
9 à à à à à ààààà à àà ààààà àààà àààà ààà à
à à à à à à à à à à à à à à à à ààààà à àà ààààà àààà àààà ààà à
81 'bytes'
So, what am I doing wrong, or need to set?
I looked over TclTerm.tcl, and thought I had some idea, but apparently not.
If the baud is 57600 I only get 71 bytes, anything over returns 81.
Interestingly, I can set the baud up to 2**27-2 before it refuses open().
I'd also like to send control chars to the ARMmite to toggle GPIOs etc., so I'll
need to send as well...
-Ray
# test.py
import serial
import time
## Open the port. Specify baudrate and handshake.
## a running program BASIC will stop
#ser = serial.Serial(port,baudrate=rate,timeout=0,xonxoff=1)
ser = serial.Serial('COM5',
baudrate=115200,
bytesize=serial.EIGHTBITS,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
timeout=0,
xonxoff=0,
rtscts=0,
interCharTimeout=None)
## Enable the ARMmite.
## Deassert Request to Send, which enables Data Carrier Detect
## which alerts the ARMmite of a serial connection.
## RTS is used to control C loading vs BASIC load/run.
## It should always be high for a BASIC program, low for pyserial control
ser.setRTS(0)
## Deassert Data Terminal Ready which deasserts reset.
## DTR is used to reset the ARMmite (reset= 1, running = 0)
ser.setDTR(0) ## run loaded code
"""
ser.write('%s' % (str(arg)))
"""
i = 0
s = ''
while time.clock()<5:
buf = ser.read(ser.inWaiting())
if buf!='':
print i, buf
s += buf
i += 1
print s
print "%d 'bytes'" % len(s)
## Toggle the ARMmite reset. The program will stop.
ser.setDTR(1)
## Close the serial port. The program will resume!
ser.close()
I use BASICtools to load the led.BAS (below)
Sample test prog :
for i=1 to 3
print i
io(15)=i and 1 ' toggle the LED
wait (1000)
next i
I then run test.py (below) from a DOS box, and I get the following:
E:\Program Files\Coridium\Python>python test.py
0 à
1
2 à
3 à à à
4 à
5 à à
6 à
7 à à
8
9 à à à à à ààààà à àà ààààà àààà àààà ààà à
à à à à à à à à à à à à à à à à ààààà à àà ààààà àààà àààà ààà à
81 'bytes'
So, what am I doing wrong, or need to set?
I looked over TclTerm.tcl, and thought I had some idea, but apparently not.
If the baud is 57600 I only get 71 bytes, anything over returns 81.
Interestingly, I can set the baud up to 2**27-2 before it refuses open().
I'd also like to send control chars to the ARMmite to toggle GPIOs etc., so I'll
need to send as well...
-Ray
# test.py
import serial
import time
## Open the port. Specify baudrate and handshake.
## a running program BASIC will stop
#ser = serial.Serial(port,baudrate=rate,timeout=0,xonxoff=1)
ser = serial.Serial('COM5',
baudrate=115200,
bytesize=serial.EIGHTBITS,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
timeout=0,
xonxoff=0,
rtscts=0,
interCharTimeout=None)
## Enable the ARMmite.
## Deassert Request to Send, which enables Data Carrier Detect
## which alerts the ARMmite of a serial connection.
## RTS is used to control C loading vs BASIC load/run.
## It should always be high for a BASIC program, low for pyserial control
ser.setRTS(0)
## Deassert Data Terminal Ready which deasserts reset.
## DTR is used to reset the ARMmite (reset= 1, running = 0)
ser.setDTR(0) ## run loaded code
"""
ser.write('%s' % (str(arg)))
"""
i = 0
s = ''
while time.clock()<5:
buf = ser.read(ser.inWaiting())
if buf!='':
print i, buf
s += buf
i += 1
print s
print "%d 'bytes'" % len(s)
## Toggle the ARMmite reset. The program will stop.
ser.setDTR(1)
## Close the serial port. The program will resume!
ser.close()