# Hdlcontroller in python

**URL:** <https://forum.robotframework.org/t/hdlcontroller-in-python/7066>\
**Category:** Libraries\
**Created:** [25 March 2024 13:47 UTC](https://forum.robotframework.org/t/hdlcontroller-in-python/7066 "2024-03-25T13:47:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![GalManz](https://avatars.discourse-cdn.com/v4/letter/g/d2c977/32.png) [@GalManz](https://forum.robotframework.org/u/GalManz)\
**Post date:** [25 March 2024 13:47 UTC](https://forum.robotframework.org/t/hdlcontroller-in-python/7066/1 "2024-03-25T13:47:19Z")

</div>

from hdlcontroller.hdlcontroller import HDLController  
import serial

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

def read\_serial():  
receivedSerialData = ser.read(ser.in\_waiting)  
print(receivedSerialData)  
return receivedSerialData

def write\_serial(data):  
ser.write(data)

hdlc\_c = HDLController(read\_serial, write\_serial)

msg = “message”

hdlc\_c.send(msg)

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?

---

<div class="post-metadata">

**Author:** ![damies13](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/damies13/32/623_2.png) [@damies13](https://forum.robotframework.org/u/damies13)\
**Post date:** [25 March 2024 14:41 UTC](https://forum.robotframework.org/t/hdlcontroller-in-python/7066/2 "2024-03-25T14:41:37Z")

</div>

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](https://github.com/whosaysni/robotframework-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

Dave.
