0

Can anyone explain where my mistake is

import time, serial
from _poll_msg import *
from exception import BadCRC
ser = serial.Serial()
ser.parity = serial.PARITY_NONE
ser.baudrate= 19200
ser.port = '/dev/ttyUSB0'
ser.open()

def write(cmd):
    ser.flushOutput()
    ser.parity = serial.PARITY_MARK
    ser.write(('82'+ mashin_n).decode('hex'))
    crc = crc_sas(mashin_n + cmd)
    cmd = cmd + crc
    ser.parity = serial.PARITY_SPACE
    ser.write(cmd.decode('hex'))
    return True

def read(size):
    response = ser.read(size).encode('hex')
    # with ttyUSB? response is 011912345678crc
    # with ttyS? response = 0101010101
    # but error is in write (010101 - command is bad)
    time.sleep(0.2)
    try:
        crc_sas(response, chk=True)
    except BadCRC:
        return False
    return response[4:-4]

It works without error. But if I change port to /dev/ttyS1 It does not work. Where's the difference and where I'm wrong.

0 Answers0