SkypLabs / pyhdlcontroller

Python HDLC controller
https://pyhdlcontroller.skyplabs.net/en/stable/
MIT License
18 stars 1 forks source link

the controller is not working #7

Closed myomv100 closed 5 years ago

myomv100 commented 5 years ago

Hi

I have setup a serial connection between two Linux machine and tried to communicate using this HDLC controller but sent message couldn't be received. The sender keeps trying to send the frame over and over again with no ACK signal from the receiver.

The code that I used is derived from your test with little additions. I am not sure why I could not get it to work. The code on both machines is this:

import threading, serial, time
from hdlcontroller.hdlcontroller import HDLController
from yahdlc import *

ser = serial.Serial(port = "/dev/ttyS0", baudrate = 9600, timeout = 0)

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

def send_callback(data):
    print('< {0}'.format(data))

def receive_callback(data):
    print('> {0}'.format(data))

hdlc_c = HDLController(read_serial, ser.write)
hdlc_c.set_send_callback(send_callback)
hdlc_c.set_receive_callback(receive_callback)
hdlc_c.start()

def readHDLC():
    while True:
        recvd = hdlc_c.get_data()
        print(recvd)

def writeHDLC():
    while True:
        strInput = input()
        hdlc_c.send(strInput)

readThread = threading.Thread(target=readHDLC)
writeThread = threading.Thread(target=writeHDLC)

readThread.start()
writeThread.start()

Best

myomv100 commented 5 years ago

Simply the mistake was in my code and my virtual-machines configurations because I created a serial bridge between the two VMs. The working code is on both machines :

import threading, serial
from hdlcontroller.hdlcontroller import HDLController
from yahdlc import *

ser = serial.Serial(port = "/dev/ttyS2", baudrate = 115200)

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

hdlc_c = HDLController(read_serial, ser.write)

def readHDLC(ser,hdlc):
    while 1:
        hdlc.start()
        recvd = hdlc.get_data()
        print(recvd)
        hdlc.stop()

def writeHDLC(ser,hdlc):
    while 1:
        hdlc.start()
        strInput = input(">")
        hdlc.send(strInput)
        hdlc.stop()

readThread = threading.Thread(target=readHDLC,args=(ser,hdlc_c))
writeThread = threading.Thread(target=writeHDLC,args=(ser,hdlc_c))

readThread.start()
writeThread.start()
SkypLabs commented 5 years ago

Hi @myomv100,

Glad to see that you have found a solution to your issue.

Let me know if you need help with something else.

Cheers.