Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

serial.serialutil.SerialException: Attempting to use a port that is not open #7

Open
itemir opened this issue Nov 13, 2016 · 25 comments

Comments

@itemir
Copy link

itemir commented Nov 13, 2016

Trying to use sniffer.py on macOS Sierra (10.12.1) is giving errors:

$ sudo python sniffer.py /dev/tty.usbserial-DJ00IO3W
Password:
Logging data to logs/capture.pcap
Connecting to sniffer on /dev/tty.usbserial-DJ00IO3W
Scanning for BLE devices (5s) ...
Traceback (most recent call last):
  File "sniffer.py", line 156, in <module>
    devlist = scanForDevices()
  File "sniffer.py", line 50, in scanForDevices
    mySniffer.scan()
  File "/Users/itemir/Temp/Adafruit_BLESniffer_Python/SnifferAPI/Sniffer.py", line 62, in scan
    self._startScanning()
  File "/Users/itemir/Temp/Adafruit_BLESniffer_Python/SnifferAPI/SnifferCollector.py", line 206, in _startScanning
    self._packetReader.sendScan()
  File "/Users/itemir/Temp/Adafruit_BLESniffer_Python/SnifferAPI/Packet.py", line 186, in sendScan
    self.sendPacket(REQ_SCAN_CONT, [], timeout)
  File "/Users/itemir/Temp/Adafruit_BLESniffer_Python/SnifferAPI/Packet.py", line 183, in sendPacket
    self.uart.writeList(packetString, timeout)
  File "/Users/itemir/Temp/Adafruit_BLESniffer_Python/SnifferAPI/UART.py", line 73, in writeList
    nBytes = self.ser.write(array)
  File "/Library/Python/2.7/site-packages/serial/serialposix.py", line 497, in write
    raise portNotOpenError
serial.serialutil.SerialException: Attempting to use a port that is not open

ble-sniffer-osx from Roland King works, so it is not an OS issue nor a hardware issue.

It also looks like there have been others who ran into this issue. See the following thread: https://forums.adafruit.com/viewtopic.php?f=22&t=82839&sid=643613138ca6829f5444dd61c1cabc7d&start=15 (Workaround mentioned there, to install 2.3 FTDI driver, does also not work).

@ckuethe
Copy link
Contributor

ckuethe commented Nov 21, 2016

I've seen this a few times on Linux 4.8.8 today; I'm guessing it's a hardware problem related to my USB hub.

@mandersen
Copy link

Still seeing this with macOS 10.12.3 (16D32). ble-sniffer-osx works, but not sniffer.py. Fails with same error as above.

@vshymanskyy
Copy link

vshymanskyy commented Mar 8, 2017

I think I had the same problem on Linux, and I have finally fixed it. I'm still working on it, and will publish a fix on my fork soon: https://github.com/vshymanskyy/BLESniffer_Python

@vshymanskyy
Copy link

Ok, seems to be fixed on my fork: https://github.com/vshymanskyy/BLESniffer_Python

@itemir
Copy link
Author

itemir commented Mar 8, 2017

Thanks for the fix. Unfortunately I cannot test it as I sent the unit back.

@dsweetkulshantechnology
Copy link

I was running into the same issue on macOS today and came across this bug.

Tried @vshymanskyy 's latest fork and crash no longer happens. However, it appears it is not detecting any devices in the scan and sits in a Scanning for BLE devices (5s) ... loop forever. I know there are devices advertising and my HW is functional since the same setup is receiving packets on the PC version+wireshark.

It also appears my log file is filling up with "SLIP skipped" exceptions, which appears to be a new addition.

@vshymanskyy
Copy link

vshymanskyy commented Mar 9, 2017

@dsweetkulshantechnology "SLIP skipped" was added to diagnose Serial stream errors.
I cannot test on OSX currently. What is syour version of OSX and hardware? Thx.
Could you also check my for on a PC? it also supports live capturing with --pipe flag

@vshymanskyy
Copy link

vshymanskyy commented Mar 9, 2017

Also, my version should show FW version: 1111.
if it shows version 0, it means it just can't get in sync with serial stream. You can try this:

  1. unplug the board
  2. plug it in
  3. wait 10 secs
  4. run the sniffer script

@vshymanskyy
Copy link

@dsweetkulshantechnology please try my latest master branch - it works with my OSX

@dsweetkulshantechnology
Copy link

@vshymanskyy OSX Version 10.11.6 (El Capitan) on MBP, using the AdaFruit BlueFruit sniffer.

With latest version I can't seem to get anything except Firmware Version: 0 - tried replugging multiple times with varying delays.

Same result on Win7 PC (Firmware Version: 0).

On the PC with the Nordic SW (same HW dongle) I get the following (Version 12?!):
image

@jmartin-usna
Copy link

I am running Ubuntu 16.04, using the Adafruit Bluefruit LE sniffer.

I have the same issues, unable to connect to the board:

Capturing data to logs/capture.pcap
Connecting to sniffer on /dev/ttyUSB0
Software Version: 1111
Firmware Version: 0
Sniffer board is not responding. Please re-plug the board.

@vshymanskyy
Copy link

vshymanskyy commented Mar 11, 2017

@jmartin-usna , @dsweetkulshantechnology - I think it would be best if I can perform some live debugging session with one of you guys.

@nad0m
Copy link

nad0m commented Mar 13, 2017

I am having the same exact issue. I've tried on all three platforms: Mac OS, Windows, and Linux.

@hindfelt
Copy link

Hi,

I get the same problem unfortunately.

@alexeicolin
Copy link

On my Arch Linux box and Adafruit BLE Sniffer (the CP210x one), this error reported above: "Sniffer board is not responding. Please re-plug the board." happens only for @vshymanskyy fork, not in this repo. With this repo, sniffer produces the pcap file fine.

@gnyman
Copy link

gnyman commented Jul 28, 2017

I solved this by editing line 246 in SnifferAPI/Packet.py

--- a/SnifferAPI/Packet.py
+++ b/SnifferAPI/Packet.py
@@ -243,7 +243,7 @@ class PacketReader(Notifications.Notifier):

             try:
                 self.uart.ser.port = iPort
-                self.uart.ser.open()
+                self.uart.ser.isOpen()
                 self.sendPingReq()
                 startTime = time.time()
                 continueLoop = True

@dbenninger
Copy link

dbenninger commented Aug 25, 2017

Thanks @gnyman, that solved the issue on my mac.

The problem is now that it does not find any devices:

Capturing data to logs/capture.pcap
Connecting to sniffer on /dev/tty.SLAB_USBtoUART
Scanning for BLE devices (5s) ...
Scanning for BLE devices (5s) ...
Scanning for BLE devices (5s) ...
Scanning for BLE devices (5s) ...
Scanning for BLE devices (5s) ...
Scanning for BLE devices (5s) ...
Scanning for BLE devices (5s) ...
Scanning for BLE devices (5s) ...
Scanning for BLE devices (5s) ...
Scanning for BLE devices (5s) ...
Scanning for BLE devices (5s) ...
Scanning for BLE devices (5s) ...
Scanning for BLE devices (5s) ...
Scanning for BLE devices (5s) ...
Scanning for BLE devices (5s) ...
Scanning for BLE devices (5s) ...
Scanning for BLE devices (5s) ...
Scanning for BLE devices (5s) ...
Scanning for BLE devices (5s) ...

It finds a lot on the windows machine...

@ladyada
Copy link
Member

ladyada commented Aug 25, 2017

uninstall the macos driver and re-install v4 - silabs released a broken driver

http://community.silabs.com/t5/Interface-Knowledge-Base/Legacy-OS-Software-and-Driver-Packages/ta-p/182585

you will need to uninstall the old driver using the script included ^ some people had to uninstall twice before re-installing

@dbenninger
Copy link

Uninstalled the driver, restarted my mac and installed the sw from the link above. Still the same issue...

@sonelu
Copy link

sonelu commented Nov 7, 2017

This is clearly a problem with the Python code.

If I run the sniffer like this:

python sniffer.py /dev/blabla

the result is:

Capturing data to logs/capture.pcap
Connecting to sniffer on /dev/blabla
Scanning for BLE devices (5s) ...
Traceback (most recent call last):
  File "sniffer.py", line 184, in <module>
    devlist = scanForDevices()
  File "sniffer.py", line 51, in scanForDevices
    mySniffer.scan()
  File "/Users/alexandrusonea/Documents/ROBOTS/Adafruit_BLESniffer_Python-master/SnifferAPI/Sniffer.py", line 62, in scan
    self._startScanning()
  File "/Users/alexandrusonea/Documents/ROBOTS/Adafruit_BLESniffer_Python-master/SnifferAPI/SnifferCollector.py", line 206, in _startScanning
    self._packetReader.sendScan()
  File "/Users/alexandrusonea/Documents/ROBOTS/Adafruit_BLESniffer_Python-master/SnifferAPI/Packet.py", line 186, in sendScan
    self.sendPacket(REQ_SCAN_CONT, [], timeout)
  File "/Users/alexandrusonea/Documents/ROBOTS/Adafruit_BLESniffer_Python-master/SnifferAPI/Packet.py", line 183, in sendPacket
    self.uart.writeList(packetString, timeout)
  File "/Users/alexandrusonea/Documents/ROBOTS/Adafruit_BLESniffer_Python-master/SnifferAPI/UART.py", line 73, in writeList
    nBytes = self.ser.write(array)
  File "/Users/alexandrusonea/anaconda/lib/python2.7/site-packages/serial/serialposix.py", line 531, in write
    raise portNotOpenError
serial.serialutil.SerialException: Attempting to use a port that is not open

there is no message that the port does not exist and was not able to open.

Reinstalling the driver had no effect.
I'm on High Sierra 10.13.1, i've updated pyserial to 3.4, and running python 2.7.13 under Anaconda.

Is anyone really looking at this issue? Practically I got a £30 blue blinking led powered by my USB port...

@1am
Copy link

1am commented Dec 9, 2017

I'm experiencing the same issue on OSX and Ubuntu. The device worked some time ago when I've tested it on Windows which I no longer have it at hand. Is there a chance for a fix for this?

My execution stack with logging some information looks like this:

python sniffer.py /dev/tty.usbserial-DN00FV4O
Capturing data to logs/capture.pcap
Connecting to sniffer on /dev/tty.usbserial-DN00FV4O
UART open on port /dev/tty.usbserial-DN00FV4O
(<SnifferAPI.UART.Uart instance at 0x103c52248>, '\xab\x06\x00\x01\x00\x00\r\xbc')
(<SnifferAPI.UART.Uart instance at 0x103c52248>, '\xab\x06\x00\x01\x01\x00\r\xbc')
(<SnifferAPI.UART.Uart instance at 0x103c52248>, '\xab\x06\x00\x01\x02\x00\r\xbc')
(<SnifferAPI.UART.Uart instance at 0x103c52248>, '\xab\x06\x00\x01\x03\x00\r\xbc')
(<SnifferAPI.UART.Uart instance at 0x103c52248>, '\xab\x06\x00\x01\x04\x00\r\xbc')
(<SnifferAPI.UART.Uart instance at 0x103c52248>, '\xab\x06\x00\x01\x05\x00\r\xbc')
(<SnifferAPI.UART.Uart instance at 0x103c52248>, '\xab\x06\x00\x01\x06\x00\r\xbc')
(<SnifferAPI.UART.Uart instance at 0x103c52248>, '\xab\x06\x00\x01\x07\x00\r\xbc')
(<SnifferAPI.UART.Uart instance at 0x103c52248>, '\xab\x06\x00\x01\x08\x00\r\xbc')
Scanning for BLE devices (5s) ...
(<SnifferAPI.UART.Uart instance at 0x103c52248>, '\xab\x06\x00\x01\t\x00\x07\xbc')
Traceback (most recent call last):
  File "sniffer.py", line 184, in <module>
    devlist = scanForDevices()
  File "sniffer.py", line 51, in scanForDevices
    mySniffer.scan()
  File "/Volumes/HD2/Users/pb/Documents/dev/hardware/ble/tools/Adafruit_BLESniffer_Python/SnifferAPI/Sniffer.py", line 62, in scan
    self._startScanning()
  File "/Volumes/HD2/Users/pb/Documents/dev/hardware/ble/tools/Adafruit_BLESniffer_Python/SnifferAPI/SnifferCollector.py", line 206, in _startScanning
    self._packetReader.sendScan()
  File "/Volumes/HD2/Users/pb/Documents/dev/hardware/ble/tools/Adafruit_BLESniffer_Python/SnifferAPI/Packet.py", line 187, in sendScan
    self.sendPacket(REQ_SCAN_CONT, [], timeout)
  File "/Volumes/HD2/Users/pb/Documents/dev/hardware/ble/tools/Adafruit_BLESniffer_Python/SnifferAPI/Packet.py", line 184, in sendPacket
    self.uart.writeList(packetString, timeout)
  File "/Volumes/HD2/Users/pb/Documents/dev/hardware/ble/tools/Adafruit_BLESniffer_Python/SnifferAPI/UART.py", line 74, in writeList
    nBytes = self.ser.write(array)
  File "/Library/Python/2.7/site-packages/serial/serialposix.py", line 517, in write
    raise portNotOpenError
serial.serialutil.SerialException: Attempting to use a port that is not open

I've added a print(self.uart, packetString) in line after line 183 in https://github.com/adafruit/Adafruit_BLESniffer_Python/blob/master/SnifferAPI/Packet.py#L182

@hornej
Copy link

hornej commented Apr 25, 2018

Anyone have any luck on this? I am still getting the same error on OSX

@stefandz
Copy link

stefandz commented May 1, 2018

I tried uninstalling the newer driver (twice, as suggested) and then reinstalling. Checking by hand I can see that only the older version of the Silabs kext exists on my system and still I get the same sort of issues that most people are seeing. Until there is a fix, my workaround is to use ble-sniffer-osx by Roland King which will capture into Wireshark 2.0.x (I had to remove my newer version). It's cludgy but it works.

@canDry
Copy link

canDry commented Jun 28, 2018

I was getting USB issues (same SerialException error)... if I run this little bash script it resets the USB and things work again:

#!/bin/bash

if [[ $EUID != 0 ]] ; then
  echo This must be run as root!
  exit 1
fi

for xhci in /sys/bus/pci/drivers/?hci_hcd ; do

  if ! cd $xhci ; then
    echo Weird error. Failed to change directory to $xhci
    exit 1
  fi

  echo Resetting devices from $xhci...

  for i in ????:??:??.? ; do
    echo -n "$i" > unbind
    echo -n "$i" > bind
  done
done

@airdrummingfool
Copy link

I was experiencing this same issue. Doing the following fixed it for me:

  1. Remove the 5.x SiLabs VCP driver (5.0.5 in my case), restart, and install the 4.x driver version instead. The older driver version is included in the 5.x driver disk image under the "Legacy MacVCP Driver" directory. I then used kextstat | grep silabs to make sure that the 4.x driver was installed instead of 5.x.
  2. Apply the fixes from PR Fix failure on macOS #16.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests