

FIRST channel commands:
OFF command : FF 01 00 (HEX) or 255 1 0 (DEC)
ON command : FF 01 01 (HEX) or 255 1 1 (DEC)
(1) Verify Python Interpreter Availability with ‘helloworld.py’
#!/usr/bin/python # Hello world python program print "Hello World!";
(2) Create ‘kmtronic_usb_relay_test.py” file
(3) Copy and paste code:
#!/usr/bin/python # Test KMtronic WEB Relay board print "Test KMtronic USB Relay board"; import os import time import serial import subprocess from struct import pack, unpack, calcsize # configure the serial connections # (the parameters differs on the device # you are connecting to) ser = serial.Serial( port='/dev/ttyUSB0', baudrate=9600, stopbits=serial.STOPBITS_ONE, bytesize=serial.EIGHTBITS, parity=serial.PARITY_NONE ) ser.isOpen() channel = 0x01; print "RELAY1_ON_COMMAND: 0xFF 0x01 0x01" state = 0x01; int_msg = [0xFF, channel, state] byte_msg = map(chr, int_msg) packet = pack('=ccc', *byte_msg) ser.write(packet) time.sleep(1) print "RELAY1_OFF_COMMAND: 0xFF 0x01 0x00" state = 0; int_msg = [0xFF, channel, state] byte_msg = map(chr, int_msg) packet = pack('=ccc', *byte_msg) ser.write(packet) ser.close()
