Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 3456

Automation, sensing and robotics • Read HID Device Data in rpi

$
0
0
I have a Decibel Meter SLM-25 which has a micro usb interface. Noise Analayser application is available only for Windows OS. I need to connect this device to RPI and record the data. using USB Data logger, i logged the data when connecting the device to windows OS and reading the data as below.
000000: PnP Event: Device Connected (UP), 2024-12-31 11:44:16.3114280 (1. Device: HID To Serial)
The USB device has just been connected to the system.
000001: Class-Specific Request (DOWN), 2024-12-31 11:44:25.8518436 +9.5404126 (1. Device: HID To Serial)
Destination: Interface, Index 0
Reserved Bits: 34
Request: 0xa
Value: 0x0
Send 0x0 bytes to the device
000002: Control Transfer (UP), 2024-12-31 11:44:25.8520326 +0.0001890. (1. Device: HID To Serial) Status: 0x00000000
Pipe Handle: Control Pipe
Setup Packet
21 0A 00 00 00 00 00 00 !.......
Recipient: Interface
Request Type: Class
Direction: Host->Device
Request: 0xa (Unknown)
Value: 0x0
Index: 0x0
Length: 0x0
000005: Class-Specific Request (DOWN), 2024-12-31 11:44:25.8523534 +0.0002562 (1. Device: HID To Serial)
Destination: Interface, Index 0
Reserved Bits: 34
Request: 0x9
Value: 0x200
Send 0x20 bytes to the device

FF C7 83 CC 10 00 00 00 00 00 00 00 00 00 00 00 �ǃ�............
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................


000006: Control Transfer (UP), 2024-12-31 11:44:25.8526668 +0.0003134. (1. Device: HID To Serial) Status: 0x00000000
Pipe Handle: Control Pipe
FF C7 83 CC 10 00 00 00 00 00 00 00 00 00 00 00 �ǃ�............
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................

Setup Packet
21 09 00 02 00 00 20 00 !..... .
Recipient: Interface
Request Type: Class
Direction: Host->Device
Request: 0x9 (Unknown)
Value: 0x200
Index: 0x0
Length: 0x20
000007: Bulk or Interrupt Transfer (DOWN), 2024-12-31 11:44:25.8527318 +0.0000650 (1. Device: HID To Serial)
Pipe Handle: 0xb4e45f38 (Endpoint Address: 0x2)
Send 0x20 bytes to the device
03 A5 00 A5 00 00 00 00 00 00 00 00 00 00 00 00 .�.�............
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................


000009: Bulk or Interrupt Transfer (UP), 2024-12-31 11:44:25.9411224 +0.0871789. (1. Device: HID To Serial) Status: 0x00000000
Pipe Handle: 0xb4e45f08 (Endpoint Address: 0x82)
Get 0x20 bytes from the device
0B 5A 00 54 4C 32 30 32 00 00 00 8E 00 00 00 00 .Z.TL202...�....
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................


000011: Bulk or Interrupt Transfer (DOWN), 2024-12-31 11:44:25.9412456 +0.0000962 (1. Device: HID To Serial)
Pipe Handle: 0xb4e45f38 (Endpoint Address: 0x2)
Send 0x20 bytes to the device
03 A5 01 A6 00 00 00 00 00 00 00 00 00 00 00 00 .�.�............
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................


000013: Bulk or Interrupt Transfer (UP), 2024-12-31 11:44:25.9471215 +0.0050437. (1. Device: HID To Serial) Status: 0x00000000
Pipe Handle: 0xb4e45f08 (Endpoint Address: 0x82)
Get 0x20 bytes from the device
12 5A 01 67 73 D9 19 00 64 03 00 00 01 CF 01 2C .Z.gs�..d....�.,
03 E8 76 00 00 00 00 00 00 00 00 00 00 00 00 00 .�v.............


000015: Bulk or Interrupt Transfer (DOWN), 2024-12-31 11:44:25.9493684 +0.0022191 (1. Device: HID To Serial)
Pipe Handle: 0xb4e45f38 (Endpoint Address: 0x2)
Send 0x20 bytes to the device
04 A5 05 00 AA 00 00 00 00 00 00 00 00 00 00 00 .�..�...........
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................


000017: Bulk or Interrupt Transfer (UP), 2024-12-31 11:44:25.9540649 +0.0039703. (1. Device: HID To Serial) Status: 0x00000000
Pipe Handle: 0xb4e45f08 (Endpoint Address: 0x82)
Get 0x20 bytes from the device
1F 5A 05 00 01 00 00 00 00 00 00 00 00 00 00 00 .Z..............
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 60 ...............`


000019: Bulk or Interrupt Transfer (DOWN), 2024-12-31 11:44:25.9541522 +0.0000672 (1. Device: HID To Serial)
Pipe Handle: 0xb4e45f38 (Endpoint Address: 0x2)
Send 0x20 bytes to the device
04 A5 05 01 AB 00 00 00 00 00 00 00 00 00 00 00 .�..�...........
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................


000021: Bulk or Interrupt Transfer (UP), 2024-12-31 11:44:25.9591292 +0.0040105. (1. Device: HID To Serial) Status: 0x00000000
Pipe Handle: 0xb4e45f08 (Endpoint Address: 0x82)
Get 0x20 bytes from the device
1F 5A 05 01 00 00 00 00 00 00 00 00 00 00 00 00 .Z..............
00 00 00 00 00 00 00 00 00 00 00 00 00 64 05 C9 .............d.�
i Used Python code to read the data

Code:

import hidimport time# Replace these with your device's Vendor ID (VID) and Product ID (PID)VENDOR_ID = 6790PRODUCT_ID = 57360import hidimport time# Replace these with your device's Vendor ID (VID) and Product ID (PID)VENDOR_ID = 0x1234PRODUCT_ID = 0x5678# Open the device with the correct VID and PIDdevice = hid.Device(vid=VENDOR_ID, pid=PRODUCT_ID)# Perform class-specific requests (based on the log)device.write([0x21, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])  # Request 0xAtime.sleep(0.1)device.write([0x21, 0x09, 0x00, 0x02, 0x00, 0x00, 0x20, 0x00])  # Request 0x9time.sleep(0.1)# Set non-blocking modedevice.set_nonblocking(1)# Write some data to the devicedevice.write([0x03, 0xA5, 0x00, 0xA5])# Read response from the devicewhile True:    data = device.read(64)    if data:        print("Received data:", data)    time.sleep(0.1)# Close the devicedevice.close()
but cannot open the device
Traceback (most recent call last):
File "/home/SDM/Desktop/Program_Files/sensorread_v1.py", line 17, in <module>
device = hid.Device(vid=VENDOR_ID, pid=PRODUCT_ID)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/SDM/Desktop/Program_Files/DBMeter_Proj/lib/python3.11/site-packages/hid/__init__.py", line 174, in __init__
raise HIDException('unable to open device')
hid.HIDException: unable to open device

Is there a solution to work around. The device has a DC signal output, i would like to have limited wiring as the USB also supplied power to the device.-

Statistics: Posted by PB_Dusty — Tue Dec 31, 2024 2:54 pm — Replies 0 — Views 16



Viewing all articles
Browse latest Browse all 3456

Trending Articles