Tcp To Serial Python8/31/2023 ![]() ![]() Code: import serial ser = rialforurl('socket://localhost:4001/logging=debug') data = ser.read(8) if data: print(data) ser.flushOutput ser.close When I use this code I receive a ConnectionRefusedError. ![]() This is the code I used to create the socket connection and read the unclean data: import socket host = ' port = 4001 backlog = 5 size = 1024 s = socket.socket(socket.AFINET, socket.SOCKSTREAM) s.bind((host,port)) s.listen(backlog) while 1: client, address = s.accept data = client.recv(size) if data: print(data) client.close Then I tried to use pyserial to make a socket connection and let pyserial interpret the data. The problem is that I can not use the data because it is not clean, it contains RS-232 bits. I am able to create a socket connection on localhost:4001 to receive the data. ![]() I am using a Moxa NPort 5110 serial-to-ethernet adapter to transfer serial data over a TCP/IP connection to my computer on port 4001. ![]()
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |