Reorganize files
This commit is contained in:
211
POCloud/python-driver/Channel.py
Normal file
211
POCloud/python-driver/Channel.py
Normal file
@@ -0,0 +1,211 @@
|
||||
"""Define Meshify channel class."""
|
||||
from pycomm.ab_comm.clx import Driver as ClxDriver
|
||||
from pycomm.cip.cip_base import CommError, DataError
|
||||
import time
|
||||
|
||||
|
||||
def binarray(intval):
|
||||
"""Split an integer into its bits."""
|
||||
bin_string = '{0:08b}'.format(intval)
|
||||
bin_arr = [i for i in bin_string]
|
||||
bin_arr.reverse()
|
||||
return bin_arr
|
||||
|
||||
|
||||
def read_tag(addr, tag):
|
||||
"""Read a tag from the PLC."""
|
||||
c = ClxDriver()
|
||||
try:
|
||||
if c.open(addr):
|
||||
try:
|
||||
v = c.read_tag(tag)
|
||||
return v
|
||||
except DataError:
|
||||
c.close()
|
||||
print("Data Error during readTag({}, {})".format(addr, tag))
|
||||
except CommError:
|
||||
# err = c.get_status()
|
||||
c.close()
|
||||
print("Could not connect during readTag({}, {})".format(addr, tag))
|
||||
# print err
|
||||
except AttributeError as e:
|
||||
c.close()
|
||||
print("AttributeError during readTag({}, {}): \n{}".format(addr, tag, e))
|
||||
c.close()
|
||||
return False
|
||||
|
||||
|
||||
def read_array(addr, tag, start, end):
|
||||
"""Read an array from the PLC."""
|
||||
c = ClxDriver()
|
||||
if c.open(addr):
|
||||
arr_vals = []
|
||||
try:
|
||||
for i in range(start, end):
|
||||
tag_w_index = tag + "[{}]".format(i)
|
||||
v = c.read_tag(tag_w_index)
|
||||
# print('{} - {}'.format(tag_w_index, v))
|
||||
arr_vals.append(round(v[0], 4))
|
||||
# print(v)
|
||||
if len(arr_vals) > 0:
|
||||
return arr_vals
|
||||
else:
|
||||
print("No length for {}".format(addr))
|
||||
return False
|
||||
except Exception:
|
||||
print("Error during readArray({}, {}, {}, {})".format(addr, tag, start, end))
|
||||
err = c.get_status()
|
||||
c.close()
|
||||
print err
|
||||
pass
|
||||
c.close()
|
||||
|
||||
|
||||
def write_tag(addr, tag, val):
|
||||
"""Write a tag value to the PLC."""
|
||||
c = ClxDriver()
|
||||
if c.open(addr):
|
||||
try:
|
||||
cv = c.read_tag(tag)
|
||||
wt = c.write_tag(tag, val, cv[1])
|
||||
return wt
|
||||
except Exception:
|
||||
print("Error during writeTag({}, {}, {})".format(addr, tag, val))
|
||||
err = c.get_status()
|
||||
c.close()
|
||||
print err
|
||||
c.close()
|
||||
|
||||
|
||||
class Channel:
|
||||
"""Holds the configuration for a Meshify channel."""
|
||||
|
||||
def __init__(self, ip, mesh_name, plc_tag, data_type, chg_threshold, guarantee_sec, map_=False, write_enabled=False):
|
||||
"""Initialize the channel."""
|
||||
self.plc_ip = ip
|
||||
self.mesh_name = mesh_name
|
||||
self.plc_tag = plc_tag
|
||||
self.data_type = data_type
|
||||
self.last_value = None
|
||||
self.value = None
|
||||
self.last_send_time = 0
|
||||
self.chg_threshold = chg_threshold
|
||||
self.guarantee_sec = guarantee_sec
|
||||
self.map_ = map_
|
||||
self.write_enabled = write_enabled
|
||||
|
||||
def __str__(self):
|
||||
"""Create a string for the channel."""
|
||||
return "{}: {}\nvalue: {}, last_send_time: {}".format(self.mesh_name, self.plc_tag, self.value, self.last_send_time)
|
||||
|
||||
def read(self, force_send=False):
|
||||
"""Read the value and check to see if needs to be stored."""
|
||||
send_needed = False
|
||||
send_reason = ""
|
||||
if self.plc_tag:
|
||||
v = read_tag(self.plc_ip, self.plc_tag)
|
||||
if v:
|
||||
if self.data_type == 'BOOL' or self.data_type == 'STRING':
|
||||
if self.last_send_time == 0:
|
||||
send_needed = True
|
||||
send_reason = "no send time"
|
||||
elif self.value is None:
|
||||
send_needed = True
|
||||
send_reason = "no value"
|
||||
elif not (self.value == v[0]):
|
||||
if self.map_:
|
||||
if not self.value == self.map_[v[0]]:
|
||||
send_needed = True
|
||||
send_reason = "value change"
|
||||
else:
|
||||
send_needed = True
|
||||
send_reason = "value change"
|
||||
elif (time.time() - self.last_send_time) > self.guarantee_sec:
|
||||
send_needed = True
|
||||
send_reason = "guarantee sec"
|
||||
elif force_send:
|
||||
send_needed = True
|
||||
send_reason = "forced"
|
||||
else:
|
||||
if self.last_send_time == 0:
|
||||
send_needed = True
|
||||
send_reason = "no send time"
|
||||
elif self.value is None:
|
||||
send_needed = True
|
||||
send_reason = "no value"
|
||||
elif abs(self.value - v[0]) > self.chg_threshold:
|
||||
send_needed = True
|
||||
send_reason = "change threshold"
|
||||
elif (time.time() - self.last_send_time) > self.guarantee_sec:
|
||||
send_needed = True
|
||||
send_reason = "guarantee sec"
|
||||
elif force_send:
|
||||
send_needed = True
|
||||
send_reason = "forced"
|
||||
if send_needed:
|
||||
self.last_value = self.value
|
||||
if self.map_:
|
||||
try:
|
||||
self.value = self.map_[v[0]]
|
||||
except KeyError:
|
||||
print("Cannot find a map value for {} in {} for {}".format(v[0], self.map_, self.mesh_name))
|
||||
self.value = v[0]
|
||||
else:
|
||||
self.value = v[0]
|
||||
self.last_send_time = time.time()
|
||||
print("Sending {} for {} - {}".format(self.value, self.mesh_name, send_reason))
|
||||
return send_needed
|
||||
|
||||
|
||||
class BoolArrayChannels(Channel):
|
||||
"""Hold the configuration for a set of boolean array channels."""
|
||||
|
||||
def compare_values(self, new_val_dict):
|
||||
"""Compare new values to old values to see if the values need storing."""
|
||||
send = False
|
||||
for idx in new_val_dict:
|
||||
try:
|
||||
if new_val_dict[idx] != self.last_value[idx]:
|
||||
send = True
|
||||
except KeyError:
|
||||
print("Key Error in self.compare_values for index {}".format(idx))
|
||||
send = True
|
||||
return send
|
||||
|
||||
def read(self, force_send=False):
|
||||
"""Read the value and check to see if needs to be stored."""
|
||||
send_needed = False
|
||||
send_reason = ""
|
||||
if self.plc_tag:
|
||||
v = read_tag(self.plc_ip, self.plc_tag)
|
||||
if v:
|
||||
bool_arr = binarray(v[0])
|
||||
new_val = {}
|
||||
for idx in self.map_:
|
||||
try:
|
||||
new_val[self.map_[idx]] = bool_arr[idx]
|
||||
except KeyError:
|
||||
print("Not able to get value for index {}".format(idx))
|
||||
|
||||
if self.last_send_time == 0:
|
||||
send_needed = True
|
||||
send_reason = "no send time"
|
||||
elif self.value is None:
|
||||
send_needed = True
|
||||
send_reason = "no value"
|
||||
elif self.compare_values(new_val):
|
||||
send_needed = True
|
||||
send_reason = "value change"
|
||||
elif (time.time() - self.last_send_time) > self.guarantee_sec:
|
||||
send_needed = True
|
||||
send_reason = "guarantee sec"
|
||||
elif force_send:
|
||||
send_needed = True
|
||||
send_reason = "forced"
|
||||
|
||||
if send_needed:
|
||||
self.value = new_val
|
||||
self.last_value = self.value
|
||||
self.last_send_time = time.time()
|
||||
print("Sending {} for {} - {}".format(self.value, self.mesh_name, send_reason))
|
||||
return send_needed
|
||||
3
POCloud/python-driver/Maps.py
Normal file
3
POCloud/python-driver/Maps.py
Normal file
@@ -0,0 +1,3 @@
|
||||
"""Holds map values for rigpump."""
|
||||
|
||||
rigpump_map = {}
|
||||
15
POCloud/python-driver/config.txt
Normal file
15
POCloud/python-driver/config.txt
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
|
||||
"driverFileName":"rigpump.py",
|
||||
"deviceName":"rigpump",
|
||||
"driverId":"0150",
|
||||
"releaseVersion":"7",
|
||||
"files": {
|
||||
"file1":"rigpump.py",
|
||||
"file2":"Channel.py",
|
||||
"file3":"Maps.py",
|
||||
"file4":"Scheduler.py",
|
||||
"file5":"modbusMap.p"
|
||||
}
|
||||
|
||||
}
|
||||
923
POCloud/python-driver/modbusMap.p
Normal file
923
POCloud/python-driver/modbusMap.p
Normal file
@@ -0,0 +1,923 @@
|
||||
(dp0
|
||||
S'1'
|
||||
p1
|
||||
(dp2
|
||||
S'c'
|
||||
p3
|
||||
VETHERNET/IP
|
||||
p4
|
||||
sS'b'
|
||||
p5
|
||||
V192.168.1.10
|
||||
p6
|
||||
sS'addresses'
|
||||
p7
|
||||
(dp8
|
||||
V300
|
||||
p9
|
||||
(dp10
|
||||
V2-2
|
||||
p11
|
||||
(dp12
|
||||
Vah
|
||||
p13
|
||||
V
|
||||
p14
|
||||
sVbytary
|
||||
p15
|
||||
NsVal
|
||||
p16
|
||||
g14
|
||||
sVvn
|
||||
p17
|
||||
VVFD Current
|
||||
p18
|
||||
sVct
|
||||
p19
|
||||
Vnumber
|
||||
p20
|
||||
sVle
|
||||
p21
|
||||
V16
|
||||
p22
|
||||
sVgrp
|
||||
p23
|
||||
V3600
|
||||
p24
|
||||
sVla
|
||||
p25
|
||||
F52.357959747314453
|
||||
sVchn
|
||||
p26
|
||||
Vvfd_current
|
||||
p27
|
||||
sVun
|
||||
p28
|
||||
V1
|
||||
p29
|
||||
sVdn
|
||||
p30
|
||||
Vrigpump
|
||||
p31
|
||||
sVvm
|
||||
p32
|
||||
NsVlrt
|
||||
p33
|
||||
F1507133764.2258689
|
||||
sVda
|
||||
p34
|
||||
V300
|
||||
p35
|
||||
sVa
|
||||
p36
|
||||
VVFD_OutCurrent
|
||||
p37
|
||||
sVc
|
||||
p38
|
||||
V1.0
|
||||
p39
|
||||
sVmisc_u
|
||||
p40
|
||||
VAmps
|
||||
p41
|
||||
sVf
|
||||
p42
|
||||
g29
|
||||
sVmrt
|
||||
p43
|
||||
V60
|
||||
p44
|
||||
sVm
|
||||
p45
|
||||
Vnone
|
||||
p46
|
||||
sS'm1ch'
|
||||
p47
|
||||
g11
|
||||
sVmv
|
||||
p48
|
||||
V0
|
||||
p49
|
||||
sVs
|
||||
p50
|
||||
VOn
|
||||
p51
|
||||
sVr
|
||||
p52
|
||||
V0-250
|
||||
p53
|
||||
sVt
|
||||
p54
|
||||
Vint
|
||||
p55
|
||||
ssV2-3
|
||||
p56
|
||||
(dp57
|
||||
g52
|
||||
V0-75
|
||||
p58
|
||||
sVah
|
||||
p59
|
||||
g14
|
||||
sVbytary
|
||||
p60
|
||||
NsVal
|
||||
p61
|
||||
g14
|
||||
sVvn
|
||||
p62
|
||||
VVFD Frequency
|
||||
p63
|
||||
sVct
|
||||
p64
|
||||
Vnumber
|
||||
p65
|
||||
sVle
|
||||
p66
|
||||
V16
|
||||
p67
|
||||
sVgrp
|
||||
p68
|
||||
V3600
|
||||
p69
|
||||
sVla
|
||||
p70
|
||||
F55.608009338378906
|
||||
sVchn
|
||||
p71
|
||||
Vvfd_frequency
|
||||
p72
|
||||
sVun
|
||||
p73
|
||||
g29
|
||||
sVdn
|
||||
p74
|
||||
Vrigpump
|
||||
p75
|
||||
sVvm
|
||||
p76
|
||||
NsVlrt
|
||||
p77
|
||||
F1507133769.354713
|
||||
sVda
|
||||
p78
|
||||
V300
|
||||
p79
|
||||
sg36
|
||||
VVFD_SpeedFdbk
|
||||
p80
|
||||
sg38
|
||||
V0.5
|
||||
p81
|
||||
sVmisc_u
|
||||
p82
|
||||
VHz
|
||||
p83
|
||||
sg42
|
||||
g29
|
||||
sVmrt
|
||||
p84
|
||||
V60
|
||||
p85
|
||||
sg45
|
||||
Vnone
|
||||
p86
|
||||
sVm1ch
|
||||
p87
|
||||
g56
|
||||
sg50
|
||||
VOn
|
||||
p88
|
||||
sVmv
|
||||
p89
|
||||
g49
|
||||
sg54
|
||||
Vint
|
||||
p90
|
||||
ssV2-1
|
||||
p91
|
||||
(dp92
|
||||
Vah
|
||||
p93
|
||||
g14
|
||||
sVbytary
|
||||
p94
|
||||
NsVal
|
||||
p95
|
||||
g14
|
||||
sVvn
|
||||
p96
|
||||
VDischarge Pressure
|
||||
p97
|
||||
sVct
|
||||
p98
|
||||
Vnumber
|
||||
p99
|
||||
sVle
|
||||
p100
|
||||
V16
|
||||
p101
|
||||
sVgrp
|
||||
p102
|
||||
V3600
|
||||
p103
|
||||
sVla
|
||||
p104
|
||||
F0.0
|
||||
sVchn
|
||||
p105
|
||||
Vdischarge_pressure
|
||||
p106
|
||||
sVun
|
||||
p107
|
||||
g29
|
||||
sVdn
|
||||
p108
|
||||
Vrigpump
|
||||
p109
|
||||
sVvm
|
||||
p110
|
||||
NsVlrt
|
||||
p111
|
||||
F1507133774.5094061
|
||||
sVda
|
||||
p112
|
||||
V300
|
||||
p113
|
||||
sg36
|
||||
Vval_DischargePressure
|
||||
p114
|
||||
sg38
|
||||
V5.0
|
||||
p115
|
||||
sVmisc_u
|
||||
p116
|
||||
VPSI
|
||||
p117
|
||||
sg42
|
||||
g29
|
||||
sVmrt
|
||||
p118
|
||||
V60
|
||||
p119
|
||||
sg45
|
||||
Vnone
|
||||
p120
|
||||
sg47
|
||||
g91
|
||||
sVmv
|
||||
p121
|
||||
g49
|
||||
sg50
|
||||
VOn
|
||||
p122
|
||||
sg52
|
||||
V0-500
|
||||
p123
|
||||
sg54
|
||||
Vint
|
||||
p124
|
||||
ssV2-6
|
||||
p125
|
||||
(dp126
|
||||
Vah
|
||||
p127
|
||||
g14
|
||||
sVbytary
|
||||
p128
|
||||
NsVal
|
||||
p129
|
||||
g14
|
||||
sVvn
|
||||
p130
|
||||
VDischarge Pressure Setpoint
|
||||
p131
|
||||
sVct
|
||||
p132
|
||||
Vnumber
|
||||
p133
|
||||
sVle
|
||||
p134
|
||||
V16
|
||||
p135
|
||||
sVgrp
|
||||
p136
|
||||
V3600
|
||||
p137
|
||||
sVla
|
||||
p138
|
||||
F60.0
|
||||
sVchn
|
||||
p139
|
||||
Vdischarge_pressure_setpoint
|
||||
p140
|
||||
sVun
|
||||
p141
|
||||
g29
|
||||
sVdn
|
||||
p142
|
||||
Vrigpump
|
||||
p143
|
||||
sVvm
|
||||
p144
|
||||
NsVlrt
|
||||
p145
|
||||
F1507133779.6010119
|
||||
sVda
|
||||
p146
|
||||
V300
|
||||
p147
|
||||
sg36
|
||||
Vcfg_PID_DischargePressureSP
|
||||
p148
|
||||
sg38
|
||||
V0.5
|
||||
p149
|
||||
sVmisc_u
|
||||
p150
|
||||
VPSI
|
||||
p151
|
||||
sg42
|
||||
g29
|
||||
sVmrt
|
||||
p152
|
||||
V60
|
||||
p153
|
||||
sg45
|
||||
Vnone
|
||||
p154
|
||||
sg47
|
||||
g125
|
||||
sVmv
|
||||
p155
|
||||
g49
|
||||
sg50
|
||||
VOn
|
||||
p156
|
||||
sg52
|
||||
V0-500
|
||||
p157
|
||||
sg54
|
||||
Vint
|
||||
p158
|
||||
ssV2-7
|
||||
p159
|
||||
(dp160
|
||||
Vah
|
||||
p161
|
||||
g14
|
||||
sVbytary
|
||||
p162
|
||||
NsVal
|
||||
p163
|
||||
g14
|
||||
sVvn
|
||||
p164
|
||||
VVFD Frequency Setpoint
|
||||
p165
|
||||
sVct
|
||||
p166
|
||||
Vnumber
|
||||
p167
|
||||
sVle
|
||||
p168
|
||||
V16
|
||||
p169
|
||||
sVgrp
|
||||
p170
|
||||
V3600
|
||||
p171
|
||||
sVla
|
||||
p172
|
||||
F60.0
|
||||
sVchn
|
||||
p173
|
||||
Vvfd_frequency_setpoint
|
||||
p174
|
||||
sVun
|
||||
p175
|
||||
g29
|
||||
sVdn
|
||||
p176
|
||||
Vrigpump
|
||||
p177
|
||||
sVvm
|
||||
p178
|
||||
NsVlrt
|
||||
p179
|
||||
F1507133723.4260002
|
||||
sVda
|
||||
p180
|
||||
V300
|
||||
p181
|
||||
sg36
|
||||
Vcfg_PID_ManualSP
|
||||
p182
|
||||
sg38
|
||||
V0.5
|
||||
p183
|
||||
sVmisc_u
|
||||
p184
|
||||
VHz
|
||||
p185
|
||||
sg42
|
||||
g29
|
||||
sVmrt
|
||||
p186
|
||||
V60
|
||||
p187
|
||||
sg45
|
||||
Vnone
|
||||
p188
|
||||
sg47
|
||||
g159
|
||||
sVmv
|
||||
p189
|
||||
g49
|
||||
sg50
|
||||
VOn
|
||||
p190
|
||||
sg52
|
||||
V0-75
|
||||
p191
|
||||
sg54
|
||||
Vint
|
||||
p192
|
||||
ssV2-4
|
||||
p193
|
||||
(dp194
|
||||
Vah
|
||||
p195
|
||||
g14
|
||||
sVbytary
|
||||
p196
|
||||
NsVal
|
||||
p197
|
||||
g14
|
||||
sVvn
|
||||
p198
|
||||
VDevice Status
|
||||
p199
|
||||
sVct
|
||||
p200
|
||||
Vnumber
|
||||
p201
|
||||
sVle
|
||||
p202
|
||||
V16
|
||||
p203
|
||||
sVgrp
|
||||
p204
|
||||
V3600
|
||||
p205
|
||||
sVla
|
||||
p206
|
||||
I1
|
||||
sVchn
|
||||
p207
|
||||
Vdevice_status
|
||||
p208
|
||||
sVun
|
||||
p209
|
||||
g29
|
||||
sVdn
|
||||
p210
|
||||
Vrigpump
|
||||
p211
|
||||
sVvm
|
||||
p212
|
||||
(dp213
|
||||
g29
|
||||
VRunning
|
||||
p214
|
||||
sV128
|
||||
p215
|
||||
VOverpressure
|
||||
p216
|
||||
sV64
|
||||
p217
|
||||
VIdle
|
||||
p218
|
||||
sV1024
|
||||
p219
|
||||
VFaulted
|
||||
p220
|
||||
ssVlrt
|
||||
p221
|
||||
F1507133728.5280639
|
||||
sVda
|
||||
p222
|
||||
V300
|
||||
p223
|
||||
sg36
|
||||
VRigPump.State
|
||||
p224
|
||||
sg38
|
||||
g29
|
||||
sVmisc_u
|
||||
p225
|
||||
g14
|
||||
sg42
|
||||
g29
|
||||
sVmrt
|
||||
p226
|
||||
V60
|
||||
p227
|
||||
sg45
|
||||
Vnone
|
||||
p228
|
||||
sg47
|
||||
g193
|
||||
sVmv
|
||||
p229
|
||||
g49
|
||||
sg50
|
||||
VOn
|
||||
p230
|
||||
sg52
|
||||
V0-32768
|
||||
p231
|
||||
sg54
|
||||
Vint
|
||||
p232
|
||||
ssV2-5
|
||||
p233
|
||||
(dp234
|
||||
Vah
|
||||
p235
|
||||
g14
|
||||
sVbytary
|
||||
p236
|
||||
NsVal
|
||||
p237
|
||||
g14
|
||||
sVvn
|
||||
p238
|
||||
VFlow Rate Setpoint
|
||||
p239
|
||||
sVct
|
||||
p240
|
||||
Vnumber
|
||||
p241
|
||||
sVle
|
||||
p242
|
||||
V16
|
||||
p243
|
||||
sVgrp
|
||||
p244
|
||||
V3600
|
||||
p245
|
||||
sVla
|
||||
p246
|
||||
F55.0
|
||||
sVchn
|
||||
p247
|
||||
Vflow_rate_setpoint
|
||||
p248
|
||||
sVun
|
||||
p249
|
||||
g29
|
||||
sVdn
|
||||
p250
|
||||
Vrigpump
|
||||
p251
|
||||
sVvm
|
||||
p252
|
||||
NsVlrt
|
||||
p253
|
||||
F1507133733.768225
|
||||
sVda
|
||||
p254
|
||||
V300
|
||||
p255
|
||||
sg36
|
||||
Vcfg_PID_FlowSP
|
||||
p256
|
||||
sg38
|
||||
V0.1
|
||||
p257
|
||||
sVmisc_u
|
||||
p258
|
||||
VBPM
|
||||
p259
|
||||
sg42
|
||||
g29
|
||||
sVmrt
|
||||
p260
|
||||
V60
|
||||
p261
|
||||
sg45
|
||||
Vnone
|
||||
p262
|
||||
sg47
|
||||
g233
|
||||
sVmv
|
||||
p263
|
||||
g49
|
||||
sg50
|
||||
VOn
|
||||
p264
|
||||
sg52
|
||||
V0-5000
|
||||
p265
|
||||
sg54
|
||||
Vint
|
||||
p266
|
||||
ssV2-8
|
||||
p267
|
||||
(dp268
|
||||
Vr
|
||||
p269
|
||||
V0-1
|
||||
p270
|
||||
sVah
|
||||
p271
|
||||
g14
|
||||
sVbytary
|
||||
p272
|
||||
NsVal
|
||||
p273
|
||||
V0
|
||||
p274
|
||||
sVvn
|
||||
p275
|
||||
VAuto/Manual Mode
|
||||
p276
|
||||
sVct
|
||||
p277
|
||||
Vnumber
|
||||
p278
|
||||
sVle
|
||||
p279
|
||||
V16
|
||||
p280
|
||||
sVgrp
|
||||
p281
|
||||
V3600
|
||||
p282
|
||||
sVla
|
||||
p283
|
||||
g14
|
||||
sVchn
|
||||
p284
|
||||
Vauto_manual
|
||||
p285
|
||||
sVun
|
||||
p286
|
||||
V1
|
||||
p287
|
||||
sVdn
|
||||
p288
|
||||
Vrigpump
|
||||
p289
|
||||
sVvm
|
||||
p290
|
||||
(dp291
|
||||
g287
|
||||
VAuto
|
||||
p292
|
||||
sg274
|
||||
VManual
|
||||
p293
|
||||
ssVlrt
|
||||
p294
|
||||
F1507133507.0949212
|
||||
sVda
|
||||
p295
|
||||
V300
|
||||
p296
|
||||
sVa
|
||||
p297
|
||||
Vmode_Auto
|
||||
p298
|
||||
sVc
|
||||
p299
|
||||
g274
|
||||
sVmisc_u
|
||||
p300
|
||||
g14
|
||||
sVf
|
||||
p301
|
||||
g287
|
||||
sVmrt
|
||||
p302
|
||||
V60
|
||||
p303
|
||||
sVm
|
||||
p304
|
||||
Vnone
|
||||
p305
|
||||
sVm1ch
|
||||
p306
|
||||
g267
|
||||
sVs
|
||||
p307
|
||||
VOn
|
||||
p308
|
||||
sVmv
|
||||
p309
|
||||
g274
|
||||
sVt
|
||||
p310
|
||||
Vint
|
||||
p311
|
||||
ssV2-9
|
||||
p312
|
||||
(dp313
|
||||
Vah
|
||||
p314
|
||||
g14
|
||||
sVbytary
|
||||
p315
|
||||
NsVal
|
||||
p316
|
||||
g274
|
||||
sVvn
|
||||
p317
|
||||
VControl Mode
|
||||
p318
|
||||
sVct
|
||||
p319
|
||||
Vnumber
|
||||
p320
|
||||
sVle
|
||||
p321
|
||||
V16
|
||||
p322
|
||||
sVgrp
|
||||
p323
|
||||
V3600
|
||||
p324
|
||||
sVla
|
||||
p325
|
||||
g14
|
||||
sVchn
|
||||
p326
|
||||
Vauto_control_mode
|
||||
p327
|
||||
sVun
|
||||
p328
|
||||
g287
|
||||
sVdn
|
||||
p329
|
||||
Vrigpump
|
||||
p330
|
||||
sVda
|
||||
p331
|
||||
V300
|
||||
p332
|
||||
sVlrt
|
||||
p333
|
||||
g274
|
||||
sg297
|
||||
VcontrolMode
|
||||
p334
|
||||
sg299
|
||||
g274
|
||||
sVmisc_u
|
||||
p335
|
||||
g14
|
||||
sg301
|
||||
g287
|
||||
sVmrt
|
||||
p336
|
||||
V60
|
||||
p337
|
||||
sg304
|
||||
Vnone
|
||||
p338
|
||||
sVm1ch
|
||||
p339
|
||||
g312
|
||||
sVmv
|
||||
p340
|
||||
g274
|
||||
sg307
|
||||
VOn
|
||||
p341
|
||||
sg269
|
||||
V0-1
|
||||
p342
|
||||
sg310
|
||||
Vint
|
||||
p343
|
||||
sVvm
|
||||
p344
|
||||
(dp345
|
||||
g287
|
||||
VFlow
|
||||
p346
|
||||
sg274
|
||||
VPressure
|
||||
p347
|
||||
sssV2-11
|
||||
p348
|
||||
(dp349
|
||||
Vah
|
||||
p350
|
||||
g14
|
||||
sVbytary
|
||||
p351
|
||||
NsVal
|
||||
p352
|
||||
g14
|
||||
sVvn
|
||||
p353
|
||||
VFlow Rate
|
||||
p354
|
||||
sVct
|
||||
p355
|
||||
Vnumber
|
||||
p356
|
||||
sVle
|
||||
p357
|
||||
V16
|
||||
p358
|
||||
sVgrp
|
||||
p359
|
||||
V3600
|
||||
p360
|
||||
sVla
|
||||
p361
|
||||
F0.0
|
||||
sVchn
|
||||
p362
|
||||
Vflow_rate
|
||||
p363
|
||||
sVun
|
||||
p364
|
||||
g29
|
||||
sVdn
|
||||
p365
|
||||
Vrigpump
|
||||
p366
|
||||
sVvm
|
||||
p367
|
||||
NsVlrt
|
||||
p368
|
||||
F1507133810.3850061
|
||||
sVda
|
||||
p369
|
||||
g9
|
||||
sg36
|
||||
Vval_Flowmeter
|
||||
p370
|
||||
sg38
|
||||
V5.0
|
||||
p371
|
||||
sVmisc_u
|
||||
p372
|
||||
VBPM
|
||||
p373
|
||||
sg42
|
||||
g29
|
||||
sVmrt
|
||||
p374
|
||||
V60
|
||||
p375
|
||||
sg45
|
||||
Vnone
|
||||
p376
|
||||
sg47
|
||||
g348
|
||||
sVmv
|
||||
p377
|
||||
g49
|
||||
sg50
|
||||
VOn
|
||||
p378
|
||||
sg52
|
||||
V0-50000
|
||||
p379
|
||||
sg54
|
||||
Vint
|
||||
p380
|
||||
ssssS'f'
|
||||
p381
|
||||
VOff
|
||||
p382
|
||||
sS'p'
|
||||
p383
|
||||
g14
|
||||
sS's'
|
||||
p384
|
||||
g287
|
||||
ssS'2'
|
||||
p385
|
||||
(dp386
|
||||
g3
|
||||
VM1-232
|
||||
p387
|
||||
sg5
|
||||
V9600
|
||||
p388
|
||||
sg7
|
||||
(dp389
|
||||
sg381
|
||||
VOff
|
||||
p390
|
||||
sg383
|
||||
g14
|
||||
sg384
|
||||
g287
|
||||
ss.
|
||||
146
POCloud/python-driver/rigpump.py
Normal file
146
POCloud/python-driver/rigpump.py
Normal file
@@ -0,0 +1,146 @@
|
||||
"""Driver for rigpump."""
|
||||
|
||||
import threading
|
||||
from device_base import deviceBase
|
||||
from Channel import Channel, write_tag, BoolArrayChannels, read_tag
|
||||
from Maps import rigpump_map as maps
|
||||
from random import randint
|
||||
import json
|
||||
import time
|
||||
import socket
|
||||
|
||||
_ = None
|
||||
|
||||
try:
|
||||
with open("persist.json", 'r') as persist_file:
|
||||
persist = json.load(persist_file)
|
||||
except Exception:
|
||||
persist = {}
|
||||
|
||||
PLC_IP_ADDRESS = "192.168.1.10"
|
||||
WATCHDOG_SEND_PERIOD = 3600 # seconds
|
||||
|
||||
|
||||
def reverse_map(value, map_):
|
||||
"""Perform the opposite of mapping to an object."""
|
||||
for x in map_:
|
||||
if map_[x] == value:
|
||||
return x
|
||||
return None
|
||||
|
||||
|
||||
def get_public_ip_address():
|
||||
"""Find the public IP Address of the host device."""
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
s.connect(("8.8.8.8", 80))
|
||||
ip = s.getsockname()[0]
|
||||
s.close()
|
||||
return ip
|
||||
|
||||
|
||||
channels = []
|
||||
|
||||
|
||||
class start(threading.Thread, deviceBase):
|
||||
"""Start class required by Meshify."""
|
||||
|
||||
def __init__(self, name=None, number=None, mac=None, Q=None, mcu=None, companyId=None, offset=None, mqtt=None, Nodes=None):
|
||||
"""Initialize the driver."""
|
||||
threading.Thread.__init__(self)
|
||||
deviceBase.__init__(self, name=name, number=number, mac=mac, Q=Q, mcu=mcu, companyId=companyId, offset=offset, mqtt=mqtt, Nodes=Nodes)
|
||||
|
||||
self.daemon = True
|
||||
self.version = "7"
|
||||
self.finished = threading.Event()
|
||||
self.forceSend = False
|
||||
threading.Thread.start(self)
|
||||
|
||||
# this is a required function for all drivers, its goal is to upload some piece of data
|
||||
# about your device so it can be seen on the web
|
||||
def register(self):
|
||||
"""Register the driver."""
|
||||
# self.sendtodb("log", "BOOM! Booted.", 0)
|
||||
pass
|
||||
|
||||
def run(self):
|
||||
"""Actually run the driver."""
|
||||
global persist
|
||||
|
||||
wait_sec = 60
|
||||
for i in range(0, wait_sec):
|
||||
print("rigpump driver will start in {} seconds".format(wait_sec - i))
|
||||
time.sleep(1)
|
||||
print("BOOM! Starting rigpump driver...")
|
||||
# after its booted up assuming that M1 is now reading modbus data
|
||||
# we can replace the reference made to this device name to the M1 driver with this
|
||||
# driver. The 01 in the 0199 below is the device number you referenced in the modbus wizard
|
||||
self.nodes["rigpump_0199"] = self
|
||||
|
||||
public_ip_address = get_public_ip_address()
|
||||
self.sendtodbDev(1, 'public_ip_address', public_ip_address, 0, 'rigpump')
|
||||
|
||||
watchdog = self.rigpump_watchdog()
|
||||
self.sendtodbDev(1, 'watchdog', watchdog, 0, 'rigpump')
|
||||
watchdog_send_timestamp = time.time()
|
||||
|
||||
send_loops = 0
|
||||
watchdog_loops = 0
|
||||
watchdog_check_after = 5000
|
||||
while True:
|
||||
if self.forceSend:
|
||||
print "FORCE SEND: TRUE"
|
||||
|
||||
# for c in channels:
|
||||
# if c.read(self.forceSend):
|
||||
# self.sendtodb(c.mesh_name, c.value, 0)
|
||||
|
||||
# print("rigpump driver still alive...")
|
||||
if self.forceSend:
|
||||
if send_loops > 2:
|
||||
print("Turning off forceSend")
|
||||
self.forceSend = False
|
||||
send_loops = 0
|
||||
else:
|
||||
send_loops += 1
|
||||
|
||||
watchdog_loops += 1
|
||||
if (watchdog_loops >= watchdog_check_after):
|
||||
test_watchdog = self.rigpump_watchdog()
|
||||
if test_watchdog != watchdog or (time.time() - watchdog_send_timestamp) > WATCHDOG_SEND_PERIOD:
|
||||
self.sendtodbDev(1, 'watchdog', test_watchdog, 0, 'rigpump')
|
||||
watchdog_send_timestamp = time.time()
|
||||
watchdog = test_watchdog
|
||||
|
||||
test_public_ip = get_public_ip_address()
|
||||
if not test_public_ip == public_ip_address:
|
||||
self.sendtodbDev(1, 'public_ip_address', test_public_ip, 0, 'rigpump')
|
||||
public_ip_address = test_public_ip
|
||||
watchdog_loops = 0
|
||||
|
||||
def rigpump_watchdog(self):
|
||||
"""Write a random integer to the PLC and then 1 seconds later check that it has been decremented by 1."""
|
||||
randval = randint(0, 32767)
|
||||
write_tag(str(PLC_IP_ADDRESS), 'watchdog_INT', randval)
|
||||
time.sleep(1)
|
||||
watchdog_val = read_tag(str(PLC_IP_ADDRESS), 'watchdog_INT')
|
||||
try:
|
||||
return (randval - 1) == watchdog_val[0]
|
||||
except (KeyError, TypeError):
|
||||
return False
|
||||
|
||||
def rigpump_sync(self, name, value):
|
||||
"""Sync all data from the driver."""
|
||||
self.forceSend = True
|
||||
# self.sendtodb("log", "synced", 0)
|
||||
return True
|
||||
|
||||
def rigpump_writeplctag(self, name, value):
|
||||
"""Write a value to the PLC."""
|
||||
new_val = json.loads(str(value).replace("'", '"'))
|
||||
tag_n = str(new_val['tag']) # "cmd_Start"
|
||||
val_n = new_val['val']
|
||||
w = write_tag(str(PLC_IP_ADDRESS), tag_n, val_n)
|
||||
print("Result of rigpump_writeplctag(self, {}, {}) = {}".format(name, value, w))
|
||||
if w is None:
|
||||
w = "Error writing to PLC..."
|
||||
return w
|
||||
Reference in New Issue
Block a user