This repository has been archived by the owner on Nov 1, 2018. It is now read-only.
forked from karioja/vedirect
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathvedirectsim.py
54 lines (43 loc) · 1.94 KB
/
vedirectsim.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
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os, serial, time
class vedirectsim:
def __init__(self, serialport):
self.serialport = serialport
self.ser = serial.Serial(serialport, 19200, timeout=10)
self.dict = {'V': '12800', 'VS': '12800', 'VM': '1280', 'DM': '120',
'VPV': '3350', 'PPV': '130', 'I': '15000', 'IL': '1500',
'LOAD': 'ON', 'T': '25', 'P': '130', 'CE': '13500',
'SOC': '876', 'TTG': '45', 'Alarm': 'OFF', 'Relay': 'OFF',
'AR': '1', 'H1': '55000', 'H2': '15000', 'H3': '13000',
'H4': '230', 'H5': '12', 'H6': '234000', 'H7': '11000',
'H8': '14800', 'H9': '7200', 'H10': '45', 'H11': '5',
'H12': '0', 'H13': '0', 'H14': '0', 'H15': '11500',
'H16': '14800', 'H17': '34', 'H18': '45', 'H19': '456',
'H20': '45', 'H21': '300', 'H22': '45', 'H23': '350',
'ERR': '0', 'CS': '5', 'BMV': '702', 'FW': '1.19',
'PID': '0x204', 'SER#': 'HQ141112345', 'HSDS': '0'}
def convert(self, datadict):
result = list()
for key in self.dict:
result.append(ord('\r'))
result.append(ord('\n'))
result.extend([ord(i) for i in key])
result.append(ord('\t'))
result.extend([ord(i) for i in datadict[key]])
# checksum
result.append(ord('\r'))
result.append(ord('\n'))
result.extend([ord(i) for i in 'Checksum'])
result.append(ord('\t'))
result.append(256 - (sum(result) % 256))
return result
def send_packet(self):
packet = self.convert(self.dict)
for k in packet:
self.ser.write(chr(k))
if __name__ == '__main__':
ve = vedirectsim('/tmp/vmodem0')
while True:
ve.send_packet()
time.sleep(1)