Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can I differentiate between input devices in C#?

Status
Not open for further replies.

noonan59

Programmer
Oct 27, 2003
29
US
If I have 2 different input devices (such as a barcode reader and a keypad) connected via 2 USB ports, is there a way for a desktop application in C# to tell which device is inputting data at any given moment? Currently the program I am working on accepts the input from either device, but it doesn't know which device is producing the input. I need to have one set of code run if the input is from the barcode reader and another set of code run if the input is from the keypad.

thanks.... Dan
 
Your program should create a thread that will watch the USB1 (for example keypad) port (buffers come in) and another thread to watch for the USB2 (barcode reader).
When a char or buffer arrive in USB1 then a custom event will be raised : event EventHandler eventUSB1KeypadStatusChanged;

When a char or buffer arrive in USB2 then a custom event will be raised :
event EventHandler eventUSB2BarcodeStatusChanged;
The both threads produce the above events and the main module consumes these events.
The main program will trap the both above events and will execute a code depending on each event.
Use:
-CreateFile() - open a port
-SetCommMask() - comm mask
-DCB structure - port settings
-CreateEvent() - create I/O event for port
-WaitCommEvent() - wait a char or buufer come in
-ReadFile() - to read the buffer in an open port

-obislavu-




 
Thanks! I'll get it a try and let you know what I come up with.

-Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top