Ejemplo n.º 1
0
def ser_open():
    try:
        ser_1.open()
        channel.listener_connection(ser_1.isOpen())
    except Exception as e:
        print("error open serial port: " + str(e))
        exit()
Ejemplo n.º 2
0
def ser_read(ser=ser_1):
    global priem
    global frames
    global read_delay
    if ser.isOpen():
        if priem == 0:
            channel.listener_user_connection(ser.dsr)
            channel.listener_connection(ser_1.isOpen())
            print('ser_read top', ser_1.isOpen(), ser_1.dsr)
            #print(ser.cts, ser.dsr, ser.ri, ser.cd)
        if ser.in_waiting == 0 and priem == 1:
            priem = 0
            read_delay = 0.5
            channel.receive(frames)
            frames = []
        while ser.in_waiting > 0:
            if priem == 0:
                priem = 1
                read_delay = 0.0001
            print('in_waiting', ser_1.in_waiting)
            while ser.in_waiting >= 238:
                response = ser.read(238)
                #print('READ', ser_2.in_waiting, datetime.datetime.now())
                frames.append(response)
    else:
        channel.listener_connection(ser_1.isOpen())
        channel.listener_user_connection(False)
        print("cannot open serial port, read", ser_1.isOpen())
        return 1
    threading.Timer(read_delay, ser_read).start()
Ejemplo n.º 3
0
def ser_write(binary_message):
    ser_1.flushInput()  # flush input buffer, discarding all its contents
    ser_1.flushOutput()  # flush output buffer, aborting current output
    channel.listener_connection(ser_1.isOpen())
    channel.listener_user_connection(ser_1.dsr)
    print('ser_write top', ser_1.isOpen(), ser_1.dsr)
    if ser_1.isOpen() and ser_1.dsr and ser_1.cts:
        for frame in binary_message:
            try:
                ser_1.write(frame)
                #print('WRITE', i, datetime.datetime.now())
                ser_1.flush()
            except Exception as e1:
                if not ser_1.cts:
                    channel.listener_transmission_failed()
                print("error communicating write...: " + str(e1))
    elif ser_1.isOpen() and not ser_1.cts:
        channel.listener_transmission_failed()
    else:
        channel.listener_connection(ser_1.isOpen())
        channel.listener_user_connection(ser_1.dsr)
        print("cannot open serial port, write", ser_1.isOpen(), ser_1.dsr)