Hey i'am using for first time Python on a RevPi and i got some problem.
The RevPi (simular to Raspberry Pi) is connected via the RS485 serial port to a measurement sensor.
Code:
import serial
def init_serial():
ser = serial.Serial()
ser.baudrate = 9600
ser.port = '/dev/ttyUSB0'
ser.stopbits = serial.STOPBITS_ONE
ser.bytesize = 8
ser.parity = serial.PARITY_NONE
ser.rtscts = 0
return ser
def main():
ser = init_serial()
ser.open()
while True:
mHex = ser.read()
if len(mHex) != 0:
print("Received:", mHex.hex())
else:
print("No data received")
time.sleep(0.1)
i look forward to your support
here is a list of available ports :
python -m serial.tools.list_ports
/dev/ttyAMA0
/dev/ttyUSB0
/dev/ttyUSB1
3 ports found
I also tried this:
~ $ python -m serial.tools.miniterm
--- Available ports:
--- 1: /dev/ttyAMA0 'ttyAMA0'
--- 2: /dev/ttyUSB0 'FT232R USB UART'
--- 3: /dev/ttyUSB1 'FT232R USB UART'
--- Enter port index or full name: 2
--- Miniterm on /dev/ttyUSB0 9600,8,N,1 ---
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
--- exit ---
Exception in thread rx:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
self.run()
File "/usr/lib/python2.7/threading.py", line 754, in run
self.__target(*self.__args, **self.__kwargs)
File "/usr/lib/python2.7/dist-packages/serial/tools/miniterm.py", line 445, in reader
data = self.serial.read(self.serial.in_waiting or 1)
File "/usr/lib/python2.7/dist-packages/serial/serialposix.py", line 501, in read
'device reports readiness to read but returned no data '
SerialException: device reports readiness to read but returned no data (device disconnected or multiple access on port?)