I am trying to read and store data in a csv
file in packets saved every 5 seconds from a rs232 serial port using Python. An example of a packet to be stored, in each row, is:
308 921 q53 246 133 137 022 1 0 1 1 1 130 C13 330 0000000199 04002201
(there are thousands of different csv rows like this) where each number has meaning which I will need to plot after.
My problem is exact same this like this one: Encode/decode data from RS232 serial port I tried their solution but still did not work for me.
I tried the following code:
import serial
rs232 = serial.Serial('COM6', 115200, timeout=2)
print(rs232.isOpen)
if rs232.isOpen() == True:
while True:
size = rs232.inWaiting()
if size:
data = rs232.read(size)
print(data)
else:
print('No Data Found!')
time.sleep(1)
else:
print('rs232 is not open.')
rs232.close()
The output was:
<bound method SerialBase.isOpen of Serial<id=0x24a180511c8, open=True>(port='COM6', baudrate=115200, bytesize=8, parity='N', stopbits=1, timeout=2, xonxoff=False, rtscts=False, dsrdtr=False)>
No Data Found!
b'\x00'
No Data Found!
No Data Found!
No Data Found!
The loop continues for infinity printing only No Data Found!.
The desired output should be a csv
file where each row will be something similar to the one given above. That sample row was generated using a software written in a non standard programming language.
I also tried this code (https://stackoverflow.com/a/45458473/10543310) and the output for reading was always empty.
I am using Python v3.7.13, pyserial v3.5 on Windows 10.