Basics of development and programming of the simplest USB devices. Android USB Programming

Antipyretic remedies for children are prescribed by a pediatrician. But there are situations of indispensable help in case of likhomantsi, if the child needs to give faces negligently. Then the fathers take on themselves the resuscitation and zastosovuyut antipyretic preparations. What is allowed to give to children of the chest? How can you lower the temperature in older children? What are the most safe faces?

Entry
Who is this book for?
What do you know in the book
software tools
vimogi to hardware security
About software code
Short description of chapters
recognition
Podyaki
Zvorotniy zv'azok
Part I. General information about USB
Chapter 1 USB Specification
1.1. What is USB and what do you need
1.1.1. Global USB architecture
1.1.2. Physical and logical USB architecture
1.1.3. warehouse USB
1.1.4. Power of USB devices
1.1.5. Data transfer principles
1.1.6. interruption mechanism
1.1.7. Data transfer modes
1.1.8. Logical equal exchange of danim
1.1.8.1. Riven of the client's software
1.1.8.2. USB system driver rev.
1.1.8.3. Host controller value for interface
1.1.8.4. Tire value of peripheral USB device
1.1.8.5. Riven logical USB device
1.1.8.6. Functional level of the USB device
1.1.9. Transfer of data for equals
1.1.10. Teepee transmission data
1.1.11. frames
1.1.12. final points
1.1.13. channels
1.1.14. packages
1.1.14.1. Format of marker packets IN, OUT, SETUP and PING
1.1.14.2. SOF packet format
1.1.14.3. Data Packet Format
1.1.14.4. Confirmation Packet Format
1.1.14.5. SPLIT Packet Format
1.1.15. Checksum
1.1.15.1. CRC Calculation Algorithm
1.1.15.2. Software Calculation CRC
1.1.16. transactions
1.1.16.1. types of transactions
1.1.16.2. Transaction confirmation and flow control
1.1.16.3. transaction protocols
1.2. Power up USB devices
1.2.1. configuration package
1.2.2. Standard Power to USB Attachments
1.2.2.1. GET_STATUS
1.2.2.2. Power Reduction CLEAR_FEATURE
1.2.2.3. Dozvіl power SET_FEATURE
1.2.2.4. Address setting on bus SET_ADDRESS
1.2.2.5. Descriptor descriptor GET_DESCRIPTOR
1.2.2.6. Passing a SET_DESCRIPTOR Descriptor
1.2.2.7. Retrieving the GET_CONFIGURATION configuration code
1.2.2.8. Setting the configuration code SET_CONFIGURATION
1.2.2.9. Removing the setup code for the GET_INTERFACE interface
1.2.2.10. Setting the setup code for the SET_INTERFACE interface
1.2.2.11. Setting the number of the synchronization frame SYNC_FRAME
1.2.2.12. Processing of standard requests
1.2.3. annex descriptor
1.2.3.1. annex descriptor
1.2.3.2. Add a clarifying descriptor
1.2.3.3. configuration descriptor
1.2.3.4. interface descriptor
1.2.3.5. End point handle
1.2.3.6. row descriptor
1.2.3.7. specific descriptors
1.2.3.8. Descriptor withdrawal order
1.3. Plug and Play (PnP) system
1.3.1. USB device configuration
1.3.2. Numbering of USB devices
1.3.3. PnP identifiers for USB devices
1.3.4. Symbolic names of attachments
1.4. WDM model
Chapter 2
2.1. Global reviews about language C for microcontrollers
2.2. Library of standard libraries
2.3. Programming for AT89C5131
2.3.1. initialization file
2.3.2. descriptor structures
2.3.3. project structure
Chapter 3. Tools
3.1. programmers
3.1.1. Flip programmer
3.1.2. ER-Tronik programmer
3.2. Driver creation tools
3.2.1. NuMega Driver Studio
3.2.2. Jungo WinDriver
3.2.3. Jungo KernelDriver
3.3. Get Microsoft Visual Studio
3.3.1. Depends (Dependency Walker)
3.3.2. Error Lookup
3.3.3. GuidGen
3.4. Custom Microsoft DDK
3.4.1. device tree
3.4.2. devcon
3.4.2.1. classes key
3.4.2.2. driverfiles key
3.4.2.3. hwids key
3.4.2.4. key rescan
3.4.2.5. key stack
3.4.2.6. status key
3.4.3. Chklnf and Genlnf
3.5. Zasobi CompuWare Corporation
3.5.1. Monitor
3.5.2. SymLink
3.5.3. EzDriverInstaller
3.5.4. WdmSniff
3.6. zasobi Syslnternals
3.6.1. WinObj
3.7. Zasobi USB Forum
3.7.1. HID Descriptor Tool
3.8. USB Command Verifier
3.9. Zasobi HDD Software
3.10. download Sourceforge
3.11. Bus Hound monitoring software
Chapter 4 Win32 Functionality in .NET
4.1. Zagalni vіdomostі
4.2. Importing Win32 Functions
4.3. structures
4.3.1. StructLayout attribute
4.3.2. MarshalAs attribute
4.4. Direct access to data
4.5. Windows update processing
4.6. Headlines about WMI
4.7. Internet resources to tsієї choli
Part II. Classy USB
Chapter 5
5.1. USB / RS-232 conversion methods
5.2. General information about the RS-232 interface
5.2.1. exchange lines
5.2.1.1. Transfer data (BA / TxD / TD)
5.2.1.2. Dani sho accepted (BB / RxD / RD)
5.2.1.3. Transfer request (CA / RTS)
5.2.1.4. Ready to Transfer (CB / CTS)
5.2.1.5. Ready DCE (CC / DSR)
5.2.1.6. DTE ready (CD / DTR)
5.2.1.7. Vikliku indicator (CE / RI)
5.2.1.8. Identification of carriers (CF / DCD)
5.2.1.9. Ready to go (CJ)
5.3. CDC specification
5.3.1. standard descriptors
5.3.2. functional descriptors
5.3.2.1. Header Function Descriptor
5.3.2.2. Command mode handle
5.3.2.3. Abstract Attachment Descriptor
5.3.2.4. grouping descriptor
5.3.3. special requests
5.3.3.1. ask SET_LINE_CODING
5.3.3.2. query GET_LINE_CODING
5.3.3.3. ask SET_CONTROL_LINE_STATE
5.3.3.4. ask SEND_BREAK
5.3.4. notifications
5.3.4.1. Notification RING ^ DETECT
5.3.4.2. SERIAL_STATE notification
5.4. Support CDC in Windows
5.4.1. Overview of Windows Functions for Work with the Last Ports
5.4.1.1. Basic operations with the port
5.4.1.2. Port setting functions
5.4.1.3. Port specific setting
5.4.1.4. I will become a line modem
5.4.1.5. Robot from CDC on the platform. NET
5.4.2. Responsiveness of Windows and USB-powered functions
Chapter 6. HID Class
6.1. Specification for HID add-ons
6.2. How to exchange data with a HID device
6.3. Installing the HID Attachment Driver
6.4. HID device identification
6.4.1. Identification of exciting outbuildings
6.4.2. HID Attachment Configuration Descriptor
6.4.3. HID descriptor
6.4.4. report descriptor
6.5. Report descriptor structure
6.5.1. element report
6.5.1.1. Short Type Elements
6.5.1.2. Elements of the old type
6.5.2. Type element report
6.5.2.1. Basic elements
6.5.2.2. Global elements
6.5.2.3. local elements
6.5.3. apply descriptors
6.6. Wash it down to the НID add-on
6.6.1. request GET_REPORT
6.6.2. ask SET_REPORT
6.6.3. request GET_IDLE
6.6.4. ask SET_IDLE
6.6.5. get GET_PROTOCOL
6.6.6. ask SET_PROTOCOL
6.7. Tools
6.8. Windows HID Device Drivers
Chapter 7. Other USB Classes
Part III. USB Programming Practice
Chapter 8
8.1. General information about АТ89С5131
8.2. Structural diagram of AT89C5131
8.3. USB registers AT89C5131
8.3.1. USBCON register
8.3.2. register USBADDR
8.3.3. register USBINT
8.3.4. register USBIEN
8.3.5. register UEPNUM
8.3.6. register UEPCONX
8.3.7. UEPSTAX register
8.3.8. register UEPRST
8.3.9. register UEPINT
8.3.10. register UEPIEN
8.3.11. register UEPDATX
8.3.12. register UBYCTLX
8.3.13. register UFNUML
8.3.14. register UFNUMH
8.4. circuitry АТ89С5131
8.5. Basic design for AT89C5131
8.5.1. First version of software for AT89C5131
8.5.2. Add row descriptors
8.5.3. Adding end points
8.6. Program Enthusiasm
Chapter 9. Implementation of the CDC class
9.1. Implementation of CDC
9.2. Attachment descriptors
9.2.1. Initialization of terminal points
9.2.2. Processing of CDC requests
9.2.3. RS-port and CDC-line configuration
9.2.4. Reception and transmission of data
9.3. driver installation
9.4. Programming data exchange with CDC-attachment on Delphi mov
9.5. Programming the exchange with CDC-attachment on movі C #
9.5.1. MSCOMM component wiki
9.5.2. Win32 Feature Wiki
9.6. CDC problems
Chapter 10 Implementing the HID Class
10.1. Implementation of HID on АТ89С5131
10.2. Transfer dekilkoh bytes
10.3. Feature report
10.4. Sending data as a host (SET_REPORT)
10.5. HID Attachment Installation
10.6. Data Exchange with HID Attachment
10.6.1. HID add-on name extension
10.6.2. I will add attributes and read reports
10.6.3. Transferring data from a host to a HID device
10.7. Apply HID Attachments
10.7.1. Realization I will add "bear"
10.7.2. Implementation I will add a "keyboard"
10.8. HID Protocol Support
10.8.1. interpretation of data
10.8.2. collections
10.8.3. Arrays and buttons
10.9. HID-attached decalcom report
Chapter 11. Windows Special Features
11.1. Setup API Functions
11.1.1. Refurbishment of USB devices
11.1.2. I will become a USB device
11.2. Repurchase USB devices for WMI help
11.3. Windows XP special features
11.3.1. HidD_GetInputReport - read HID reports
11.3.2. Removal of data from Raw Input
11.4. DirectX features
11.5. Dialog for adding a new property
11.6. Robot with symbolic names of attachments
11.7. Safe flash disk storage
11.8. Demonstration of completion and removal of outbuildings
11.9. Internet resources
Chapter 12 Driver Development
12.1. WDM Driver Basic Procedures
12.1.1. procedure DriverEntry
12.1.2. procedure AddDevice
12.1.3. unload procedure
12.1.4. Driver Work Procedures
12.1.4.1. packet header
12.1.4.2. Intro/Output Stack Centers
12.4.1.3. Driver Work Procedures
12.1.5. IOCTL request service
12.2. Driver acquisition and retrieval to driver procedures
12.2.1. Robotic procedure with driver
12.2.2. Driver Registration
12.2.2.1. Registration for the assistance of an SCM manager
12.2.2.2. Driver parameters in the registry
12.2.3. Return to worker procedures
12.2.4. Save the driver in the middle of the iconized file
12.3. The creation of the driver for the help of Driver Studio
12.3.1. A piece of information about the Driver Studio library
12.3.1.1. KDriver class
12.3.1.2. class KDevice
12.3.1.3. Klrp class
12.3.1.4. class KRegistryKey
12.3.1.5. class KLowerDevice
12.3.1.6. Classy USB
12.3.2. Other classes Driver Studio
12.3.3. Creating a driver template for help Driver Studio
12.3.3.1. Krok 1. Head of the name of the project
12.3.3.2. Krok 2. Selection of driver architecture
12.3.3.3. Krok 3. Selection of tires
12.3.3.4. Krok 4. Setting a set of endpoints
12.3.3.5. Croc 5. Specifying the class name and file
12.3.3.6. Krok 6. Selection of driver functions
12.3.3.7. Krok 7. Select the method of processing requests
12.3.3.8. Krok 8. Creation saves driver parameters
12.3.3.9. Krok 9. The power of the driver
12.3.3.10. Krok 10. Setting IOCTL codes
12.3.3.11. Krok 11. Additional settings
12.3.4. Extending the driver template
12.3.5. Basic methods and class I will add
12.3.6. Implementation of data reading
12.3.7. driver installation
12.3.8. data reader program
12.3.9. Reading data from endpoints of other types
12.3.10. "Clean" USB plug-in driver
Part IV. dovidnik
Chapter 13. INF File Format
13.1. Structure of an INF file
13.1.1. Version section
13.1.2. Manufacturer section
13.1.3. DestinationDirs section
13.1.3.1. Key DefaultDescDir
13.1.3.2. File-list-section keys
13.1.3.3. dirid key
13.1.3.4. subdir key
13.1.4. Section description of the model
13.1.5. Section xxx. AddRegw xxx. DelReg
13.1.6. Section xxx. logconfig
13.1.7. Section xxx. CopyFiles
13.1.8. Strings section
13.1.9. section links
13.2. Creation and testing of INF files
13.3. Installing add-ons behind the help of the INF file
13.4. Registry plugs for USB
Chapter 14. Basic Windows Features
14.1. CreateFile and CloseHandle functions: open and close an object
14.1.1. dodatkovі vіdomosti
14.1.2. meaning, what to turn
14.1.3. butt viklik
14.2. ReadFile function: reading data
14.2.1. dodatkovі vіdomosti
14.2.2. meaning, what to turn
14.2.3. butt viklik
14.3. Write File Function: Data Transfer
14.3.1. dodatkovі vіdomosti
14.3.2. meaning, what to turn
14.3.3. butt viklik
14.4. The ReadFileEx function. ARS reading data
14.4.1. meaning, what to turn
14.4.2. dodatkovі vіdomosti
14.4.3. butt viklik
14.5. WriteFiieEx Function: APC Data Transfer
14.5.1. meaning, what to turn
14.5.2. butt viklik
14.6. Function WaitForSingieObject
14.6.1. meaning, what to turn
14.7. WaitForMultipleObjects function: clearing signal objects
14.7.1. meaning, what to turn
14.8. GetOverlapped Result function: the result of an asynchronous operation
14.8.1. meaning, what to turn
14.9. DeviceloControl function: direct driver control
14.9.1. meaning, what to turn
14.10. Function Cancel / o: canceling an operation
14.10.1. meaning, what to turn
14.11. Query Dos Device function
14.11.1. meaning, what to turn
14.11.2. butt viklik
14.12. Define Dos Device function: add DOS operations
14.12.1. meaning, what to turn
14.12.2. butt viklik
Chapter 15
15.1. Structure to configure the COMMCONFIG port
15.2. Authority structure of the COMMPROP port
15.3. Timeout structure COMMTIMEOUTS
15.4. COMSTAT port status structure
15.5. DCB structure
15.6. BuildCommDCB Function: Building a Charging DCB Structure
15.6.1. dodatkovі vіdomosti
15.6.2. meaning, what to turn
15.6.3. butt viklik
15.7. BuildCommDCBAndTimeouts Function: Building a DCB Structure and Charging Timeouts
15.8. Functions SetCommBreak and ClearCommBreak: data control
15.8.1. meaning, what to turn
15.9. Function ClearCommError: canceling and discarding port pardons
15.9.1. meaning, what to turn
15.10. EscapeCommFunction: port control
15.10.1. meaning, what to turn
15.11. Functions GetCommMask and SetCommMask: Weekly mask
15.11.1. meaning, what to turn
15.12. WaitCommEvent function Checking out the COM port
15.12.1. meaning, what to turn
15.12.2. dodatkovі vіdomosti
15.12.3. butt viklik
15.13. Functions GetCommConfig and SetCommConfig: configuration parameters in the port
15.13.1. meaning, what to turn
15.13.2. butt viklik
15.14. CommConfigDialog Function: Port Configuration Dialog
15.14.1. meaning, what to turn
15.14.2. dodatkovі vіdomosti
15.14.3. butt viklik
15.15. GetCommProperties Function: Read Port Authority
15.15.1. meaning, what to turn
15.15.2. butt viklik
15.16. Functions GetCommState and SetCommState: port port
15.16.1. meaning, what to turn
15.16.2. butt viklik
15.17. Functions GetCommTimeouts and SetComniTimeouts: port timeout
15.17.1. meaning, what to turn
15.17.2. butt viklik
15.18. PurgeComm function: dropping the buffer in the port
15.18.1. meaning, what to turn
15.18.2. butt viklik
15.19. SetupComm function: buffer expansion configuration
15.19.1. meaning, what to turn
15.20. Functions GetDefaultCommConfig and SetDefaitltCommConfig: lockout port settings
15.20.1. meaning, what to turn
15.21. Function TransmitCommChar. transmission of special characters
15.21.1. meaning, what to turn
15.22. Function GetCommModemStatus: modem status
15.22.1. meaning, what to turn
15.22.2. butt viklik
15.23. EnumPorts function: port remapping
15.23.1. dodatkovі vіdomosti
15.23.2. meaning, what to turn
15.23.3. butt viklik
Chapter 16. Windows Setup API Structures and Functions
16.1. Setup DiGetCiassDevs function: resetting attachments
16.1.1. meaning, what to turn
16.2. SetupDiDestroyDevicelnfoList function
16.2.1. meaning, what to turn
16.3. SetupDiEnumDevicenterfaces function: device information
16.3.1. meaning, what to turn
16.4. Function SetupDiGetDevicelnterfaceDetaii: detailed information about attachments
16.5. SetupDiEnumDevicelInfo function: device information
16.6. SetupDiGetDeviceRegistryProperty Function: Add Plug and Play Authority
16.7. Function CM_Get_DevNode_Status: add status
16.8. Function CM_Request_Device_Eject
Chapter 17. Windows HID API Structures and Functions
17.1. Function HidD_Hello: refactoring the library
17.2. HidD_JetHidGuid Function: Retrieving a GUID
17.3. Function HidD_GetPreparsedData: creating a device descriptor
17.4. Function HidD_EreePreparsedData: An extension of the device descriptor
17.5. HidD_Get Feature Function: Retrieving a Feature Report
17.6. Function HidD_SetFeature: Passing Feature-Report
17.7. Function HidD_GetNumlnputBuffers: Retrieving the number of buffers
17.8. Function HidD_SetNumlnputBuffers: setting the number of buffers
17.9. HidD_GetAttributes Function: Retrieving Attached Attributes
17.10. Function HidD_GetManufacturerString. trimming row of picker
17.11. Function HidD_GetProductString to remove a product row
17.12. Function HidD_GetSerialNumberString. alteration of the serial number row
17.13. Function HidD_GetIndexedString. removing row after index
17.14. Function HidD_Jetlnput Report
17.15. Function HidD_SetOutputReport. transfer Output-report
17.16. HidP_GetCaps Function: Add Power Cap
17.17. HidP_MaxDataListLength function: deselecting reports
17.18. Function HidD_FIushQueue: drop buffers
17.19. HidP_GetLinkColiectionNodes function: collection tree
17.20. Functions HidP_GetScaledUsageValue and HidP_SetScaledUsage Value: Retrieving and setting conversion values
17.21. Function HidF_MaxUsageListLength: Buffer expansion for key codes
17.22. Function HidP_UsageListDifference: visibility between arrays
appendages
Addendum 1. Additive functions
Addendum 2. Compilation of applications in other versions of Delphi
Addendum 3. Table of mov identifiers (LangID)
Addendum 4. Table of codes of vendors (Vendor ID, Device ID)
Addendum 5. How to create a Device Manager shortcut
Addendum 6. Food parts
Addendum 7. Description of the CD
literature
indicator

And yet, it’s not enough just physically to get to the computer, it’s necessary to make the exchange of data between them. How to choose a port and organize a connection? Kіlka rokіv to that standard solutions bulo vikoristannya COM-port. To the speech, before tsikh pіr raznі fahivtsі to install on the industrial computer 8, 16, and even і 32 COM-ports (є tsіla category of different PCI-cards of expansion of the last ports, controllers, etc.). In such a way, as it is necessary to connect a dekil of zvnіshnіh pristroїv with RS-232 interface, you may need expensive adapters and exotic expansion payments, as if following the old tradition of sailing to Russia on steamboats. By the way, naming the typical adapter "DB9m / DB25f adapter" from the manager of the computer store can ask you if it's a problem.

What are HID attachments

At the same time, practically all attachments are connected to the computer via a USB interface. That's why in a bagatioh new PC COM-port vіdsutnіy vzagalі.

USB-interface - a typical solution for obtaining a new building with a computer, more precisely, a HID-interface, which is based on the USB 1.1 protocol.

If you want to know if the HID-interface (Human Interface Device) is used exclusively for the keyboard, mouse and joystick, it can be used for impersonal solutions related to other devices and computers.

It is necessary to viroblyat low-speed data exchange (up to 64 kb/s) and while it is necessary to spend an hour on a stably rozrobtsі vladnyh drivіrіv, then you need to use HID as a whole. At the exit, we will be simple and whole today's solution on the basis of a standard software USB-interface with a guaranteed support on all wider software platforms.

Power HID add-ons

From the point of view of the organization of the software support of the HID-attachment, everything looks pleasant: for Windows robots, it is possible to quickly create intelligible compact code based on ready-made altered algorithms. If the retailer has to spend a lot of time on the implementation of the high-level protocol for the exchange of data from the upper level, the shards of the necessary level of abstraction are already organized for the HID-protocol (div. Table). In addition, it is easy for the programmer to update the written exchange protocol (expectedly, with the presence of a working HID-attachment) - the problems of the protocol itself are easy to complete, just expand the support program by attaching it to the computer. Wow! Masa roboti has already taken over the creator of the HID add-on.

Organization of data exchange between HID device and computer

To describe the interaction between a HID device and a computer, let's use the term "host". In this way, under it, there is a clear understanding of the key attachment to the global physical architecture in conjunction with the USB protocol. So, all ports in the computer are hosts. Before them, you can connect various USB attachments (flash drives, mouses, webcams, cameras, etc.), as the host cannot be. The host takes care of the display, connection, inclusion, configuration of the outbuildings, as well as the selection of statistics and energy management.

HID attachments can set the sampling frequency yourself, at any time it will be revealed in some new data. So, on such a low level, the programmer can trust the system, but the frequency of testing and other parameters of the exchange of data is due to the task in the program of the HID controller. The CIM HID protocol is considered to be a common description of USB 1.1 or USB 2.0, in which there are few hardships to organize the protocol. However, with specific tasks that require increased security, you may be able to complete the tasks of cyclical experiments, if only one and the same blocks of data are constantly transmitted.

Features of programming HID devices

HID attachments may have special descriptors. If the host is set to qualify for the HID class, then the host passes control to the appropriate driver. It is said that the further exchange of money is carried out under yoga.

On Windows, for access to the HID add-on, the HidServ system service is denied. More details about the functions of powering up to the HID-attachment and other features of the work with the HID-driver are revealed in the work of P. V. Agurova “USB interface. The practice of vikoristannya and programming "(St. Petersburg: BHV-Petersburg, 2005).

Programming HID-attachments on the "upper level"

The life of "applied" programmers is not easy, as they work on Pascal, which makes it easier to convert the HID module. PAS, a hid wrapper. dll (Hid User Library - as assigned by the authority of the file). The comments before the file tell you that it is based on the hidsdi.h and hidpi.h modules of the Microsoft Corporation. And the HID file itself. PAS is part of the JEDI() package.

For work with HID devices in the Delphi for win32 environment, the TJvHidDeviceController component is installed, which is a manual global manager for accessing HID devices. And even on the yoga base, you can select an object instance for robots with a specific attachment.

Main powers and subs of the TJvHidDeviceController component

Let's take a closer look at the TJvHidDeviceController component. Podіya OnArrival spratsovuє on nadhodzhennya (connection) in the HID-attachment system, access to the attachment is possible in the opiónnik dієї podії through an instance of the class TJvHidDevice. Simply put OnDeviceChange I will react to the change, I will add it, it only signals about changes in the system. Podіya OnDeviceData spratsovu if necessary data from one of the HID-appliances and transfers the control to the foot: HidDev: TJvHidDevice; - ustrіy-stvo, vіd kogo buli otrimani dіnі;

The OnDeviceDataError subdial notifies about the pardon of the data transfer, passing the HidDev parameters to the processing procedure: TJvHidDevice; - HID attachment and Error: DWORD; - pardon code. Podіya OnDeviceUnplug podіdlyaє about vidalannya I'll add zі to the list of installed in the system. Types of probes for Plug and Unplug however (in the postscript: TJvHidUnplugEvent = TJvHidPlugEvent). An object of the TJvHidDevice class, which is suitable for the HID device, is passed to the builder.

For subsequent reprocessing of HID attachments found in the system after a week, the Enumerate method is assigned the OnEnumerate subkey, i.e., in the description of the found attachments, they are sequentially transferred to the lookup objects. This approach is initiated by the Enumerate method, which is used to "carry out" the latest HID devices through a sampler, for example, when auditing a HID device from the initiative of the host (computer).

Podіya OnRemoval spratsovuє on fіzіchne vіchne vyluchennya I'll add from the system and can the same type of TJvHidUnplugEvent handler as for OnDeviceUnplug. The CountByProductName function is in the form of the number of attachments, which means that it matches the product specified in the name argument, and the CountByVendorName function - to the one specified in the vendor name argument.

Main power and subclass TJvHidDevice

The TJvHidDevice class is a virtual manifestation of a specific HID device. A new object of this class can be taken, as already mentioned, under OnArrival or OnEnumerate. The functionality of the TJvHidDeviceController and TJvHidDevice classes is often duplicated, but in the first of them the main tools are integrated for work with a set of HID-additions in the system and a mechanism for accessing up to one of them. Attachments can be uniquely identified by the authority of SerialNumber, ProductName and VendorName. To get information about the need for data from such an object, you can check it under OnData. Data entry is carried out through the WriteFile method (in a strict sense - through a function). WriteFile is a wrapper around the system function WriteFile (kernel32).

In order to check the fact of the error, I will add it, add your own workbook under OnUnplug. Before you start exchanging data with HID attachments, you need to be aware of the possibility of such an exchange for the help of HasReadWriteAccess. In this class, for the sake of pardoning the exchange of data, navit є okrema Podiya OnDataError.

And now let's take a look at code fragments from a "live" project that implements a test client program for organizing data exchange with a non-standard add-on - plastic chip cards based on HID. In the fight for realism, the author, having taken on the courage not to look for listings, "zayv" technological binding to the code.

The ScanDevices method (Listing 1) of assignments for initiating a scan process on the system of the required HID device. There is a large part of the code, for a wink to the Enumerate method, neobov'yazkova and secure flexibility of add-ons, for example, in order to add the possibility of robots to the test program via the interface, the HID command line. The AddError method is shown in the window of the alarm in the process of the robot program.

Listing 2 has an OnEnumerate checklist for the search for a required caller. For simplicity, we will take into account that the program can only be used with one outbuilding of the required type.

Let’s take a closer look at the implementation of the project, trace a few words about the accepted form of exchange of data from the upper level, i.e. About the structure called by the intermediary between the methods of receiving and transmitting data and specific roses of applied orders. On the right, in the fact that here the retailer hopes to be able to realize his creative talents. Vernishe, retailers, to that the process of creating a new protocol is often two-sided, and at the same time I play the violin with the one who is more important to implement the exchange algorithm. Zagalom, as if I didn’t use the protocol for the exchange, start the reception of the skin program day as much as possible scientific and self-sufficient, let them inspire badly accepted traditions. bo best solution- something that will be implemented in the style of the term with a minimum binding to the program medium and with great possibilities for a distant development. On the basis of these principles of creations, the protocol for the exchange of the upper level, which is more understandable - “command”. Listing 3 shows how much the author loves string data; software modules. It's amazing what we have got into the String type! All protocol commands are divided into categories (classes), in the middle of which there is a command code that uniquely characterizes their recognition. The edParam parameter is used to add data to attachments, and the edAnswerData parameter is used to remove data in the appendix. The string type of the description of the members of the record allows you to freely and intentionally manipulate data in the HEX-row format. І what is the best, the format of the described record is ideologically placed here in the middle between її without middle recognition and various formsїї submission (INI, HEX, XML, etc.)

The command wiping, i.e., data entry into attachments, was implemented with the help of 8 bytes data packet entry (Listing 4). Tsya dozhina is not the only solution, such a choice of dictations for the protocol of the upper level and in a specific skin type can be different. Tse, which is called, on the right relish. The strange flag IsUSBMode in the ExecuteCommand method (Listing 5 on the “World of the PC-disk”) is redundant as a guess about those who can replace USB robots, we may need to select a COM port or another interface. On the cob, a group of data is transferred to the attachment, a synchro-series of a fairly selected format (for example, 3E3E3E2B) is transmitted, which supports the power, which has a whole legal data at the entrance. I’m guessing that in this case, the language is not about HID, but about the specific protocol of the upper level, ideologically broken in the form of “hall” and recognized for the accomplishment of special applied tasks.

In the GetDataExecutor data collector, I will add data (package of 8 bytes), the OnNewInputData sub-pod has been specially created to transfer the primary data data to a further processing, moreover, from the old and new values ​​(Listing 6 on the “PC-disk world”). In this manner, the submission of unprocessed data and the introduction to further processing are untied, allowing you to add a specific algorithm for advancement at an early stage of pardon, repeated or non-necessary input information.

Presented here are examples of robots with HID devices illustrating the main idea of ​​the article - one can see the simplicity of programming non-standard HID devices using Delphi tools.


Fig.1 Illustration of the Android robot I will add in USB Host and Accessory modes (little one from the site http://developer.android.com)

It is significant that using USB is not the only way to communicate with the same self-contained attachment. Android allows Wi-Fi, NFC, Wi-Fi P2P, SIP, as well as a standard connection to a network. So, in the arsenal of the retailer, there are enough opportunities for creating your most ambitious ideas.

The second broadest option is to connect with various attachments to the dos and є using a USB-COM adapter. The material in the merezhі on the installation of the USB-COM adapter in Android є - div., For example,. The popularity of such a connection is driven by reality great number earlier razroblennym s different microcontrollers attachments, zv'yazyk z zdіysnyuєtsya for help COM-port (serial port), scho 10 years ago there was a standard way to transfer data from the computer to a self-contained "zalіznitse".

In connection with the COM-port, the USB switch allows you to accurately increase the speed of data transfer and the stability of the process, which is easy for a koristuvach. Shvidkіst peredachі, yak navіt in razі nizkoshvidkіsnih pristroїv (klavіaturi, mishі, joysticks), becoming 10-1500 Kbіt / c, i simplicity nevisoka vartіst kabelnoї i sistemi pіdklyuchen, samoіdentifіkatsіya pristroїv of automaticity konfіguratsієyu, prihovuvannya podrobits elektrichnogo broadband Internet od kіntsevogo koristuvacha (plus mozhlivіst connection to the cable without disconnection of attachments), pardon control and its implementation on a par with the protocol is the axis of non-transverse progress of this technology (div., p.12).

When talking about the use of USB for data transmission, it will be indeterminate to guess the book by P. Agurov "USB interface". Vaughn, although often criticized in the measure and released the last time in 2006, helped more than once to know the correct solution when looking for information from various aspects of the impact of technology. The book looks at the nutrition: from the choice of microcircuit and circuitry for the controller to the writing of microcontroller programs and applications for programming data transfer via the USB protocol from the side of the computer. It is impossible not to say that this data was "performed" - the site of the non-commercial organization USB IF (USB Implementers Forum), which deals with the development of the specification of this interface -, The truth is given by the material of the English mine. However, there you will also find information about attachments to the USB interface. Є indecent translation of parts of the specification -. Tim, who to squeal software solutions From the side of the microcontroller, you can also look at strength.

This article is addressed first of all to those who have electronic attachments (split independently or even more), a protocol for exchanging data with some kind of good information (for example, it’s already a program that works with sim attachments in Windows / Linux) and wanted use the program that works with it in Android.

Trochy about classy USB devices

It is necessary to indicate that the development of software for the exchange of data with a specific device is heavily dependent on the implementation of the microcontroller. It is not possible to provide application programs for all types of USB devices within the framework of one article, for reasonable reasons (early information about programming of various types of devices can be found in). However, we agree that we will induce a code that I will implement a search for and add access to some control points for exchanging information. We will also analyze data editing on the butt of one of the types of USB attachments, and itself, the HID class of attachments (human interface device - a class of attachments for interfacing with people). This class includes “more” attachments, such as a keyboard, a mouse, a joystick and applications for yoga implementation for additional microcontrollers in the measure (є, for example, and in).

Why is the HID class itself so fond of the builders of various self-contained outbuildings? To quote Wikipedia: “Crimea of ​​detailed specifications for classic outbuildings (keyboards and bears) the HID standard defines special class outbuildings without detailed specifications. This class is called USB HID Consumer Control and is, in essence, a non-regulatory communication channel with an extension. In case of any attachment, it is necessary to use the same standard drivers for the operating system and the bear with the keyboard. In this way, it is possible to create a USB attachment that does not require the creation and installation of special drivers in most advanced computer operating systems. It remains to be added only that the specification works in the Android OS (not including CyanogenMod firmware).

One of the options for exchanging data with a HID attachment is interrupt transfer, which is viable in that case, if it is necessary to transfer data packets of a small size (the maximum size of the packet is to be stored in the transmission speed and set to 64 to 1024 bytes) via clock tasks interval The packet for transmission is called a report (English - report, see p.71, 95). Such a report should be called as a whole for the exchange of information with a self-contained attachment, 64 bytes of information in one package, for example, - it is necessary to send a lot for the controller, even for the transmission of light stations, or the simplest sensor to send 1 bit of information.

necessary tools

So, we need to know - a tablet or a phone with Android version no lower than 3.1. Here it is necessary to indicate that the USB Host API will not be implemented on all mobile devices (it is also possible to find out on the website developer.android.com, div. Power). Some tablets/phones with USB plugs have only a socket for charging and connecting with a personal computer. Once again, I will correct the reader to the list of mobile attachments, adjuncts or non-applications for our doslidiv (div.).

You will also need a USB-attachment (for the first few, a standard USB-flash drive will suffice), an OTG adapter (On-The-Go - see Fig. 2) and/or a USB cable for communication with the attachment. Wikipedia says about the OTG drive: “When connected via USB OTG, the rank of the add-on (head or sub-orders) is displayed either directly or if there is a jumper between pins 4 and 5 in the charging cable. For USB OTG cables, such a jumper is installed only in one of the two sockets (div.). » Clearly, we need such a jumper on the side of the mobile building.


Fig. 2 Specifications in the scheme of the standard USB cable and OTG cable (figure from the site http://tech.firstpost.com)

Such an OTG cable for your add-on can be soldered and independently. For this, it is necessary to buy in the radio store a new rose, plus the author, for example, recapturing an old cable from a portable hard drive:

I will be a bad help in a robot USB program Device Info, installed from the Google Play Market. The program can be used to connect to the USB port of the tablet / phone, I will attach it for help Java API and for help Linux kernels. So, if your attachment is not supported by the Java USB Host API in USB Device Info, then, with great humility, you will be able to win for any mobile application, be it (including your own) Android program, written with the help of Java and USB host API.

In other words, it is also the same information that is displayed by the lsusb operating command Linux systems. With the -v and -d lsusb keys, show everything about the USB-attachment, or else everything that is necessary for the software distributor for the attachment of this class (div. Fig. 3).


Fig.3 Example of viewing lsusb and lsusb -v -d commands

Dali, required computer install android SDK and integration environment (IDE) Eclipse with ADT plug-in (you can also use SDK if you want). How to create and install an add-on for Android, you can look, for example, in, or in the Internet.

Well, and, obviously, it is necessary to want to be able to achieve the result, without a new one! I will appoint, that on z'yasuvannya deyakyh tekhnіchnyh zastosuvannya USB in Android by the author, will need tizhnі kopitkoї pokuku іnformatsiї.

Use Java for robots from USB in Android API

Also, as it seems on the site of the USB Host API retailers for Android (div.) - “first lower, it’s important to understand what class you will win in the robot”. Table 1 has a description of the most important classes for robots from the USB Host API (try to translate the information from http://developer.android.com).

Table 1. Description of classes for USB robots in Android

Naming the class description
UsbManager Allows you to enumerate and communicate with connected USB devices.
Allows you to designate USB-attachment connections and exchange data with it.
UsbDevice Represents a connected USB device and contains methods to access its identifying information, interfaces, and endpoints.
It is a USB connection and a method for accessing various identification information, interfaces, and endpoints.
usbinterface Represents an interface of a USB device, which defines a set of functionality for the device. A device can have one or more interfaces on which to communicate on.
Introducing the “interface” of the USB attachment, which defines the set of functions for this attachment. One attachment may be one or more interfaces for the exchange of information.
UsbEndpoint Represents an interface endpoint, which is a communication channel for this interface. An interface can have one or more endpoints, and usually has input and output endpoints for two-way communication with the device.
Representing the "endpoint" of the interface, as a channel for communication for this interface. The interface can have one and more endpoints, and ring up as many endpoints to remove information for the transmission.
UsbDeviceConnection Represents a connection to the device, which transfers data on endpoints. This class allows you to send data back and forth sychronously or asynchronously.
Representing the "connection" to this extension. Necessary for transferring data to the terminal point. This class allows you to receive data or transmit synchronously or asynchronously.
UsbRequest Represents an asynchronous request to communicate with a device through a UsbDeviceConnection.
It is an asynchronous request for data exchange with the device via UsbDeviceConnection.
UsbConstants Defines USB constants that correspond to definitions in linux / usb / ch9.h of the Linux kernel ..
Assigns constants to be used in linux / usb / ch9.h of the Linux kernel.

The most important thing is that the USB Host API has a high-class programmer in his robot. The algorithm of їх zastosuvannya looks approximately like this: you can change the add-on (meta - software access to the UsbDevice class), connect to the host (mobile add-on), for the help of UsbManager. If the software access is disabled, it is necessary to assign the UsbInterface and UsbEndpoint permissions to link with it. Just as you have taken the end point in your order, open the UsbDeviceConnection to communicate with the USB device. As the end point works in asynchronous transfer mode, the UsbRequest class wins.

Let's try to do this together by creating a simple add-on, like a vicorous API, to assign connections to a host with Android OS, and display information about the new day on the screen of a phone or a tablet.

we create a project

In Eclipse, the project is created by the additional menu item File-> New-> Android Application Project. It is also worth noting that the code, pointing below the positions of add-ons that are supplied with the Android SDK (folder android sdk samples / android-N (API Level) / USB) is a guide for the program to control the USB-toy Missile Launcher (div. Fig. 4 ) Apply addenda zavantazhuyutsya through the Android SDK Manager (it is necessary to check the box next to the item - Samples for SDK). In the listings hovering below, apply the code with comments to explain the essence of what is happening.


Fig.4 Funny toy "Rocket launcher"

When creating a project, do not forget to set the required API Level in the Minimum Requared SDK option (API Level 12, optional). android versions 3.1 / Honeycomb /, or more). The project will have a simpler interface of the koristuvach - the main window (Activity) and TextView for displaying information. A similar project is reviewed in detail in.

For the automatically created class for the Activity of our project, it is necessary to assign the next instance of the class for robots from USB:

private TextView lgView;
private UsbManager mUsbManager;
private UsbDevice mDevice;
private UsbDeviceConnection mConnection;
private UsbEndpoint mEndpointIntr;

LGView = (TextView) findViewById(R.id .logTextView);

and access to the UsbManager class is required

MUsbManager = (UsbManager) getSystemService(Context .USB_SERVICE);

Let's create a sample subdivision onResume (). Let's do it - sob information about the connected outbuildings was updated during the activation of our congestion (div. Listing 1).

Listing 1. Checkbox onResume()

public void onResume()(
super.onResume();

// populate the container with a list of attachments
hashmap< String , UsbDevice>deviceList = mUsbManager.getDeviceList();
Iterator< UsbDevice>deviceIterator = deviceList.values() .iterator();

lgView.setText("Devices Count:" + deviceList.size());

while (deviceIterator.hasNext()) (
UsbDevice device = (UsbDevice) deviceIterator.next();

// attachment assigned ProductID attachment
\n"+ "Device ProductID:" + device.getProductId());
}
// we assign the name, described in the filter
// name_in AndroidManifest.xml
intent intent = getIntent();
lgView.setText(lgView.getText() + " \n"+ "Intent:" + intent);
String action = intent.getAction();

// as an attachment is connected, we send it to
// to the setDevice() function
UsbDevice device = (UsbDevice) intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
if (UsbManager.ACTION_USB_DEVICE_ATTACHED .equals(action))(
setDevice(device);
lgView.setText(lgView.getText() + " \n" + "UsbManager.ACTION_USB_DEVICE_ATTACHED.equals(action) is TRUE") ;
) Else if (UsbManager.ACTION_USB_DEVICE_DETACHED .equals(action)) (
if (mDevice != null && mDevice.equals(device))(
setDevice(null);
lgView.setText(lgView.getText() + " \n" + "UsbManager.ACTION_USB_DEVICE_DETACHED.equals(action) is TRUE") ;
}
}

Next, for the Activity, we create the setDevice () function, which is necessary for working with our add-on (div. Listing 2). In the onResume () routine and in the setDevice () function, we have exactly implemented the USB Host API logging algorithm, descriptions in the front section.

Listing 2. setDevice() function

private void setDevice (UsbDevice device) (
lgView.setText(lgView.getText() + " \n"+ "SetDevice" + device);

// we can see the available interfaces of the add-on
if(device.getInterfaceCount() != 1)(

lgView.setText(lgView.getText() + " \n"+ "Could not find interface");
return;
}
UsbInterface intf = device.getInterface(0);

// I'll add the end points
if (intf.getEndpointCount() == 0) (

lgView.setText(lgView.getText() + " \n"+ "Could not find endpoint");
return;
) Else (
lgView.setText(lgView.getText() + " \n"+ "Endpoints Count:" + intf.getEndpointCount ());
}

UsbEndpoint epIN = null;
UsbEndpoint epOUT = null;

// look for endpoints for transfers over relays
for (int i = 0; i< intf.getEndpointCount () ; i++ ) {
if (intf.getEndpoint(i).getType() == UsbConstants.USB_ENDPOINT_XFER_INT)(
if (intf.getEndpoint(i).getDirection() == UsbConstants.USB_DIR_IN)(
epIN = intf.getEndpoint(i);
lgView.setText(lgView.getText() + " \n"+ "IN endpoint:" + intf.getEndpoint(i));
}
else(
epOUT = intf.getEndpoint(i);
lgView.setText(lgView.getText() + " \n"+ "OUT endpoint:" + intf.getEndpoint(i));
}
) Else(lgView.setText(lgView.getText() + " \n" + "No endpoints for INTERRUPT_TRANSFER") ; }
}

MDevice = device;
mEndpointIntr = epOUT;

// open an attachment for data transfer
if (device != null) (
UsbDeviceConnection connection = mUsbManager.openDevice(device);
if (connection != null && connection.claimInterface (intf, true)) (

lgView.setText(lgView.getText() + " \n"+ "Open device SUCCESS!" );
mConnection = connection;

) Else (

lgView.setText(lgView.getText() + " \n"+ "Open device FAIL!" );
mConnection = null;
}
}
}
}

In addition to the induced code, which, as if already sing-songly guessing a respectful reader, opens attachments for receiving and transmitting data, the protocol for the exchange of data is left behind, which, I repeat, can be good for the retailer. Or rather, as it was declared, the code to edit the HID will add a definitive packet of message data overrides, the UsbRequest class and the end point - see Listing 3.

Listing 3. Code example for editing data

// assign buffer size for editing
// out of the maximum package size
int bufferDataLength = mEndpointIntr.getMaxPacketSize();

lgView.setText(lgView.getText() + " \n"+ MEndpointIntr.getMaxPacketSize());

ByteBuffer buffer = ByteBuffer.allocate(bufferDataLength + 1);

UsbRequest request = new UsbRequest();

buffer.put(message);

request.initialize(mConnection, mEndpointIntr);

request.queue(buffer, bufferDataLength);

if (request.equals(mConnection.requestWait()))

// editing was successful
//lgView.setText(lgView.getText() + "\n" + "sending CLEAR!!!");

catch (Exception ex)

// that's not right...
//lgView.setText(lgView.getText() + "\n" + "sending not clear ...");

Add-ons filtering in AndroidManifest.xml

Although in our add-on it is not possible to ask for a specific add-on with the VID (Vendor-ID) and PID (Product-ID), Google engineers do not produce add-on applications without the intent-filter section in the manifest file, and the author could not reach the robot programs without filtering add in AndroidManifest.xml.

I guess that Vendor-ID and Product-ID are unique identifiers for USB devices. Tobto, vikoristovuyuchi filtration, you can create an addendum, as if interacting only with a singing outbuilding, or as a class of outbuildings. It is significant that the builders of the device are responsible for the organization of the USB IF.

Addendum, the manifest file of which is listed in Listing 4, and the file with smart filtering in Listing 5, for example, successfully connected to the USB-flash-storage mobile attachment, but does not recognize the keyboard and mouse, please contact the author. This program can be downloaded at the same time with the original code by request.

Listing 4. AndroidManifest.xml file


" > http://schemas.android.com/apk/res/android"
> package = "en.learn2prog.usbhostexample"
android:versionCode="1"
android:versionName="1.0">


android:minSdkVersion="12"
android:targetSdkVersion="14" />


android:allowbackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">

android:name= "Ru.learn2prog.usbhostexample.MainActivity"
android:label="@string/app_name">
>

"Android.intent.category.DEFAULT" />

"Android.intent.category.LAUNCHER" />

>

>

>
"android.hardware.usb.action.USB_DEVICE_ATTACHED"
android:resource="@xml/device_filter" />
>
>

>

Listing 5. Device_filter.xml filter file (/res/xml directory)

>

>

Operations on the selection and installation of our zastosuvannya are not considered in any way in the wild (div. Apply to,). I want to get respect for the difltra namiriv - when connected, I will add a request to the OS host to the OS host about the launch of our zastosuvannya.

Literature / References: 11.
12.
13. http://developer.android.com/guide/topics/connectivity/usb/host.html - an overview of the classes required for Android USB robots
14. sending supplements for the holidays

As it was already guessed, the Windows operating systems provide software for the sake of the functioning of attachments connected to the USB bus. Processing the data streams of USB devices on the same operating system is based on a stack of standard drivers, as well as changing the main functions of managing all USB devices and exchanging data between them and the system.

If you need to write security software for any kind of USB attachment, if it expands the data processing capabilities, then you can convert one of three possible ways:

I will write an authoritative driver, which will secure all the necessary functions of managing and exchanging data, and a program, as if it would interact with this driver in the mode recognized for the coristuvach. With this, you can almost do without standard system drivers;

write a filter driver, which would provide the necessary functionality, but also expand it in the drivers section above the system drivers. In this way, all the standard processing functions would be disabled by USB drivers, installed by the system, And the additional functions were taken care of by your filter driver, and the koristuvach program would work together;

speed up with freely expanding libraries of functions and drivers

mi for access to USB I will add.

More software access to the USB attachment may be needed, as this attachment may have a specific function. For example, on the basis of USB, "electronic oscillography" or data collection systems are developed, for which you need access to the device itself. Most of these types can be recreated with freely expanding function libraries, which will be practical in all popular programming environments. For example, under the GNU program, once again, I'll use software security, I'll call it LibUsb, which includes the necessary drivers and libraries of functions for robots in Windows and Linux operating systems. These libraries of functions are even more popular and allow you to freely expand the programs, as if interfacing with your device for an additional set of standard functions. Including the need to write a free driver, I will add it, which will significantly save an hour.

In addition, most of the coristuvachiv do not know the methodology for distributing drivers,

and even more foldable is the programming area, so the presence of such a freely expandable programmable software can be an invaluable aid to a wide coryne. On the basis of the LibUsb project, wrappers for Visual Basic .NET and C # .NET, the most popular of all LibUsbDotNet, are also developed for the widely expanded software. Regardless of guessing the folding nature of USB programming, refurbished the software security of the flooring will make this task easier, which will give strength to beginners. We marvel at practical butts, how to use them with your USB devices, and perhaps with the LibUsb software package. By the way, the above list of software security can be purchased for a fee from the site www.sourceforge.net or from the number of duplicate sites.

How to work with libraries of USB functions LibUsb? The library was motivated in such a way

so that you can perform the basic operations associated with the USB device:

Identification or, in other words, pererahuvannya (enumeration). When the operation is over, there will be an appearance of attachments connected to the USB bus, which will take care of the additional functions of the libusb library;

selection of parameters in the annex (identifiers of the annex, data on the type and characteristics of the annex), for which there are a number of functions in the library;

vodkrittya, zakrittya, reading and recording data, sending commands. Before attaching USB, just like other objects of the file system, you can start writing and reading, which can be used for additional functions of the library.

All refurbished possibilities can be implemented for additional support of the libusb library functions, but here the stench will not be refurbished, the shards would take too much money; we marvel at how victorious

Mal. 6.10

Deployment of the libusb0.sys driver in the driver's office

tions on practical butts. A description of all the functions of the reader can be found in the documentation. Guess what we are looking at zastosuvannya functions of the libusb library in Windows operating systems.

When installing the distribution kit with libusb in operating system Windows installs the libusb0.sys filter driver in the system. This driver will be reloaded at the top of the driver stack of the system, which is easy to hit on the butt, marveling at the information about drivers for any kind of USB add-on (Fig. 6.10).

In addition, for downloading to the driver from the program, the libusb0.dll library is installed into the system, which can be downloaded by other programs.

Mal. 6.17

View of the window of the program when removed

USB device from the system

In the past year, we took the firmware for the controller, making it possible to process it via USB. And for interfacing with the computer, we need a special program to run on the computer.

Axis at once mi і we will її create.

Well, I know in the Microchip solutions package - an example for our controller, but I rewrote yoga in my own way. First, I created the graphical interface without changing it, and changed the code by 3-4 times. What is richer than the wedding. Prote, the principle of work is one. the code in the standard application as a microchip works just the same.

The program is written in C++. Draft draft in student version of Visual C ++ express 2010. I will give great ideas and comments on the code, but I may on the other hand, so you can still get some knowledge of programming in C ++.

Father, let's start

Here you can find the whole project, including the original text sent

In order to read and write data via the USB port, we need to take the indicator to our device. Shards on the vіdmіnu vіd old portіv, it's possible to connect but have attached over a hundred, then it's not so easy to take the indicator. In order to keep us safe, we will go to windows drivers, and the SetupAPI itself. Before we speak, as soon as we take the indicator, we will use the USB port, no matter the file.
Transferring data will only take a couple of commands. Ale axis preparation!
Since we are programmable in C ++, then we need to be more accurate with data types.
We create a win32 console project. І add one file main.cpp

Otzhe, we need to connect the deacons of the library.
#include
#include
#include

So the very connection of the library is included:
#pragma comment (lib, "setupapi.lib")

First, the function in the getUSBHandle () program is described. Її description - in comments to the code. That and the main comments are put in the code. Won to serve in order to know our attachments and prepare demonstrators, so that we could write down in attachments and read from the new.
In a nutshell, there are standard windows functions for accessing USB drivers and through them taking the indicator to the device itself.
If so, if all functions work and work, then go to MSDN or to Agurov's book, which lies in the dark. What is important to know: I’ll build a way at the skin, and it’s important for us to take yoga. We are slowly checking, chi zbіgaєtsya ID z pristroєm, scho mi joking. And then we know the path of the device. it is indicated in the change Guid. Reshta divas in the comments of the program
The next function is writeReadUSB. This is just an additional function, as it is recorded in our appendix. I’m sorry that I’ll add a write and a read after that, as we have created an indicator for a new implementation using the standard commands WriteFile and ReadFile
І after all, we are now running the main function for the sake of starting the program. It calls getUSBHandle, while we don't take away the indicator for the attachment, then we read the command from the keyboard and in the fallback in it, transfer and read the data from the USB attachment.
At the project, according to the strength, it’s better to lie exit code With comments, that program itself was compiled. Hai be happy.

In the process of asking for a pardon, I spent on the hidapi library. Won є cross-platform. І T_lki for robots with hid outbuildings. It is even simpler for the vikoristan. Navodzha project under it. posilannya.
Hidapi downloads from the official site. In order to start the project, you need to add setupapi.lib to the linker. project-> properties-> linker-> input and signing things setupapi.lib;
Hai be happy.
Know a decent description of the library here: http://microsin.net/programming/PC/multi-platform-hid-api.html.
Thank you!

Support the project - share your efforts, thank you!
Read also
Sbebrank (also known as Oschadbank) Sbebrank (also known as Oschadbank) Solving license problems with Autocad Chi does not start autocad windows 7 Solving license problems with Autocad Chi does not start autocad windows 7 Instructions for selecting the CryptoPro PIN code, at the hour of signing a number of documents - Instructions - AT Instructions for choosing the CryptoPro PIN code, at the hour of signing a number of documents - Instructions - JSC "PEK-Torg"