Issue
I am trying to read data from weighing scale YH-T7E using raspberry pi via RS232 to USB cable in pyhon. However, when I am reading the data via it gives me empty string.
Here is my code:
import serial
import time
ser = serial.Serial('/dev/ttyUSB0',
baudrate=9600,
parity=serial.PARITY_EVEN,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.SEVENBITS,
timeout = 1)
while True:
print(ser.read())
The output of above code is:
b''
I have also tried solution from this post but it gives nothing since it keeps on waiting:
while True:
data = ''
while ser.inWaiting() > 0:
data += ser.read()
if data:
print("Received: ", data)
I have verified RS232 is properly connected with the laptop:
[ 6105.752153] usb 1-1.2: ch341-uart converter now attached to ttyUSB1
Even when I used minicom, configured baud rate and other parameters, still no data received.
Here is the YH-T7E manual for the reference
Kindly assist me?
Solution
Your code looks fine. The call to ser.read()
would read one byte at the time - so you should see one character per line if it receives any data. You should probably troubleshoot a bit here.
Are you wires connected correctly? Is the TX from the scale connected to the RX on your RS232 port? Are the grounds connected together?
Are the communication settings correct? Have you tried to set it to 8 bits instead? Also try to set parity to ODD or EVEN, maybe NONE also?
Does you USB RS232 work? Maybe you could check it on some other device?
Answered By - J. P. Petersen