PySerial - full duplex communication

Is it possible to achieve full duplex communication using PySerial? In particular, is it possible to constantly monitor the port for input and recording if necessary? I suppose this should be possible using streams (and serial interfaces without duplex, no?). If not, what would be the best approach to monitoring a serial port if it is not transmitted? Time-out?

Edit: Here is my attempt. This code is for the TI CC2540 Bluetooth LE chip. When I send a GATT activation message, I expect a response (detailing the operating parameters of the chip) ... I do not receive anything, although

import serial
import threading
from time import sleep

serial_port = serial.Serial()

GAP_DeviceInit  = \
                "\x01\x00\xfe\x26\x08\x03\x00\x00\x00\x00\x00\x00\x00\x00\
                \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
                \x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00"

def read():
    while True:
        data = serial_port.read(9999);
        if len(data) > 0:
            print 'Got:', data

        sleep(0.5)
        print 'not blocked'

def main():
    serial_port.baudrate = 57600
    serial_port.port = '/dev/ttyACM0'
    serial_port.timeout = 0
    if serial_port.isOpen(): serial_port.close()
    serial_port.open()
    t1 = threading.Thread(target=read, args=())
    while True:
        try:
            command = raw_input('Enter a command to send to the Keyfob: \n\t')
            if (command == "1"):
                serial_port.write(message)
        except KeyboardInterrupt:
            break
    serial_port.close()
+5
source share
2 answers

. , Rx Tx . , , .

+3

, -.

0

All Articles