Pybluez on Nano: SDP can’t be generated - python

I had an issue like this on my Nano:
profiles = [ SERIAL_PORT_PROFILE ],
File "/usr/lib/python2.7/site-packages/bluetooth/bluez.py", line 176, in advertise_service
raise BluetoothError (str (e))
bluetooth.btcommon.BluetoothError: (2, 'No such file or directory')
I tried adding compatibility mode in the bluetooth.service file, reloading daemon, restarting bluetooth and then adding a serial port by doing
sudo sdptool add SP
These steps work fine on my ubuntu 20.04 laptop, but on jetpack 4.5.1, they don’t. And I checked also, they don’t work on jetson NX either.
I am really curious on how to solve this issue, otherwise, another way to use bluetooth inside a python code is welcomed.
Thanks

You might want to have a look at the following article which shows how to do the connection with core Python Socket library
https://blog.kevindoran.co/bluetooth-programming-with-python-3/.
The way BlueZ does this now is with the Profile API.
There is a Python example of using the Profile API at https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/test/test-profile
hciattach, hciconfig, hcitool, hcidump, rfcomm, sdptool, ciptool, and gatttool were deprecated by the BlueZ project in 2017. If you are following a tutorial that uses them, there is a chance that it might be out of date and that Linux systems will choose not to support them.

The solution was in the path of the bluetooth configuration file (inspired from this https://developer.nvidia.com/embedded/learn/tutorials/connecting-bluetooth-audio)
this answer : bluetooth.btcommon.BluetoothError: (2, 'No such file or directory')
is not enough for jetson devices (jetpack). Although I didn't test if it works without changing the file mentioned in this link.
There is a .conf file that needs to be changed also : /lib/systemd/system/bluetooth.service.d/nv-bluetooth-service.conf
modify :
ExecStart=/usr/lib/bluetooth/bluetoothd -d --noplugin=audio,a2dp,avrcp
to :
ExecStart=/usr/lib/bluetooth/bluetoothd -C
after that it is necessary to do:
sudo systemctl daemon-reload
sudo systemctl restart bluetooth
Tested on jetson Nano and NX with jetpach 4.5.1
Thanks for the help !

Related

Failed to register package for vnd.sun.star.expand:$UNO_USER_PACKAGES_CACHE/uno_packages/lu15798vfxfyn.tmp_/apso(3).oxt/python/scripts

Version: 6.0.7.3
Build ID: 1:6.0.7-0ubuntu0.18.04.10
CPU threads: 4; OS: Linux 5.3; UI render: default; VCL: gtk3;
Locale: en-IN (en_IN); Calc: group
i am getting Failed to register package for vnd.sun.star.expand:$UNO_USER_PACKAGES_CACHE/uno_packages/lu15798vfxfyn.tmp_/apso(3).oxt/python/scripts error
download link is https://gitlab.com/jmzambon/apso/raw/v1.2.5/apso.oxt
please help me
Try to rename the file you downloaded "apso(3).oxt" to its correct name "apso.oxt".
That "(3)" was added by your browser when you downloaded the file for the fourth time, but somehow it made LO mad. I had the same problem and I solved it this way, maybe you're lucky too.
The problem occurs for me as well. APSO installs successfully on Windows, but not on Ubuntu. Other python-uno extensions install successfully on Ubuntu, so there may be some problem with APSO. Consider contacting the owner or filing an issue at https://gitlab.com/jmzambon/apso/-/issues.
Keep in mind that, while APSO is convenient, it is not necessary for python macro development. Navigate to user/Scripts/python and create a .py file as explained at Transfer from Basic to Python, or open a python prompt and enter import uno.
The following solved it for me:
sudo apt install libreoffice-script-provider-python
NB May be also restarting LBO and user profile clean up are needed.

DeLorme USB GPS into Raspberry Pi using Python

I have a DeLorme Earthmate LT-40 USB GPS device that I used years ago with a Windows XP program. Out of curiosity I plugged it into my Raspberry Pi to see if I could read the data. I've managed to see data using sudo gpsmon at the command prompt so I would like to take this a step further and write a Python program to read the data. Not knowing very much about Python I've searched YouTube and google for possible solutions. It looks like that I need to import pynmea2. I used pip install pynmea2 to install the module. I keep getting
"ModuleNotFoundError: No module named pynmea2"
when I try to run my script. I tried to reinstall pynmea2 again which gave me
Requirement already satisfied: pynmea2 in ./.local/lib/python2.7/site-packages(1.15.0).
I don't understand what I'm doing wrong. Any help would be greatly appreciated. Thank you.
I have the older version LT-20 of that GPS and usually it presents itself as ttyUSB0 (in my case) when I plug it on Raspberry.
Just do a dmesg command to see in which port it is being recognized, then you can do a cat /dev/ttyUSB0 command and you see all the messages coming from your GPS. The messages start with a $GP for each type of frame. See detailed $GP description at: http://aprs.gids.nl/nmea/ .
Then from your python program, you can open /dev/ttyUSB0 as a file (as read only) and handle each frame and interpetting it according to its format.
Best regards
Flavio

Python pyVISA GPIB connection issue

I'm trying to connect to a GPIB instrument using pyVISA but I get an error. I'm following the simple example on the pyVISA website: http://pyvisa.readthedocs.org/en/master/
I type the following code into the IPython console:
import visa
rm = visa.ResourceManager()
rm.list_resources()
Out[4]:
(u'USB0::0x0957::0x0D0B::MY49431510::INSTR',
u'USB0::0x0957::0x17BC::MY52400338::INSTR',
u'ASRL1::INSTR',
u'ASRL2::INSTR',
u'ASRL5::INSTR',
u'ASRL6::INSTR',
u'ASRL7::INSTR',
u'ASRL8::INSTR',
u'ASRL9::INSTR',
u'ASRL10::INSTR')
However, my GPIB instruments do not show up, just the serial ports and my USB instruments. When I launch the Agilent Connection Expert (or NI MAX) I can see all my GPIB instruments and can communicate with them. I also am able to communicate with the instruments without issue with Matlab.
So when I try and connect to the instrument with the line:
inst = rm.open_resource('GPIB0::19::INSTR')
It throws an error:
VisaIOError: VI_ERROR_INTF_NUM_NCONFIG (-1073807195): The interface type is valid but the specified interface number is not configured.
I've also tried to connect with the USB instruments that show up when I list the resources and they do not throw this error. However, when I try and do a simple query:
inst = rm.open_resource('USB0::0x0957::0x0D0B::MY49431510::INSTR')
inst.query("*IDN?")
Nothing gets returned and no errors get thrown.
I'm using Python(X,Y) 2.7.9.0 with Python version 2.7.9 32 bit
pyVISA version is 1.6.3
NI bitness is 32
Any guidance is appreciated as I'm new to Python.
Thanks
You probably need to start the resource manager with:
rm = ResourceManager('Path to library')
where Path to library is the location of the NI Vista Library.
Also try:
python -m visa info
to ensure that you have it installed with the same word length as the python version that you are running.
I was having the same issue, and did manage to fix it by setting the path address to: 'C:/Program Files/IVI Foundation/VISA/WinNT/agvisa/agbin/visa32.dll'. If you haven't found the solution, I hope it works for you as well.
I had exactly the same problem - USB resources showed up, GPIB resources didn't. I tried to open the resource exactly as you did, inst = rm.open_resource('GPIB0::22::INSTR') (with the GPIB address changed to that of one of my instruments) with exactly the same result. Some inspired random guessing led me to
inst = rm.open_resource('GPIB1::22::INSTR')
which worked perfectly! Once the instrument is open it shows up in the list of resources, as expected. I have no idea why the interface is seen as GPIB1.
I am using the Keysight/Agilent/HP IO libraries suite as my VISA library (the NI library is not installed), and an Agilent 82357B USB to GPIB interface. I did not have to do any customisation of my pyVisa installation to get this working. Which is nice.
Hope this helps!
I had the same problem (running 32-bit python 2.7 on a 64-bit win7), I got it fixed using
rm = ResourceManager('C:/Program Files (x86)/IVI Foundation/VISA/WinNT/agvisa/agbin/visa32.dll')
which is the 32-bit VISA path given in the "About Agilent IO Control" Information.
I have ni-visa and Agilent visa installed on my computer. However, pyvisa cannot access the Agilent 82357B device due to pointing to the wrong library.
I used this command to specify the right library, it worked for me. Couples of notes:
Find the right library for the device which is visa32.dll located in different installation directories depends on each visa packet.
Use forward slash for delimiting characters even it is on windows.
Specify visa packet in the command: rm = visa.ResourceManager('c:/....')
I had the same issue. The problem was that the automatically installed Windows driver was wrong and my device showed up as USB0::0x3923::0x702A::010A65AB::RAW in NI MAX.
It was solved by an update of the driver (device manager-> properties) from C:\Program Files\National Instruments\NI-488.2 (or where your driver is installed).
Now GPIB works also from python.
I observed same error report when running on a PC with visa library from Keysight. Replacing with visa dll from National Instruments solved the problem.

pcapy.findalldevs() No valid interfaces to open

I am trying to run Sulley's (the fuzzer) "network_monitor.py" on an Ubuntu vm. Everytime I do, I get the following error.
pcapy.PcapError: No valid interfaces to open
I believe that this has little to do with the code I am running it in, because when I run
python
>>> import pcapy
>>> devices = pcapy.findalldevs()
I get the same error
Any hints on what's going on would be amazing. Thanks so much in advance
Try to use it with sudo.
Pcapy, AFAIK, needs special rights to access interfaces.
mycode.py:
import pcapy
devices = pcapy.findalldevs()
sudo python mycode.py

Pyusb on windows - no backend available

I'm trying to have my Python application interface with an NFC device via USB.
The best option seems to be PyUSB, but I can't get it to connect to the libusb backend.
I keep getting
ValueError: No backend available
I've looked at the stack trace, and found that usb/backend/libusb10.py (which is part of pyusb) is trying to load libusb-1.0.dll to use as the backend, but it can't find it. It's not that it's not in my path, it's not on my computer at all!
I have installed libusb-win32, but the resulting directory only seems to include libusb0.dll. Where is libusb-1.0.dll???!
I would love to know either where to get that dll, or even a different suggestion to get PyUSB to work on Windows 7.
Download and install libusb-win32-devel-filter-1.2.6.0.exe. It should work.
2021 and the problem still occurs on Windows (Windows 10). I solved it by installing pyusb and libusb and adding libusb path to Windows environment:
pip install pyusb
pip install libusb
libusb-1.0.dll will be automatically added to:
\venv\Lib\site-packages\libusb\_platform\_windows\x64
and
\venv\Lib\site-packages\libusb\_platform\_windows\x32
Now just add those paths (the full path) to Windows Path and restart CMD / PyCharm.
I had a similar issue recently trying to talk to a USB device I am developing. I scoured the web looking for libusb-1.0.dll's and had no luck. I found source code, but nothing built and ready to install. I ended up installing the libusb-win32 binaries, which is the libusb0.dll.
PyUSB will search for libusb-1.0, libusb0, and openUSB backends.
libusb0.dll was already on my system, but something was still not set up right, do PyUSB was not working.
I followed the directions here to download and install the driver using the GUI tools provided to install the filter driver, and the INF wizard. Note, it didn't work until I ran the INF wizard.
I'm pretty new to programming and I've found the lack of clear documentation/examples to string this all together rather frustrating.
I am using Python 2.6.5, libusb-win32-device.bin-0.1.12.1 and pyusb-1.0.0-a0 on a windows XP system and kept receiving ValueError: No backend available.
Since there wasn't any real help on the web for this problem I spent a lot of time finding that ctypes util.py uses the Path variable to find the library file. My path did not include windows\system32 and PYUSB didn't find the library. I updated the path variable and now the USB is working.
There's a simpler solution.
Download and unpack to C:\PATH the libusb-1.0.20 from download link
Then try this line:
backend = usb.backend.libusb1.get_backend(find_library=lambda x: "C:\PATH\libusb-1.0.20\MS32\dll\libusb-1.0.dll")
dev = usb.core.find(backend=backend, find_all=True)
Depending on your system, try either MS64 or MS32 version of the .dll
Update of 17/01/2020, after a request to share more code:
import usb.core
import usb.util
from infi.devicemanager import DeviceManager
dm = DeviceManager()
devices = dm.all_devices
for i in devices:
try:
print ('{} : address: {}, bus: {}, location: {}'.format(i.friendly_name, i.address, i.bus_number, i.location))
except Exception:
pass
import usb.backend.libusb1
backend = usb.backend.libusb1.get_backend(find_library=lambda x: "C:\\libusb-1.0.20\\MS32\\dll\\libusb-1.0.dll")
dev = usb.core.find(backend=backend, find_all=True)
def EnumerateUSB(): #I use a simple function that scans all known USB connections and saves their info in the file
with open("EnumerateUSBLog.txt", "w") as wf:
counter = 0
for d in dev:
try:
wf.write("USB Device number " + str(counter) + ":" + "\n")
wf.write(d._get_full_descriptor_str() + "\n")
wf.write(d.get_active_configuration() + "\n")
wf.write("\n")
counter += 1
except NotImplementedError:
wf.write("Device number " + str(counter) + "is busy." + "\n")
wf.write("\n")
counter += 1
except usb.core.USBError:
wf.write("Device number " + str(counter) + " is either disconnected or not found." + "\n")
wf.write("\n")
counter += 1
wf.close()
I had the same problem with Windows 10, both Python 2.7.16 and Python 3.7.2. I installed libusb (through python -m pip install libusb ) but the error message remained. Also, the advice above about installing libusb-win32 did not work for me; neither of the 2 links (original post and #beebek's answer) existed.
What did work, however, is the comment by #user1495323 : I copied libusb-1.0.dll from
C:\Users\username\AppData\Roaming\Python\Python27\site-packages\libusb\_platform\_windows\x64\
to C:\Windows\System32\
download the latest libusb
Download libusb
Copy MS32\dll\libusb-1.0.dll to C:\Windows\SysWOW64
Copy MS64\dll\libusb-1.0.dll to C:\Windows\System32
3.
pip install libusb
Copy MS32\dll\libusb-1.0.dll to C:\Python\Python37-32\Lib\site-packages\libusb_platform_windows\x86
Copy MS64\dll\libusb-1.0.dll to C:\Python\Python37-32\Lib\site-packages\libusb_platform_windows\x64
This method works for me.
Had some problems with backendnotavailable at 2022 when I install pyusb and libusb on my Windows x64.
I've found a way to solve it reading -> Github solve explaining
To solve, first you need copy path to libusb-1.0.dll (..\envs<your_env_name>\Lib\site-packages\libusb_platform_windows\x64) at system's PATH variable.
Secondly restart IDE.
Third try to get_backend use usb.backend:
import usb.core
from usb.backend import libusb1
# it should find libusb-1.0.dll at our path variable
back = libusb1.get_backend()
print(type(back)) # return: <class 'usb.backend.libusb1._LibUSB'>
dev = usb.core.find(backend=back)
print(type(dev)) # return: <class 'usb.core.Device'>
# flag 'find_all=True' would return generator
# reprecent connected usb devices
dev_list = usb.core.find(find_all=True, backend=back)
print(type(dev_list)) # return: <class 'generator'>
If back is a NoneType, that means get_backend() hasn't found libusb-1.0.dll or found the wrong usblib (and that was my problem - I copied atPATH variable path to _x86 file, on my x64 machine).
Another way to solve it -> copy libusb-1.0.dll from (.._x64\libusb-1.0.dll) to (C:\Windows\System32).
"There are two versions of the libusb API: the current libusb-1.0 API, and its legacy predecessor libusb-0.1." (http://www.libusb.org/) "libusb-win32 is a port of the USB library ​libusb-0.1 to the Microsoft Windows operating systems". "Download the latest release tarball" from the same page (1.0.9 is the current version) to have libusb-1.0 equivalent, you'll find a folder Win32, where you'll find your libusb-1.0.dll to play with! You can even build it: http://www.libusb.org/wiki/windows_backend.
EDIT
You have to build it (download from/ http://sourceforge.net/projects/libusb/files/libusb-1.0/) since the tarball is from 2012, while the latest sources are from 2014-06-15.
To connect to your NFC device via USB using PYUSB, you will need to install the backend for that device. I do not think there is any backend for any device other than a libusb device.
To build a backend. You will need to know the driver (.sys file) for your device, so you could write a wrapper DLL to expose functionalities in the device. Your DLL would have to have a method to find device based on PID & VID, another method to open device and another method to send data and so on...
Just in case:
I haven't tried this on Windows but I had to set DYLD_LIBRARY_PATH path to circumvent this error on the Macintosh.
export DYLD_LIBRARY_PATH=/opt/local/lib
Discussion on whether or not to set this variable is here.
The libusb backend is initialized by the python script in /usb path,by loading the binary DLL from Windows PATH,if it's missed or installed by the zadig's dummy DLL,it will complained about this.Because the DLL installed by zadig doesn't exports any symbol to outside wolrd(dummy one I guess)

Categories

Resources