This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Sniffer breaks serial devices

Hi,

During startup the nRF sniffer extcap script does the following:

def find_sniffer(write_data=False):
    open_ports = list_ports.comports()

    sniffers = []
    for port in [x.device for x in open_ports]:
        for rate in SNIFFER_BAUDRATES:
            reader = None
            try:
                reader = Packet.PacketReader(portnum=port, baudrate=rate)
                try:
                    if write_data:
                        reader.sendPingReq()
                        _ = reader.decodeFromSLIP(0.1, complete_timeout=0.1)
                    else:
                        _ = reader.decodeFromSLIP(0.3, complete_timeout=0.3)

                    # FIXME: Should add the baud rate here, but that will be a breaking change
                    sniffers.append(port.encode('ascii', 'ignore'))
                    break
                except (Exceptions.SnifferTimeout, Exceptions.UARTPacketError):
                    pass
            except (serial.SerialException, ValueError):
                continue
            finally:
                if reader is not None:
                    reader.doExit()
    return sniffers

Which (at least on Linux) breaks applications having open serial ports.

Why not instead use serial.tools.list_ports.comports(? Something like this:

        for port in serial.tools.list_ports.comports():
            if "J-Link - CDC" in port.description:
                return port.device

Thanks, Jacob

Related