serial-device/writer_tcp.py
2023-10-01 22:41:21 +03:00

25 lines
660 B
Python

import socket
from time import sleep
import yaml
config_name = "config.yml"
with open(config_name) as f:
config = yaml.load(f, Loader=yaml.FullLoader)
commands_list = ['GET_A', 'GET_B', 'GET_C', 'GET_NORESP', 'INVALID_CMD']
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect((config["writer"]["transport"]["host"], config["writer"]["transport"]["port"]))
while (True):
for cmd in commands_list:
print('Write: ' + cmd)
s.sendall(bytes(cmd+"\n", 'utf-8'))
# data = s.recv(1024)
sleep(0.5)
# print("Response: ", data.decode('utf-8'))
sleep(1)