| |

VerySource

 Forgot password?
 Register
Search
View: 5206|Reply: 20

HID devices read and write data to the USB port? ?

[Copy link]

1

Threads

7

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-2-22 12:00:02
| Show all posts |Read mode
Does any friend provide a bit of information about the problem of HID-type devices reading and writing data to the USB port?
Reply

Use magic Report

0

Threads

7

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-5-6 02:15:01
| Show all posts
You asked this question in a more general way, first briefly answer as follows:
1.If it refers to hardware (firmware), then it depends on what USB interface chip is used. According to the chip information, the firmware is written to complete the function of sending / receiving data. If the chip is a microcontroller with a USB HID interface, the operation is simpler, as long It is enough to read and write special addresses, the specific operation depends on the hardware information
2.If you refer to PC programming, find the symbolic link name of this device under WINDOWS, open it with CreateFile, and then read and write with ReadFile / WriteFile. SetupApi is used. If you are interested, you can continue the discussion.
Reply

Use magic Report

3

Threads

7

Posts

8.00

Credits

Newbie

Rank: 1

Credits
8.00

 China

Post time: 2020-5-16 19:45:02
| Show all posts
If I know the device path is "\\\\.\\usb # vid_0204&pid_6025 # _ #"
The GUID ID is {36FC9E60-C465-11CF-8056-444553540000}
How does CreatFile specifically use pipeline 0 that can be connected to the device?
Reply

Use magic Report

1

Threads

7

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

 Author| Post time: 2020-7-7 23:00:02
| Show all posts
TO:soilking
My question should belong to the second situation you said. I am now writing a HID class. Through this class, I will communicate between the PC interface and the USB port. I am only responsible for writing data and reading data and identifying hardware interfaces. .I have basically realized the recognition function, I would like to ask how to send data, the data I want to send has up to 8 bytes, what should I do?? Thank you!!
Reply

Use magic Report

0

Threads

7

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-8-9 16:00:03
| Show all posts
Give you a few functions, it should be enough for you, don't dislike it

DeviceHandle=CreateFile (detailData->DevicePath,
GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_READ|FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
0,
NULL);
HidD_GetPreparsedData (DeviceHandle,&PreparsedData);
To
HidP_GetCaps (PreparsedData,&Capabilities);

    ReadHandle=CreateFile
(detailData->DevicePath,
GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_READ|FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,

Result = ReadFile
(ReadHandle,
InputReport,
Capabilities.InputReportByteLength,
&NumberOfBytesRead,
(LPOVERLAPPED)&HIDOverlapped);

Result = WriteFile
(DeviceHandle,
OutputReport,
Capabilities.OutputReportByteLength,
&BytesWritten,
NULL);
FILE_FLAG_OVERLAPPED,
NULL);

To
         CloseHandle(DeviceHandle);

         CloseHandle(ReadHandle);
Reply

Use magic Report

1

Threads

7

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

 Author| Post time: 2020-8-12 09:30:02
| Show all posts
Sorry, I only saw your information now. I have implemented the data sending function. The piece of data reading is still in progress, thank you. I want to ask if the data is read one by one. ? ?
Reply

Use magic Report

0

Threads

9

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-8-14 18:00:01
| Show all posts
Different devices have different readings
Reply

Use magic Report

1

Threads

7

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

 Author| Post time: 2020-8-14 19:00:02
| Show all posts
So if I connect a phone with USB, when should I start reading the data uploaded by the phone, or do I keep reading? ? ? ?
Reply

Use magic Report

0

Threads

9

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-8-14 20:30:01
| Show all posts
It depends on how the device and driver specifically support how to read and write
WriteFile
ReadFIle
DeviceIoControl
Reply

Use magic Report

0

Threads

9

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-8-14 20:45:02
| Show all posts
If you don’t understand the IoControl of the device's related interface and driver
Then you are in trouble

If the driver is written by yourself, it is easy to handle
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list