-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.py
72 lines (58 loc) · 1.55 KB
/
index.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import os
import sys
from ctypes import *
import socket
lib = windll.LoadLibrary('IPSerial.dll')
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect(('10.1.10.65', 5000))
sock.send(bytes('g r0x90\r', encoding="utf-8"))
data = sock.recv(1024)
print("DATA PORT RESPONSE: ", data.decode('unicode_escape'))
sock.send(bytes('s r0x90 115200\r', encoding="utf-8"))
print("SET BAUD RATE TO 115200")
# sock.close()
ret = lib.nsio_init()
if ret < 0:
print("INIT ERROR: ", ret)
else:
print("INIT OK", ret)
port_id = lib.nsio_open(b'10.1.10.65', 1, 3000)
if port_id < 0:
print("OPEN ERROR: ", port_id)
else:
print("OPEN OK", port_id)
ret = lib.nsio_baud(port_id, 115200)
if ret < 0:
print("BREAK ERROR: ", ret)
else:
print("BREAK OK", ret)
sock.send(bytes('g r0x90\r', encoding="utf-8"))
data = sock.recv(1024)
print("DATA PORT RESPONSE: ", data.decode('unicode_escape'))
sock.send(bytes('g r0x90\r', encoding="utf-8"))
data = sock.recv(1024)
print("DATA PORT RESPONSE: ", data.decode('unicode_escape'))
ret = lib.nsio_break(port_id, 200)
if ret < 0:
print("BREAK ERROR: ", ret)
else:
print("BREAK OK", ret)
ret = lib.nsio_baud(port_id, 9600)
if ret < 0:
print("BAUD ERROR: ", ret)
else:
print("BAUD OK", ret)
ret = lib.nsio_close(port_id)
if ret < 0:
print("CLOSE ERROR: ", ret)
else:
print("CLOSE OK", ret)
ret = lib.nsio_end()
if ret < 0:
print("CLOSE ERROR: ", ret)
else:
print("CLOSE OK", ret)
sock.send(bytes('g r0x90\r', encoding="utf-8"))
data = sock.recv(1024)
print("DATA PORT RESPONSE: ", data.decode('unicode_escape'))
sock.close()