74 lines
1.9 KiB
Python
74 lines
1.9 KiB
Python
import socket
|
|
import json
|
|
from pprint import pprint
|
|
|
|
from func import *
|
|
|
|
s = socket.socket()
|
|
host = MODBUS_SERVER_HOST
|
|
port = 9760
|
|
|
|
s.connect((host, port))
|
|
# print(s)
|
|
def send_data(data):
|
|
s.send(str.encode(json.dumps(data)))
|
|
response_data = s.recv(1024)
|
|
response = json.loads(response_data)
|
|
|
|
if data["reqType"] == 'query':
|
|
pprint({"request":data["queryAddr"], "response":response["queryData"]})
|
|
elif data["reqType"] == 'command':
|
|
pprint({"request":data["cmdData"], "response":response["cmdReply"]})
|
|
else:
|
|
pprint(response)
|
|
|
|
# получить версию оборудования
|
|
request_data = {
|
|
"dsID": "www.hc-system.com.RemoteMonitor",
|
|
"reqType": "query",
|
|
"queryAddr": ["version", "curMold"],
|
|
}
|
|
|
|
|
|
send_data({
|
|
"dsID": "www.hc-system.com.RemoteMonitor",
|
|
"reqType": "query",
|
|
"packID": "0",
|
|
"queryAddr": ["RemoteCmdLen"],
|
|
})
|
|
|
|
send_data({
|
|
"dsID": "www.hc-system.com.HCRemoteCommand",
|
|
"reqType": "AddRCC",
|
|
"emptyList": "1",
|
|
"packID": "0",
|
|
"instructions": [{"oneshot": "1", "action": "4",
|
|
"m0":"79.287",
|
|
"m1":"1.639",
|
|
"m2":"-31.667",
|
|
"m3":"3.380",
|
|
"m4":"7.986",
|
|
"m5":"-25.592",
|
|
"m6":"0",
|
|
"m7":"0",
|
|
"ckStatus":"0xFF",
|
|
"speed":"11.0",
|
|
"delay":"1.0",
|
|
"coord":"0",
|
|
"tool":"0",
|
|
"smooth":"0",
|
|
}],
|
|
})
|
|
|
|
send_data({
|
|
"dsID": "www.hc-system.com.RemoteMonitor",
|
|
"reqType": "query",
|
|
"packID": "0",
|
|
"queryAddr": ["RemoteCmdLen"],
|
|
})
|
|
send_data({
|
|
"dsID": "www.hc-system.com.RemoteMonitor",
|
|
"reqType": "command",
|
|
"packID": "0",
|
|
"cmdData": ["actionSingleCycle"],
|
|
}) |