Hdlcontroller in python

from hdlcontroller.hdlcontroller import HDLController
import serial

ser = serial.Serial(“COM6”, 9600)

def read_serial():
receivedSerialData = ser.read(ser.in_waiting)
return receivedSerialData

def write_serial(data):

hdlc_c = HDLController(read_serial, write_serial)

msg = “message”


receivedData = hdlc_c.get_data()

Running this code I see that the message is sent to the desired module. But we do not get back a message sent from the module in response to the message sent
Does anyone have any advice what is wrong with the code?

Hi Gal,

Are you trying to use functions read_serial() and write_serial() as keywords (Read Serial and Write Serial) in Robot framework?

My first question would be have you looked at using SerialLibrary? that might make your life easier than having to handle serial IO yourself.

I suspect because you haven’t used a python class each time you call one of your keywords a new instance of serial.Serial is created? You might have better results if you put everything except the import in a class. your function def’s will need self as the first argument and ser.read will become self.ser.read etc. But that might resolve the issue with your code.

I’d still suggest using the existing library that’s probably had a lot more issues than this sorted out given the 11 releases