Python serial ( pySerial) can write but not read data ( Windows 11, Python 3.10 )?

Viewed 46

My Python script can send a download command over a Bluetooth serial COM port, but cannot receive data?

  • Windows 11
  • Python 3.10.7
  • Serial.Version: 3.5

code:

import serial

print("serial.VERSION: %s" % (serial.VERSION))
BluetoothSerialPort = 'COM9'
ser = serial.Serial()
ser.timeout = 1.0
ser.baudrate = 115200
ser.parity = 'N'
ser.bytesize = 8
ser.stopbits = 1
ser.port = BluetoothSerialPort
ser.open()

# Start binary data download
# This works. Bluetooth device responds by replying
# with a one line ASCII response,
# followed by 10 KB of binary file data ( non ASCII )
ser.write(b'download')

# packetBytes is always zero ??? 
downloading = True
while downloading:
    packetBytes = ser.read(1)
    print("packetBytes.: %d" % (len(packetBytes)))

This program prints "packetBytes.: 0" at the timeout rate of 1.0 second.

serial.VERSION: 3.5
packetBytes.: 0
packetBytes.: 0
packetBytes.: 0
...

Why would write work, but not read?

  • The Bluetooth device receives the download command.
  • I can see the data being sent from the Bluetooth device.
  • Using a Windows Serial Terminal connected to COM9, I can send command and receive data as expected

Python read never returns anything?

0 Answers
Related