Created
October 30, 2016 08:41
-
-
Save metametaclass/fdcd53e4e699ed5a0a780bc74a8a5eca to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import serial | |
import time | |
import sys | |
import socket | |
import datetime | |
s = None | |
sock = None | |
def setup(): | |
global s | |
global sock | |
s = serial.Serial("/dev/ttyS0", 9600, timeout=1) | |
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # UDP | |
def loop(): | |
b = bytearray([0xFF, 0x01, 0x86, 0x00, 0x00, 0x00, 0x00, 0x00, 0x79]) | |
#print('q'); | |
s.write(b) | |
time.sleep(1) | |
result = s.read(9) | |
#print('a', type(result)) | |
msg = datetime.datetime.now().isoformat()+","+result.encode("hex")+","+str(ord(result[2])*256+ord(result[3]))+'\n' | |
sock.sendto(msg, ("192.168.1.4", 0xC0C0)) | |
sock.sendto(msg, ("192.168.1.4", 0xC0C1)) | |
for i in result: | |
sys.stdout.write(hex(ord(i))) | |
sys.stdout.write(' ') | |
sys.stdout.write('\n') | |
sys.stdout.flush | |
time.sleep(14) | |
if __name__ == '__main__': | |
setup() | |
while True: | |
loop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment