1

I have a hardware setup with one lock controller Made in China, I have setted up everything as it was supposed to, trying to communicate with the device with Python Script, lsusb show me the device connected as "Cygnal Integrated Products, Inc. CP210x UART Bridge / myAVR mySmartUSB light" the device address is "ttyUSB0" i have runned several scripts but i am not getting any answer back from the unit, i have even connect it to a Windows machine and run RealTerm and TeraTerm to send hexadecimal strings as the communication protocol of the device dictates, i have setted up the monitor on to see if there is any response and nothing happens.

Baudrate: 9600 parity:none stopbits=1 Checkbits=No DateBits=8

this is the comunication protocol:

Communication Agreement

  1. Communication interface: RS485 Baud rate: 9600 Check bits: No Date bits: 8 Stop bits: 1

  2. Plate address query The main engine should send the command to the slave plate, the plate address is 0x1 to 0xf, when receive the confirmation reply, we can think the slave plate of the plate address is existence.

    Command header plate address Fixation Status Check code (XOR) 0X81 0X01 - 0x1F 0X01 0X99 0X18

    Return: Command header Slave plate address Fixation Fixation Check bits 0X81 0X01 - 0x1F 0X01 0X99 XXXX

  3. Unlock command is below: Command plate address Lock address Status Check code (XOR) 0X8A 0X01 - 0x1F 0X01 – 32 0X11 XX

eg: Upper computer send 0X8A 0X02 0X01 0X11 0X98 (hexadecimal), open the control cabinet door, return after 1 second:

Command plate address Lock address Status Check code 0X8A 0X02 0X01 0X11 0X98(Lock Open) 0X8A 0X02 0X01 0X00 0X89(Lock Close)

  1. Read the lock status command(The feedback of the door switch status) Start plate address Lock address Command Check code (XOR) 0X80 0X01 – 0XF 0X00-32 0X33 XX The lock address is 0X00, return the status of all of the locks, if it’s not 0, then it will back to this lock status.

    eg: a. Return back to the status of lock 1 eg: Upper computer send 0X80 0X01 0X01 0X33 0XB2 (hexadecimal), return Command plate address Lock address Status Check cod (Lock Open) 0X80 0X01 0X01 0X00 0X80 (Lock Close b. Return back to the status of all of the locks:

eg: Host machine send 0X80 0X01 0X00 0X33 0XB2 (hexadecimal),return Start plate address Status1 Status2 Status3 Status4 Status5 Status6 Status7

Command Check cod 0X80 0X01 0XFF 0XFF 0XFF 0XFF 0XFF 0XFF 0XFF 0X33 0XXX

Status: From status 1 to Status 7, high to low, the corresponding lock is 1-50.

  1. Read the agreement identifiers command Android main board send the agreement identifiers command to confirm the agreement version number of the lock control board

Start plate address Command1 Command2 Check code (XOR) 0X91 0X1-0XF 0XFE 0XFE 0xXX

Return Start plate address Command1 Version NO. Check code (XOR) 0X91 0X1-0XF 0X6d 0X03 0xXX

so i type the commands directly to the send tab of RealTerm and i just can see the sent command but there is no response.

I am using Python. Code sample next:

#!/usr/bin/env python

# based on tutorials:
#   http://www.roman10.net/serial-port-communication-in-python/
#   http://www.brettdangerfield.com/post/raspberrypi_tempature_monitor_project/

import serial, time

SERIALPORT = "/dev/ttyUSB0"
BAUDRATE = 9600

ser = serial.Serial(SERIALPORT, BAUDRATE)

ser.bytesize = serial.EIGHTBITS #number of bits per bytes

ser.parity = serial.PARITY_NONE #set parity check: no parity

ser.stopbits = serial.STOPBITS_ONE #number of stop bits

#ser.timeout = None          #block read

#ser.timeout = 0             #non-block read

ser.timeout = 2              #timeout block read

ser.xonxoff = False     #disable software flow control

ser.rtscts = False     #disable hardware (RTS/CTS) flow control

ser.dsrdtr = False       #disable hardware (DSR/DTR) flow control

ser.writeTimeout = 0     #timeout for write

print 'Starting Up Serial Monitor'

try:
    ser.open()

except Exception, e:
    print "error open serial port: " + str(e)
    exit()

if ser.isOpen():

    try:
        ser.flushInput() #flush input buffer, discarding all its contents
        ser.flushOutput()#flush output buffer, aborting current output

        # ser.write (serial.to_bytes([0x80,0x01,0x33,0xB2]))     # Test Line
        ser.write("0X80,0X01,0X00,0X33,0XB2")
        print("write data: Status command")
        time.sleep(0.5)
        numberOfLine = 0

        while True:

            response = ser.readline()
            print("read data: " + response)

            numberOfLine = numberOfLine + 1
            if (numberOfLine >= 5):
                break

        ser.close()

    except Exception, e:
        print "error communicating...: " + str(e)

else:
    print "cannot open serial port "

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.