USB CDC read using python - python

I have used usb communication in renesas microcontroller, I am able to get USB CDC as com port in my device manager of laptop running on windows 10, I am trying to read and write on this port using pyserial python but I am not able to open port, every time it shows exception that no such device there or permission error. Please provide me the solution.

Related

Bleak can't find Arduino Nano 33 BLE

I want to read gyroscope and acceleration values from an Arduino Nano 33 BLE board by using Bleak on a Windows OS. The code to make the discovery is the default Bleak code (see here). On Arduino I use a code similar to this one, except that I work with the gyroscope and the accelerometer.
Using the Android nRF Connect application I can view the device and the characteristic. Using Bleak instead I can't see any device.
Is it possible to have a problem with permissions on Windows?
I tried to connect it via Bluetooth to the pc first, but Windows 10 says: try to connect your device again. But the Arduino sketch sees the connection attempt as a Central BLE device connecting, in fact he enters the while loop and starts sending data.
How to solve it?

USB Device/PyUSB on Windows and LInux behaving differently

I have a device with USB interface which I can connect to both my Ubuntu 18.04 machine and my Windows 10 machine. On Windows 10 I have to install the CP210x driver and manually attach it to the device (otherwise Windows tries to find the device manufacturer's driver - it's a CP210x serial chip), and in Linux write the vendorID and productID to the cp210x driver to allow it to attach to ttyUSB0. This works fine.
The Windows driver is from SiliconLabs - the manufacturer of the UART-USB chip in the device.
So on Windows it is attached to COM5 and Linux to ttyUSB0 (Ubuntu, Raspbian)
Using Wireshark I can snoop the usb bus successfully on both operating systems.
The USB device sends data regularly over the USB bus and on Windows using Wireshark I can see this communication as "URB_INTERRUPT in" messages with the final few bytes actually containing the data I require.
On Linux it seems that the device connects but using Wireshark this time I can only see URB_BULK packets. Examining the endpoints using pyusb I see that there is no URB_Interrupt endpoint only the URB_Bulk.
Using the pyusb libraries on Linux it appears that the only endpoints available are URB_BULK.
Question mainly is how do I tell Linux to get the device to send via the Interrupt transfer mechanism as Windows seems to do. I don't see a method in pyusb's set_configuration to do this (as no Interrupt transfer endpoints appear) and haven't found anything in the manufacturer's specification.
Failing that, of course, I could snoop the configuration messages on Windows, but there has to be something I'm missing here?
Disregard this, the answer was simple in the end: Windows was reassigning the device address on the bus to a different device.

STM32 - can't open serial port from pyserial, but can from ST-Link

I'm working with STM32 (NUCLEO-L476RG) - uploading code via Workbench, sometimes using ST-Link Utility to connect to it.
Additionally, I've some python code that listens to STM via serial port.
Till yesterday everything was working fine, but today (without changing anything connected to STM, drivers etc.) pyserial can't connect to the device, showing message:
File "C:\python37\lib\site-packages\serial\serialwin32.py", line 62, in open raise SerialException("could not open port {!r}: {!r}".format(self.portstr, ctypes.WinError()))
serial.serialutil.SerialException: could not open port 'COM7': FileNotFoundError(2, 'Nie można odnaleźć określonego pliku.', None, 2)
I can upload code using Workbench or connect to STM via ST-Link Utility without any problems. Port is not used by any other application.
When I list ports by serial.tools.list_ports.comports() it shows properly as STMicroelectronics STLink Virtual COM Port (COM7).
In 'Device Manager' there's a yellow triangle next to the COM, but I'm not sure if it were there earlier (probably yes) - it says that the device driver is not signed.
I tried to:
reinstall the drivers to these provided by STM
reinstall pyserial
use older python
use older pyserial
change COM to another
change cable to new one
connect the device to all possible USB ports
but any of that changed anything.
My setup:
Windows 7
python 3.7.1
pyserial 3.4
STM 32 NUCLEO-L476RG
System Workbench for STM32 & ST-Link Utility, which are working perfectly fine
This setup was working for half a year (!) and I didn't change anything connected to it in the last couple of days. Only thing I did yesterday was installing PostgreSQL, but it seems highly unbelievable that it could cause my current problem...
Thank you in advance for any help - I don't really have an idea what should I try next, so I appreciate any piece of advice.

How to establish serial connection with Bluetooth device on Win7

I am really frustrated and have no idea where to search for an answer.
Currently I am working on a project to detect drowsiness with an ECG device (Zephyr Bioharness 3). The device works but I can't find it with windows (For example like this). I tried several things:
Find the device with my Smartphone -> works
Find the device with an Ubuntu on the same Laptop -> works
Connect directly on Win7 via Bluetooth with this Python Script: Gist -> connects and sends data
Find other Bluetooth devices with my Laptop on Win7 -> Bluetooth radio is dound
COM port for (virtual) serial connection to a bluetooth device (device manager)
What I am trying, is getting this script to work: ZephyrApp. Beside some compatibility problems with QT and serial (which I was able to fix), the programm hangs here protocol.py. I suspect the problems of not finding the device relates to the problems with the program. I know this is very special case, but hope anyone has an idea, how to fix this.
Regards,
paul
EDIT: Another PC with Win7 can't detect the device as well, it seems it is a Windows problem.
The device can't be detected with Win7, but I found a way to connect via bluetooth directly: https://gist.github.com/darkopetrovic/2127217

Connect PySerial to Bluetooth COM port via BlueSoleil on Windows 7

I am trying to communicate with a Bluetooth COM port, via Python on a Windows 7 machine. Since this Computer has no built-in Bluetooth, I use a USB stick which works with BlueSoleil (https://en.wikipedia.org/wiki/BlueSoleil).
My problem seems to be, that BlueSoleil, after a successfull pairing to a COM port, Python cannot open it (access denied). When I define a serial port with PySerial and try to write to it without opening it explicitly, I have no success and a few minutes later the computer crashes with a bluescreen.
When using a terminal (Kitty), I can read and write from and to the port.
My suspicion is, that PySerial tries to 'block' the port, which conflicts with BlueSoleil, but I am not sure.
Any Ideas?
Alright, it seems, that the Problem is bad drivers of the no-name Bluetooth Dongle under Win 7.
I am now using a Raspberry Pi with Raspbian and after installing the needed Packages and loading the needed modules, I have no Problems to connect my Bluetooth device to a serial port.

Categories