Search code examples
pythonhex

When reading hexadecimal data using python with baudrate 100, receiving only zeros


I am trying to read serial[hexadecimal] data using Python, but when read its showing only zeros. I tried cross checking the data using a logic analyzer and there i can see the data properly.

If any one can give any solution it will be great.

Pasted below is the code.

import serial
ser = serial.Serial(
    port='COM5',       
    baudrate=100,      # Set baud rate to 100
    bytesize=serial.EIGHTBITS,
    parity=serial.PARITY_NONE,
    stopbits=serial.STOPBITS_ONE,
    #timeout=1          # Optional: set a timeout for read operations
)

data = ser.read(100)  # Read up to 100 bytes
print(data)`

**Output: **

b'\\xfc\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00'

Also i cross checked the port setting with the logic anlayzer, its all same but still not able to see the data.


Solution

  • for some one else who is finding the solution, i figured out the issue. I was using a USB to serial cable and the chip used in that will support only from 300 baudrate. Thank you all for trying to help me. This post can be closed.