-
Notifications
You must be signed in to change notification settings - Fork 1
/
serial_check.py
executable file
·52 lines (43 loc) · 1.06 KB
/
serial_check.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
#!/usr/bin/env python
import time
import serial
import sys, os
try:
ser_send = serial.Serial(
port='/dev/ttyAMA0', baudrate = 1200, timeout=1,
parity=serial.PARITY_EVEN,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.SEVENBITS
)
ser_recv = serial.Serial(
port='/dev/ttyUSB0', baudrate = 1200, timeout=1,
parity=serial.PARITY_EVEN,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.SEVENBITS
)
counter=0
# Try send receive 10 times
while counter<20:
sys.stdout.write('Sending Teleinfo %d ... '%(counter))
sys.stdout.flush()
# Send data
ser_send.write('Teleinfo %d\n'%(counter))
time.sleep(1)
# Try to read Data back
s=ser_recv.readline()
# Data correct ?
if s.find("Teleinfo") != -1 or s.find("MOTDETAT ") != -1:
print "Transmission OK"
ser_recv.close()
ser_send.close()
os._exit(0)
else:
print "Nothing Received!"
print s
counter += 1
# Clean exit even if error
ser_recv.close()
ser_send.close()
os._exit(1)
except:
os._exit(1)