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
|
import sh
from sh import flashcp
from sh import flash_eraseall
from sh import ErrorReturnCode
from sh import Command
from test.helpers.gpio import gpio
import time
class dcpPLC(object):
__nReset = None
__Phy = None
__Plc = None
__mtd_device = None
__factool = None
__myConfigTool = None
def __init__(self, plcfactool, mtd_device):
# default save firmware
self.__nRest = gpio('75', 'out', '0')
self.__nRest = gpio('69', 'out', '0')
self.__nRest = gpio('78', 'out', '1')
self.__factool = plcfactool
self.__mtd_device = mtd_device
self.__myConfigTool = Command(self.__factool)
def setSaveFirmwareMode(self):
self.__nRest = gpio('75', 'out', '0')
self.__nRest = gpio('69', 'out', '0')
self.__nRest = gpio('78', 'out', '1')
def setBootMode(self):
self.__nRest = gpio('78', 'out', '0')
self.__nRest = gpio('75', 'out', '1')
self.__nRest = gpio('69', 'out', '1')
def setPLCReset(self):
self.__nRest = gpio('75', 'out', '0')
self.__nRest = gpio('69', 'out', '0')
time.sleep(0.25)
self.__nRest = gpio('69', 'out', '1')
self.__nRest = gpio('75', 'out', '1')
def SaveFirmware(self, firmare):
self.setSaveFirmwareMode()
try:
flash_eraseall(self.__mtd_device)
flashcp(firmare, self.__mtd_device)
except ErrorReturnCode as Error:
return False, "plc flash firmware failed {} ".format(Error.exit_code)
return True, ''
def set_plc (self, var, value, password):
try:
res = self.__myConfigTool("-o", "SET", "-p", "{}={}".format(var, value), "-w", "{}".format(password))
print(res)
except ErrorReturnCode as Error:
return False, "set var failed {} {}".format(var,Error.exit_code)
return True, ''
def set_plc2 (self, var1, value1,var2, value2, password):
try:
res = self.__myConfigTool("-o", "SET", "-p", "{}={}".format(var1, value1), "-p", "{}={}".format(var2, value2), "-w", "{}".format(password))
print(res)
except ErrorReturnCode as Error:
return False, "set var failed {}".format(Error.exit_code)
return True, ''
def get_plc (self, var, value, password):
try:
self.__myConfigTool("-o", "GET", "-p", "{}".format(var), '{}'.format(value), "-w", "{}".format(password))
except ErrorReturnCode as Error:
return False, "set var failed {} {}".format(var,Error.exit_code)
return True, ''
|