-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsocket_test.py
145 lines (135 loc) · 6.86 KB
/
socket_test.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import sys
from pcom import commands
from pcom.plc import EthernetPlc
from datetime import timedelta
with EthernetPlc(address=('192.168.5.47', 1616)) as plc:
if False:
columns = [
commands.datatables.ULong(3), # employee, job, material
commands.datatables.Bool(), # begin / end
commands.datatables.Long(3), # weight, reserved, reserved
commands.datatables.Int(3), # year, day-month, hour-minutes
commands.datatables.Byte(), # seconds
commands.datatables.Int(2), # reserved, reserved
commands.datatables.Bool(), # reserved
commands.datatables.Bool(), # reserved
]
structure = commands.datatables.DatatableStructure("Readings", offset=39200,
rows=500,
columns=columns)
c = commands.datatables.ReadDatatable(structure=structure, row_count=25)
res = plc.send(c)
print('test', res)
if True:
cmd = commands.ReadOperands()
cmd.add_request(commands.operand_request.MB(addresses=[10, 11, 12, 13, 14, 15, 16, 17, 18, 19]))
x = plc.send(cmd)
print('reply:', x[0].values)
if False:
cmd = commands.WriteFloats(address=30, values=[1, -10, 3.3])
x = plc.send(cmd)
print('reply:', x)
if False:
cols = [
commands.datatables.Int(), # Quantity
commands.datatables.Long(), # Length
commands.datatables.Int(), # length table #
commands.datatables.Int(), # width table #
]
struct = commands.datatables.DatatableStructure("Recipe", offset=9760, rows=60,
columns=cols)
data = [[[2], [10333], [0], [0]], [[4], [12777], [1], [0]], [[0], [0], [0], [0]], [[0], [0], [0], [0]], [[0], [0], [0], [0]], [[0], [0], [0], [0]], [[0], [0], [0], [0]], [[0], [0], [0], [0]], [[0], [0], [0], [0]], [[0], [0], [0], [0]], [[0], [0], [0], [0]], [[0], [0], [0], [0]], [[0], [0], [0], [0]], [[0], [0], [0], [0]], [[0], [0], [0], [0]], [[0], [0], [0], [0]], [[0], [0], [0], [0]], [[0], [0], [0], [0]], [[0], [0], [0], [0]], [[0], [0], [0], [0]], [[0], [0], [0], [0]], [[0], [0], [0], [0]], [[0], [0], [0], [0]], [[0], [0], [0], [0]], [[0], [0], [0], [0]], [[0], [0], [0], [0]], [[0], [0], [0], [0]], [[0], [0], [0], [0]], [[0], [0], [0], [0]], [[0], [0], [0], [0]], [[0], [0], [0], [0]], [[0], [0], [0], [0]], [[0], [0], [0], [0]], [[0], [0], [0], [0]], [[0], [0], [0], [0]], [[0], [0], [0], [0]], [[0], [0], [0], [0]], [[0], [0], [0], [0]], [[0], [0], [0], [0]], [[0], [0], [0], [0]], [[0], [0], [0], [0]], [[0], [0], [0], [0]], [[0], [0], [0], [0]], [[0], [0], [0], [0]], [[0], [0], [0], [0]], [[0], [0], [0], [0]], [[0], [0], [0], [0]], [[0], [0], [0], [0]], [[0], [0], [0], [0]], [[0], [0], [0], [0]], [[0], [0], [0], [0]], [[0], [0], [0], [0]], [[0], [0], [0], [0]], [[0], [0], [0], [0]], [[0], [0], [0], [0]], [[0], [0], [0], [0]], [[0], [0], [0], [0]], [[0], [0], [0], [0]], [[0], [0], [0], [0]], [[0], [0], [0], [0]]]
cmd = commands.datatables.WriteDatatable(structure=struct, data=data)
plc.send(cmd)
# c = commands.SetBits(code=commands.SetBits.MEMORY, address=300, values=values)
# c = commands.SetRtc(value=datetime.now())
# c = commands.SetRtc(value=datetime(2018, 12, 13, 14, 43, 10))
if False:
test_structure = commands.datatables.DatatableStructure("Test", offset=20200, rows=2, columns=[
commands.datatables.String(5),
commands.datatables.Float(),
commands.datatables.Timer(),
commands.datatables.ULong(),
commands.datatables.Long(),
commands.datatables.UInt(),
commands.datatables.Int(),
commands.datatables.Byte(),
commands.datatables.Bool(),
commands.datatables.Bool(),
commands.datatables.Bool(),
commands.datatables.Bool(),
commands.datatables.Bool(),
commands.datatables.Bool(),
commands.datatables.Bool(),
commands.datatables.Bool(),
commands.datatables.Bool(),
])
data = [
[
[timedelta(hours=6)]
],
[
[timedelta(hours=5)]
]
]
c = commands.datatables.WriteDatatable(structure=test_structure, data=data, start_column_index=2)
res = plc.send(c)
print('test', res)
if False:
test_structure = commands.datatables.DatatableStructure("Test", offset=20200, rows=2, columns=[
commands.datatables.String(5),
commands.datatables.Float(),
commands.datatables.Timer(),
commands.datatables.ULong(),
commands.datatables.Long(),
commands.datatables.UInt(),
commands.datatables.Int(),
commands.datatables.Byte(),
commands.datatables.Bool(),
commands.datatables.Bool(),
commands.datatables.Bool(),
commands.datatables.Bool(),
commands.datatables.Bool(),
commands.datatables.Bool(),
commands.datatables.Bool(),
commands.datatables.Bool(),
commands.datatables.Bool(),
])
c = commands.datatables.ReadDatatable(structure=test_structure, row_count=2, start_column_index=2, column_count=1)
res = plc.send(c)
print('test', res)
if False:
poids_structure = commands.datatables.DatatableStructure("Poids", offset=19000, rows=2, columns=[
commands.datatables.Int(),
commands.datatables.Int(),
commands.datatables.Int(),
commands.datatables.Int(),
commands.datatables.Long(),
])
c = commands.datatables.ReadDatatable(structure=poids_structure, row_count=2)
res = plc.send(c)
print('poids', res)
print()
if False:
table1_structure = commands.datatables.DatatableStructure("Table1", offset=0, rows=2, columns=[
commands.datatables.ULong(),
commands.datatables.ULong(),
commands.datatables.ULong(),
commands.datatables.Bool(),
commands.datatables.Long(),
commands.datatables.Long(),
commands.datatables.Long(),
commands.datatables.Int(),
commands.datatables.Int(),
commands.datatables.Int(),
commands.datatables.Byte(),
commands.datatables.Int(),
commands.datatables.Int(),
commands.datatables.Bool(),
commands.datatables.Bool(),
])
c = commands.datatables.ReadDatatable(structure=table1_structure, row_count=2)
res = plc.send(c)
print('table1')
for r in res:
print(r)