factory/apps/em/cd.py

19 lines
499 B
Python

import socket
from rest_framework.exceptions import ParseError
def get_tyy_data(*args):
sc = socket.socket()
try:
sc.connect((args[0], int(args[1])))
except Exception:
raise ParseError("无法连接到采集器")
sc.send(b"R")
resp = sc.recv(1024)
if len(resp) < 8:
raise ParseError("设备未启动")
json_data = resp[5:-4]
json_str = json_data.decode('utf-8')
return "str", json_str
if __name__ == '__main__':
print(get_tyy_data())