Reputation: 1
I am currently trying to write a python program to control a microchip over a serial connection for my undergraduate studies. I am using a tested microchip board, which was given to me by my supervisor, in conjunction with a Waveshare USB to RS232/485/422/TTL converter. For the IDE I am using PyCharm Community Edition 2024.1.4 with python 3.9. The microchip was programmed using Microchips MPLAB X IDE v6.20 and compiler XC32 v4.35.
When the microchip is supplied with power, it sends a hello message over UART to the connected device which I am trying to read out in python using the following code sniplets. But all I can read back is b''
.
The python code I am using to read the message reads:
import serial
import serial.rs485 as rs
port = 'COM7'
br = 38400
to = 1
n = 10000
ser = serial.Serial(port)
ser.baudrate = br
ser.bytesize = serial.EIGHTBITS
ser.parity = serial.PARITY_NONE
ser.timeout = to
ser.xonxoff = False
ser.stopbits = serial.STOPBITS_ONE
ser.inter_byte_timeout = None
ser.rtscts = False
ser.dsrdtr = False
ser.rs485_mode = rs.RS485Settings()
print(ser.rs485_mode)
if ser:
print('Success')
assert ser.is_open
cnt = 0
while True:
msg = th_controller.read()
print(msg)
cnt += 1
if cnt > n:
break
if cnt > n:
print('No Data received')
This code only yields b''
which is an indicator that no data was sent. Yet I have access to the code for the microchip and tried running it in MPLAB debugger, where it did fine. Also running the program for production works without problems. But receiving the hello message on my end fails.
I've checked the wire connections, checked the settings for UART and tried to reprogram the board for release. I have messed around with different timeout settings and different implementations of the above loop, following the PySerial API. But nothing has worked and I've also scoured Microchip and Arduino forums to no avail. So I was wondering if maybe one of you has tips for me on how tackle this issue.
Upvotes: 0
Views: 69