Small console utility to control SZ_IO62 controller

Commands:

-h - Show help list with commands
./SZ_IO62R2 "COMMAND" or SZ_IO62R2.exe "COMMAND" - Send command to controller

Command List:

Input activation commands:
sI1, cI1, sI2, cI2, sI3, cI3, sI4, cI4, sI5, cI5, sI6, cI6, sV7, sV8
Output activation commands:
out1, out2, out3, out4, out5, out6, out7, out8

Starting app

Edit config.txt COM port settings Windows COM port name "COMx" x - Port name (1,2…) Linux Com port name "/dev/ttyUSB0" USB0 - Port name (1,2…)
Run "./bridge" or "bridge.exe" as service
Run ./SZ_IO62R2 "COMMAND" or SZ_IO62R2.exe "COMMAND"

Depends

Program depends on pySerial Module can be installed by command pip install pyserial

Screenshots

Code

main.py

import sys 
import os
    
# Help function
def help_f():
    print("""
    
SZ_IO62R2 controller serial utility
    
Commands:
    
    -h - Show help list with commands
    ./SZ_IO62R2 "COMMAND" or SZ_IO62R2.exe "COMMAND" -  Send command to controller

Command List:

    Input activation commands:
    sI1, cI1, sI2, cI2, sI3, cI3, sI4, cI4, sI5, cI5, sI6, cI6, sV7, sV8 
    Output activation commands:
    out1, out2, out3, out4, out5, out6, out7, out8

    """)


# Listen for arguments 
if len(sys.argv) > 1:
    with open('commands', 'w') as f:
        f.write(sys.argv[1])
        f.close()
else:
    help_f()

bridge.py

import serial
import time
import os


# COM port config from config.txt
with open('config.txt') as f:
   lines = f.readlines()


for line in lines:
   if "PORT" in line:
       port_com = line.split(" = ")[1]
       rep=["\n"]
       for r in rep:
          port_com=port_com.replace(r,"")


# COM port starting
ser = serial.Serial(port=port_com, baudrate=9600, timeout=.1)

# Wait while controller boot after serial connected
time.sleep(2)

# Read boot stuff information
while ser.readline():
    unused_data = ser.readline()

# Bridge function
while True:

    time.sleep(0.1)
    if os.path.isfile('commands'):
        with open('commands', 'r') as f:
                cmd = f.read()+ '\r\n'
                ser.write(cmd.encode())
                f.close()
        os.remove('commands')

config.txt

PORT = COM5

Video

Source code

Download

Compiled to Windows and Linux

Download

Link to SZ_IO62R2 module Page

https://sznetwork.systems/index.php/projects/sz_io62r2/
SZ_IO62R2 page updates BUG FIXing
SZ_IO62R2 1.02 version update

Leave a Comment

Your email address will not be published. Required fields are marked *