generated from github/welcome-to-github-and-desktop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
seralrs485.py
35 lines (27 loc) · 1.07 KB
/
seralrs485.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
import serial
import serial.rs485
import time
import RPi.GPIO as GPIO
TXDEN_1=7
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(TXDEN_1, GPIO.OUT, initial=GPIO.HIGH)
ser=serial.rs485.RS485(port='/dev/ttySC0',baudrate=9600,timeout=5,parity=serial.PARITY_EVEN)
ser.rs485_mode = serial.rs485.RS485Settings(rts_level_for_tx=False,
rts_level_for_rx=False,
delay_before_tx=0.0,
delay_before_rx=-0.0)
SendFrame =b'\x01\x03\x00\x02\x00\x01\x25\xCA'
#SendFrame='\x01\x06\x00\x09\x00\x01\x98\x08' #0x0898
#SendFrame ='\x01\x06\x00\x06\x00\x0A\xE9\xCC' #0AE8 #0xCA29 #0xCCE9 write reg 6
#SendFrame='\x01\x03\x00\x00\x00\x0e\xc4\x0e' #0x0EC4
while True:
GPIO.output(TXDEN_1, GPIO.HIGH)
ser.write(SendFrame)
GPIO.output(TXDEN_1, GPIO.LOW) #read
coming_data = ser.inWaiting()
print "comming_data:",coming_data
x=ser.read(ser.inWaiting())
print repr(x)
print "ok"
time.sleep(2)