-
Notifications
You must be signed in to change notification settings - Fork 0
/
railtest.py
83 lines (59 loc) · 2.34 KB
/
railtest.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
import serial
import time
class RailTest:
def __init__(self, portname, baudrate=115200, xonxoff=False, rtscts=False, timeout=10):
self.portname = portname
self.timeout = timeout
self.port = None
try:
self.port = serial.Serial(port=self.portname,
baudrate=baudrate,
bytesize=serial.EIGHTBITS,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
timeout=timeout,
xonxoff=xonxoff,
rtscts=rtscts,
dsrdtr=False)
except Exception as e:
raise e
self.EOL = '\r\n'
def __del__(self):
if self.port != None:
self.port.close()
def __sendCommand(self, command, *args):
outputString = ''
outputString += command
for arg in args:
outputString += ' ' + arg
outputString += self.EOL
self.port.flushInput()
self.port.write(outputString)
return outputString
def rx(self, state):
self.__sendCommand('rx', str(state))
def setZwaveMode(self, val1, val2):
self.__sendCommand('SetZwaveMode', str(val1), str(val2))
def setTxLength(self, value):
self.__sendCommand('SetTxLength', str(value))
def setTxPayload(self, val1, val2):
self.__sendCommand('SetTxPayload', str(val1), str(val2))
def setZwaveRegion(self, value):
self.__sendCommand('SetZwaveRegion', str(value))
def setPower(self, power, ptype):
self.__sendCommand('SetPower', str(power), ptype)
def setChannel(self, channel):
self.__sendCommand(str(channel))
def setTxTone(self, state):
self.__sendCommand('setTxTone', state)
def testByCwWithoutSaw(self, region=0, powerValue=0, powerType='raw' channel=1, timeout=10):
self.rx(0)
self.setZwaveMode(1, 3)
self.setTxLength(20)
self.setTxPayload(7, 20)
self.setZwaveRegion(region)
self.setPower(powerValue, powerType)
self.setChannel(channel)
self.setTxTone(1)
time.sleep(timeout)
self.setTxTone(0)