CN107562676B - Method for communicating with generator set controller through USB (universal serial bus) based on VB - Google Patents

Method for communicating with generator set controller through USB (universal serial bus) based on VB Download PDF

Info

Publication number
CN107562676B
CN107562676B CN201710835537.3A CN201710835537A CN107562676B CN 107562676 B CN107562676 B CN 107562676B CN 201710835537 A CN201710835537 A CN 201710835537A CN 107562676 B CN107562676 B CN 107562676B
Authority
CN
China
Prior art keywords
command
generator set
set controller
hid
communicating
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201710835537.3A
Other languages
Chinese (zh)
Other versions
CN107562676A (en
Inventor
冯斌
杨新征
王海川
王洪杰
徐铁山
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Zhengzhou Smartgen Technology Co Ltd
Original Assignee
Zhengzhou Smartgen Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Zhengzhou Smartgen Technology Co Ltd filed Critical Zhengzhou Smartgen Technology Co Ltd
Priority to CN201710835537.3A priority Critical patent/CN107562676B/en
Publication of CN107562676A publication Critical patent/CN107562676A/en
Application granted granted Critical
Publication of CN107562676B publication Critical patent/CN107562676B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Abstract

The invention provides a method for communicating with a generator set controller through a USB (universal serial bus) based on VB.net, which comprises the following steps: step 1: acquiring a GUID of HID equipment on a computer; step 2: acquiring handles containing all HID equipment interface information sets through the GUIDs obtained in the step 1; and step 3: finding out a generator set controller connected with the computer according to VID and PID of the HID; and 4, step 4: the upper computer generates a command list sent to the generator set controller; and 5: and writing the command list into the generator set controller through a USB, and communicating the upper computer with the generator set controller. The VB.net-based method for communicating with the generator set controller through the USB has the advantages of easiness in implementation, no need of driving and high communication speed.

Description

Method for communicating with generator set controller through USB (universal serial bus) based on VB
Technical Field
The invention relates to a method for communicating with a controller, in particular to a method for communicating with a generator set controller through a USB (universal serial bus) based on VB.
Background
The communication between the generator set controller and the upper computer is generally carried out through an RS485 mode, the mode needs to be connected to a COM port of a computer in a wiring mode, more and more computers, particularly notebook computers, do not have COM ports at present, a converter for converting a USB into a serial port needs to be bought for communicating with the controller, and the communication between the generator set controller and the upper computer is quite inconvenient, slow in speed and incapable of meeting the requirements of users.
In order to solve the above problems, people are always seeking an ideal technical solution.
Disclosure of Invention
The invention aims to overcome the defects in the prior art, and provides a VB.net-based method for communicating with a generator set controller through a USB, which is easy to implement, does not need to be driven, and has stable communication and high communication speed.
In order to achieve the purpose, the invention adopts the technical scheme that: a vb.net based method of communicating with a genset controller over USB comprising the steps of:
step 1: acquiring a GUID of HID equipment on a computer;
step 2: acquiring handles containing all HID equipment interface information sets through the GUIDs obtained in the step 1;
and step 3: finding out a generator set controller connected with the upper computer according to VID and PID of the HID;
and 4, step 4: the upper computer generates a command list sent to the generator set controller;
and 5: and writing the command list into the generator set controller through a USB, and communicating the upper computer with the generator set controller.
Based on the above, in step 1, invoking the HidD _ GetHidGuid function includes:
step 1.1, newly building an empty GUID object HidGuid;
and step 1.2, calling a HidD _ GetHidGuid function to obtain GUIDs of all HID devices on the upper computer, and assigning values to HidGuid.
Based on the above, the step 1.2 further includes generating a guiding string according to the HidGuid.
Based on the above, the step 2 includes:
step 2.1, obtaining DeviceInfoSet information of the HID;
step 2.2, enumerating all HID devices;
and 2.3, obtaining the path of each HID and obtaining the HID mark code number.
Based on the above, the step 3 includes:
step 3.1, obtaining VID and PID of the HID according to the HID identification code obtained in the step 2.3, wherein the VID is manufacturer ID, and the PID is equipment version number;
3.2, finding out HID equipment with the same VID and PID as the generator set controller;
3.3, recording a handle of the generator set controller, wherein the HID found in the step 3.2 is the generator set controller needing to be communicated with the upper computer.
Based on the above, the step 4 includes:
step 4.1, the upper computer generates a command list which is sent to the generator set controller, wherein the command list comprises 03, 05, 06, 09 and 10 function codes;
the 03 function code comprises the model of the reading generator set controller, reading configuration and reading monitoring information; 05, using the function code for data calibration; 06 function codes are used for writing configuration; 09. the 10 function codes are used for writing a word stock lattice of the generator set controller;
and 4.2, generating a command table CmdList from the commands in the command list.
Based on the above, in step 5, according to the command identifier, selecting a corresponding command in the command list; the command identification corresponds to corresponding commands in the command list one by one;
when the upper computer sends commands, adding a command number YZCode to each command, and sending the commands to the generator set controller by using a WriteReport function;
when the upper computer receives the command, the command returned by the generator set controller is received by using a ReadReport function, whether the command number is the requested command number or not is judged, and if the command number is not the requested command number, the upper computer retransmits the command; if the command number is the requested command number, judging whether the command number is smaller than 255, if so, adding 1 to the command number, otherwise, setting the command number to be 1.
Compared with the prior art, the invention has substantive characteristics and progress, and particularly comprises the following steps:
1) the invention provides a method for communicating with a generator set controller through a USB (universal serial bus) based on VB.net, wherein the generator set controller is connected to a computer through any one common USB wire without any drive or a converter for converting the USB into a serial port, an upper computer enumerates all HID (human interface device) equipment on the computer, finds corresponding HID equipment according to VID and PID (proportion integration differentiation) of the generator set controller, packages a command list and adds a command number to send the command list to the generator set controller for communicating with the generator set controller, and the method is convenient to use, stable in communication and high in communication speed;
2) the upper computer is used for communicating with the generator set controller through USB connection, so that operations such as reading configuration, writing configuration, reading monitoring information, data calibration and the like of the generator set controller are realized;
in conclusion, the invention has the advantages of easy realization, no need of driving, stable communication and high communication speed.
Drawings
FIG. 1 is a flow chart of the present invention.
FIG. 2 is a flow chart of step 5 of the present invention.
FIG. 3 is an interface of the present invention communicating with a controller via a USB connection.
Detailed Description
The technical solution of the present invention is further described in detail by the following embodiments.
A method of communicating with a genset controller over USB based on vb.
Step 1: acquiring a GUID of HID equipment on a computer;
in step 1, calling a HidD _ GetHidGuid function includes:
step 1.1, newly building an empty GUID object HidGuid;
step 1.2, calling a HidD _ GetHidGuid function to obtain GUIDs of all HID devices on the computer, and assigning values to HidGuid.
The step 1.2 further comprises generating a GuidString string according to the HidGuid.
Step 2: acquiring handles containing all HID equipment interface information sets through the GUIDs obtained in the step 1; the step 2 comprises the following steps:
step 2.1, obtaining DeviceInfoSet information of the HID;
step 2.2, enumerating all HID devices;
and 2.3, obtaining the path of each HID and obtaining the HID mark code number.
And step 3: finding out a generator set controller connected with the computer according to VID and PID of the HID; the step 3 comprises the following steps:
step 3.1, obtaining VID and PID of the HID according to the HID identification code obtained in the step 2.3, wherein the VID is manufacturer ID, and the PID is equipment version number;
3.2, finding out HID equipment with the same VID and PID as the generator set controller;
3.3, recording a handle of the generator set controller, wherein the HID found in the step 3.2 is the generator set controller needing to be communicated with the upper computer.
And 4, step 4: generating a command list sent to the generator set controller by an upper computer, wherein the upper computer is software installed in a computer; the step 4 comprises the following steps:
step 4.1, the upper computer generates a command list which is sent to the generator set controller, wherein the command list comprises 03, 05, 06, 09 and 10 function codes; the 03 function code comprises the model of the reading generator set controller, reading configuration and reading monitoring information; 05, using the function code for data calibration; 06 function codes are used for writing configuration; 09. the 10 function codes are used for writing a word stock lattice of the generator set controller;
and 4.2, generating a command table CmdList from the commands in the command list. The command includes a function code and an address, etc.
And 5: and writing the command list into the generator set controller through a USB, and communicating the upper computer with the generator set controller.
In the step 5, selecting a corresponding command in the command list according to the command identifier; the command identification corresponds to corresponding commands in the command list one by one; when the upper computer sends commands, adding a command number YZCode to each command, and sending the commands to the generator set controller by using a WriteReport function; when the upper computer receives the command, the command returned by the generator set controller is received by using a ReadReport function, whether the command number is the requested command number or not is judged, and if the command number is not the requested command number, the upper computer retransmits the command; if the command number is the requested command number, judging whether the command number is smaller than 255, if so, adding 1 to the command number, otherwise, setting the command number to be 1.
Finally, it should be noted that the above examples are only used to illustrate the technical solutions of the present invention and not to limit the same; although the present invention has been described in detail with reference to preferred embodiments, those skilled in the art will understand that: modifications to the specific embodiments of the invention or equivalent substitutions for parts of the technical features may be made; without departing from the spirit of the present invention, it is intended to cover all aspects of the invention as defined by the appended claims.

Claims (6)

1. A vb.net-based method for communicating with a generator set controller via a USB, the method comprising: the method comprises the following steps:
step 1: acquiring a GUID of HID equipment on a computer;
step 2: acquiring handles containing all HID equipment interface information sets through the GUIDs obtained in the step 1;
and step 3: finding out a generator set controller connected with the computer according to VID and PID of the HID;
and 4, step 4: the upper computer generates a command list sent to the generator set controller;
and 5: writing a command list into the generator set controller through a USB, and communicating an upper computer with the generator set controller;
in the step 5, selecting a corresponding command in the command list according to the command identifier; the command identification corresponds to corresponding commands in the command list one by one;
when the upper computer sends commands, adding a command number YZCode to each command, and sending the commands to the generator set controller by using a WriteReport function;
when the upper computer receives the command, the command returned by the generator set controller is received by using a ReadReport function, whether the command number is the requested command number or not is judged, and if the command number is not the requested command number, the upper computer retransmits the command; if the command number is the requested command number, judging whether the command number is smaller than 255, if so, adding 1 to the command number, otherwise, setting the command number to be 1.
2. Net-based method for communicating with a genset controller over USB according to claim 1 wherein invoking the HidD _ GetHidGuid function in step 1 comprises:
step 1.1, newly building an empty GUID object HidGuid;
step 1.2, calling a HidD _ GetHidGuid function to obtain GUIDs of all HID devices on the computer, and assigning values to HidGuid.
3. A vb.net based method of communicating with a genset controller over USB as claimed in claim 2 wherein: the step 1.2 further comprises generating a GuidString string according to the HidGuid.
4. A vb.net-based method for communicating with a genset controller over USB as claimed in claim 1 wherein step 2 comprises:
step 2.1, obtaining DeviceInfoSet information of the HID;
step 2.2, enumerating all HID devices;
and 2.3, obtaining the path of each HID and obtaining the HID mark code number.
5. A VB.net-based method for communicating with a genset controller over USB, the method of claim 4 wherein step 3 comprises:
step 3.1, obtaining VID and PID of the HID according to the HID identification code obtained in the step 2.3, wherein the VID is manufacturer ID, and the PID is equipment version number;
3.2, finding out HID equipment with the same VID and PID as the generator set controller;
3.3, recording a handle of the generator set controller, wherein the HID found in the step 3.2 is the generator set controller needing to be communicated with the upper computer.
6. A vb.net-based method for communicating with a genset controller over USB as claimed in claim 1 wherein step 4 comprises:
step 4.1, the upper computer generates a command list which is sent to the generator set controller, wherein the command list comprises 03, 05, 06, 09 and 10 function codes;
the 03 function code comprises the model of the reading generator set controller, reading configuration and reading monitoring information; 05, using the function code for data calibration; 06 function codes are used for writing configuration; 09. the 10 function codes are used for writing a word stock lattice of the generator set controller;
and 4.2, generating a command table CmdList from the commands in the command list.
CN201710835537.3A 2017-09-15 2017-09-15 Method for communicating with generator set controller through USB (universal serial bus) based on VB Active CN107562676B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201710835537.3A CN107562676B (en) 2017-09-15 2017-09-15 Method for communicating with generator set controller through USB (universal serial bus) based on VB

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201710835537.3A CN107562676B (en) 2017-09-15 2017-09-15 Method for communicating with generator set controller through USB (universal serial bus) based on VB

Publications (2)

Publication Number Publication Date
CN107562676A CN107562676A (en) 2018-01-09
CN107562676B true CN107562676B (en) 2020-10-09

Family

ID=60981194

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201710835537.3A Active CN107562676B (en) 2017-09-15 2017-09-15 Method for communicating with generator set controller through USB (universal serial bus) based on VB

Country Status (1)

Country Link
CN (1) CN107562676B (en)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108664434B (en) * 2018-05-16 2021-10-22 郑州众智科技股份有限公司 Communication method of HID (high intensity discharge) equipment based on USB (Universal Serial bus) interface of generator set controller
CN110855447B (en) * 2019-10-23 2022-03-25 郑州众智科技股份有限公司 Communication connection method, communication method and generator set controller communication system

Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101169732A (en) * 2006-10-25 2008-04-30 北京握奇数据系统有限公司 Method and system for matching equipment handle and equipment of multiple human-machine interface equipment
CN103441912A (en) * 2013-08-14 2013-12-11 上海固泰科技有限公司 FlexRay bus monitoring method based on USB-HID protocol
CN204283632U (en) * 2014-11-27 2015-04-22 福建唐力电力设备有限公司 Generator set Intelligent integrated formula controller

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9256569B2 (en) * 2014-02-26 2016-02-09 American Megatrends, Inc. Monitoring and managing storage drives and performing backplane controller firmware using a USB interface

Patent Citations (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101169732A (en) * 2006-10-25 2008-04-30 北京握奇数据系统有限公司 Method and system for matching equipment handle and equipment of multiple human-machine interface equipment
CN103441912A (en) * 2013-08-14 2013-12-11 上海固泰科技有限公司 FlexRay bus monitoring method based on USB-HID protocol
CN204283632U (en) * 2014-11-27 2015-04-22 福建唐力电力设备有限公司 Generator set Intelligent integrated formula controller

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
基于Java的USB-HID设备通信设计与实现;杨民峰;《北京工业职业技术学院学报》;20160131;第15卷(第01期);全文 *

Also Published As

Publication number Publication date
CN107562676A (en) 2018-01-09

Similar Documents

Publication Publication Date Title
CN108769109B (en) Unified processing method and system for data of Internet of things heterogeneous equipment
CN104007801B (en) For providing the method and apparatus of power to electronic equipment
CN102760104B (en) USB (Universal Serial Bus) equipment control method
CN104199723B (en) Camera mapping method based on virtual equipment
CN101938164B (en) Power equipment control method, device and related system thereof
CN102736565B (en) Communication method of automatic control equipment based on upper and lower computer structures
KR20160013174A (en) A method, apparatus and system for performing management component transport protocol (mctp) communications with a universal serial bus (usb) device
CN107688548B (en) System, device and method for expanding sequence communication and system for expanding communication port
ATE443889T1 (en) DEVICE INTERFACES FOR NETWORKING A COMPUTER AND AN EMBEDDED DEVICE
CN102638397A (en) USB (universal serial bus) device communication transmission method, device and system
CN107562676B (en) Method for communicating with generator set controller through USB (universal serial bus) based on VB
US20100180050A1 (en) Communication system capatible to universal serial bus (usb) and method thereof
CN104077252B (en) USB device communication means, device and electronic equipment
CN101763324A (en) Method for realizing equipment simulating and device thereof
CN102737003B (en) A kind of method and device of simulating USB device
WO2021120674A1 (en) Method and apparatus for multi-bus device fused access
US8452883B2 (en) Method for data transmission
CN108920389B (en) Method and device for dynamically matching protocol type and application of multi-protocol USB device
CN104753746B (en) The method and control server of a kind of access device
US20130132600A1 (en) Apparatus and method of a portable terminal for performing communication with a device supporting media transfer protocol
CN110572387B (en) Link layer processing method
JP3647827B2 (en) Wireless printing interface kit and method
WO2022110125A1 (en) Method for transmitting data to hmi, and usb hid device
CN101056312A (en) A method and system for communication between the devices
KR101122418B1 (en) Protocol interface device, system and method using a text file

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant