Field | Starting byte | Team size (number + data) | Current status | Team number | Command data | Check sum |
The size | one | one | one | one | 0-254 | one |
Value | 0x7E | 1 - 255 0 - error | A bit field that determines the current state of each type of device. | 1 - 255 0 - error | Determined by the team | The sum of all previous message fields, including the start byte |
Team number | Command description | Data |
0x01 | Device Type Request | not |
0x02 | Device Type Response | 1 byte: 0 - error 1 - measuring part 2 - interface part 3 - PC |
0x03 | Serial Number Request | not |
0x04 | Serial Number Answer | 2 bytes |
0x05 | Request software version | not |
0x06 | Answer software version | 2 bytes |
0x07 | Request Iron Version | not |
0x08 | Iron version response | 2 bytes |
0x0A | Set port status | 1 byte |
0x0B | Request port status | not |
0x0C | Port Status Response | 1 byte |
0x0D | Turn on beeper, ms | 1-2 bytes |
0x0E | Jumper Status Request | not |
0x0F | Jumper Status Response | 1 byte |
0x10 | Request for input status (optocoupler) | not |
0x11 | Input Status Response | 1 byte |
0x12 | Query the number of input fronts | 1 byte (login number) |
0x13 | Answer the number of fronts of inputs | 5 bytes: 1st byte - entry number 2-3 bytes - the number of leading fronts 4-5 bytes - the number of rear edges |
0x14 | Batch request for the status of the inputs and the number of edges | not |
0x15 | Response to batch request for the status of inputs and counters of the number of edges | 33 bytes: 1st byte - input status 2-17 bytes - the number of leading edges of 2 bytes per input starting from zero 18-33 bytes - the number of rear edges of 2 bytes per input starting from zero |
0x16 | Resetting front counters | No (a 0x15 command with zero counter values is issued in response) |
0x20 | Setting the auto flashing bits of the outputs | 1 byte |
0x21 | Request set bits flashing outputs | not |
0x22 | The response of the set bits flashing outputs | 1 byte |
0x23 | Setting the blink time of output | 3 bytes: 1st byte - exit number 2-3 bytes - period in ms The default period is 500ms. If bytes 2-3 are 0, then the default period is set. |
0x24 | Output flashing period response | 3 bytes (similar to the 0x23 command) |
#! /usr/bin/env python3 import sys, os, termios, threading, time, http.client if len(sys.argv)<=1: sys.exit("Usage: {0} CONFIG-FILE".format(sys.argv[0])) exec(open(sys.argv[1], "rt").read()) portfd=os.open(serialport, os.O_RDWR) # Configure serial port - make it "raw", set 9600 baud rate and 8N1 iflag,oflag,cflag,lflag,ispeed,ospeed,cc=tuple(termios.tcgetattr(portfd)) iflag&=~(termios.IGNBRK|termios.BRKINT|termios.PARMRK|termios.ISTRIP|termios.INLCR|termios.IGNCR|termios.ICRNL|termios.IXON) oflag&=~(termios.OPOST) lflag&=~(termios.ECHO|termios.ECHONL|termios.ICANON|termios.ISIG|termios.IEXTEN) cflag&=~(termios.CSIZE|termios.PARENB|termios.CSTOPB) cflag|=termios.CS8 ispeed=termios.B9600 ospeed=termios.B9600 termios.tcsetattr(portfd, termios.TCSANOW, [iflag, oflag, cflag, lflag, ispeed, ospeed, cc]) # Current state of traffic light: # 0 - fail (red light) # 1 - success (green light) # 2 - in progress (yellow light) # 3 - no data (blinking yellow) state=3 RED=0 YELLOW=1 GREEN=2 def trafficLightControl(light): cmd=[0x7E, 0x02, 0xFF, 0x0A] if light==RED: cmd.append(1) elif light==YELLOW: cmd.append(2) elif light==GREEN: cmd.append(4) else: cmd.append(0) cmd.append(sum(cmd)&0xFF) os.write(portfd, bytes(cmd)) def controlThreadProc(): while True: if state==0: trafficLightControl(RED) elif state==1: trafficLightControl(GREEN) elif state==2: trafficLightControl(YELLOW) else: trafficLightControl(YELLOW) time.sleep(1.5) trafficLightControl(None) time.sleep(1.5) controlThread=threading.Thread(target=controlThreadProc) controlThread.start() def pollThreadProc(): global state connection=None while True: try: if connection is None: connection=http.client.HTTPConnection(server) connection.request("GET", "/{0}/status?test={1}".format(project, ",".join(tests))) r=connection.getresponse().readall() state=int(r.decode("ascii")) except: state=3 connection=None time.sleep(5) pollThread=threading.Thread(target=pollThreadProc) pollThread.start()
server="192.168.2.245" project="tvz-win-trunk" tests=['build', 'xmlcheck', 'qdebug', 'runss', 'runssc', 'tr_en', 'trcyr_en', 'warning1', 'warning10', 'warning100', 'xmldeps', 'issue16683a', 'issue17071', 'issue16796', 'runmain', 'issue17319', 'issue17318', 'issue17396a', 'smartstation_su', 'xmlrpcdoc_ss', 'src_encoding', 'issue17241', 'issue17228'] serialport="/dev/ttyUSB0"
Source: https://habr.com/ru/post/216743/
All Articles