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:

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

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

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

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

Thanks, Jacob

  • Hi,

    There is a new nRF sniffer planned released on Friday, so I suggest to wait for that.

    Best regards,
    Kenneth

  • Hi,

    When looking at the code for 3.0.0 this piece of code looks identical.

    Thanks, Jacob

  • Okey, I have reported it for improvement for future.

    Kenneth

  • The problem here is that some users do not use J-Link at all, and  your proposed patch would break nRF Sniffer for Bluetooth LE for them.

    How about opening your other applications' ports in exclusive mode so that the sniffer script you paste is unable to open the serial port?

  • Right.

    Sure, but that means that the sniffer script also has to open the port in exclusive mode in order for it to work.

    Thanks, Jacob

1 2 3