i'm trying read data off of sensor bought, using conversion module (ssi rs232). have module plugged windows laptop via usb/serial converter.
when use putty in serial mode, can send command $2rd , receive appropriate response sensor unit. when run script try same thing, unit returns: ''
here code using:
import sys import serial import time ser = serial.serial( port='com4', baudrate=9600, timeout=1, parity=serial.parity_none, stopbits=serial.stopbits_one, bytesize=serial.eightbits, ) while true: ser.write('$2rd'.encode()) #time.sleep(1) s = ser.read(26) print s
a few other notes:
- i've tried variations using flushinput, flushoutput, sleeping, waiting, etc...nothing seems help.
- i know have com ports right/the hardware works in putty, pretty sure code.
- i've tries 13,400 baud no difference in outcome.
- if connect tx , rx lines usb, can read command i'm sending...so should @ least getting rs232/ssi conversion device.
s = ser.read(26)
should ser.read(size=26)
since takes keyword argument , not positional argument.
also, can try set timeout see sent after specific time because otherwise function can block if 26 bytes aren't sent specified in read docs of pyserial :
read size bytes serial port. if timeout set may return less characters requested. no timeout block until requested number of bytes read.
Comments
Post a Comment