Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 2005 > Visual Basic 2005 Basics
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Visual Basic 2005 Basics If you are new to Visual Basic programming with version 2005, this is the place to start your questions. For questions about the book: Beginning Visual Basic 2005 by Thearon Willis and Bryan Newsome, ISBN: 0-7645-7401-9 please, use this forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Basic 2005 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 23rd, 2008, 04:54 AM
Registered User
 
Join Date: Jan 2008
Location: , , .
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default Read stream from USB Magnetic Card Reader

Hello,
I would appreciate some help putting a stream of numbers from a USB magnetic card reader into a variable.

I have a USB Magnetic Card Reader (type MSR210). When I swipe any magnetic card it returns a stream of numbers. No matter what program is opened (Excel, Notepad, or even a command prompt) it puts that stream of numbers in the opened program and ends the stream with a return (CR).

I would like to have my form1.vb being aware of a magnetic card being swiped. (without that stream being put into any field that has current focus at the time, e.g. a textbox.)

I want to pick up the stream of numbers, put it into a variable then extract form the variable a number that is identifying our club members (userid) and use that to set the bindingmanager index to a userid in the database (the program will then show user data and picture of that member).

Questions: how do I:
1. Pick up the stream of numbers from the USB port (if that is what I must do - to eventually put that number into a variable)

2. If not 1. then how do I capture the stream of numbers at any time (no matter what object has focus on the form)

3. How do I make sure the stream of numbers is ONLY entered into my variable and not into a field that has current focus?

Thank you in advance for your help.

- Tsadok

Reply With Quote
  #2 (permalink)  
Old January 23rd, 2008, 09:33 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

You'll need to refer to the device manual further I think.

It sounds like what is happening is that the device is simply "typing" the values it gets from the card. So it is essentially acting as a user interface device like a keyboard. If you have a windows form application active you can capture keyboard input and put the values somewhere else (i.e. your "card number" variable). The problem here is that if this is the way the device does indeed behave you may very well not be able to distinguish between characters entered by the device and characters entered by the user at a keyboard. So the program would similarly consume the characters entered by a user because it can't tell the difference. This will require you to have the focus on a specific control such as a textbox so that the device can enter the data.

Does the device provide any additional data that might help you identify input from it versus that from a keyboard (perhaps some prefix characters to what is scanned)?

One possible solution could be pattern recognition. Your form could watch what is being "entered" (by either the user or the device) and then look for the pattern of the numbers you would expect from the card reader. When you encounter input that matches, you could perform the necessary action. If the user happens to have focus on an input field such as a textbox, you could erase the number you just recognized from that textbox so it would be as if it wasn't entered.

Looking at this from the perspective of usability I wonder if it wouldn't be sensible to set this up as a textbox entry field anyway. What happens if the card reader can't read the card? Shouldn't the user be allowed to manually enter the card number that's printed on it? This could remove the problem of trying to hide the reader input from the user while providing the user with a fall back in the event of a problem.

-Peter
Reply With Quote
  #3 (permalink)  
Old January 23rd, 2008, 10:07 AM
Registered User
 
Join Date: Jan 2008
Location: , , .
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

[quote]Originally posted by planoie
 You'll need to refer to the device manual further I think.

First - Thank you Peter for your quick reply.
The device doesn't come with a manual and you are right - the USB Card reader is listed in Windows Hardware as HID Keyboard.

When a card is swipped a long row of numbers (15-19 characters) starting with 000 appears. That would indeed make it possible to distinguish them from other input BUT... I would rather pick-up the stream from the HID Device using a capture or such.

I have browsed the endless solutions on MSDN and Google about HID-Classes and RawInput API's see e.g. http://msdn2.microsoft.com/en-us/library/ms996387.aspx but I seem not to comprehend the how to capture the data originating from the HID Keyboard (Card Reader).

- Tsadok



Reply With Quote
  #4 (permalink)  
Old January 23rd, 2008, 01:21 PM
Friend of Wrox
 
Join Date: Nov 2004
Location: Port Orchard, WA, USA.
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

I would guess that there is Windows message traffic associated with this action.

As you probably know, everything that happens in Windows is message based. When you press a key, a message is generated, when you release it, a message is generated. When you move the mouse messages are generated.

It seems reasonable that when this reader starts talking, there is message traffic associated with that. You can cause a VB program to pay attention to messages through the API functions Windows comes with. Research messaging, and how to add message handling to your app.

After adding message listening, log activity while using the reader, and see if you can discover the specific messages that this device raises. Then you'll be able to refine your “listening” process so as to handle input from this device in the way that you need to.

Like I said, just guessing.
Reply With Quote
  #5 (permalink)  
Old January 23rd, 2008, 02:08 PM
Registered User
 
Join Date: Jan 2008
Location: , , .
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

 
Quote:
quote:
Quote:
After adding message listening, log activity while using the reader, and see if you can discover the specific messages that this device raises. Then you'll be able to refine your “listening” process so as to handle input from this device in the way that you need to.
Thank you BrianWren. You must have expected the next question:
Being a newbie and not at all familiar with debugging yet...
Question:

Please point me to any documentation about activating "listeners" in VB2005. I have Rod Stephens book (VB 2005 Programmers Reference) but cannot find anything about streams originating from HID, and other ports other then a serial port.

Thank you all again in advance for taking the time to help me.

- TSadok

Reply With Quote
  #6 (permalink)  
Old January 23rd, 2008, 03:40 PM
Friend of Wrox
 
Join Date: Nov 2004
Location: Port Orchard, WA, USA.
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Well, I wasn't using a technical term... What I would do if I were you, is research using APIs (this involves adding a statement that starts with "Declare Sub . . . " or "Declare Function . . . ") and using Windows Messages.

As for a "listener," what I meant by that was having a process in your app that pays attention to messages.

Perhaps I'll come back in a bit and add some more.
Reply With Quote
  #7 (permalink)  
Old January 23rd, 2008, 04:53 PM
Friend of Wrox
 
Join Date: Nov 2004
Location: Port Orchard, WA, USA.
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

I believe the API that is going to helpful for this is GetMessage()
Reply With Quote
  #8 (permalink)  
Old September 3rd, 2008, 05:48 AM
Mo Mo is offline
Registered User
 
Join Date: Sep 2008
Location: Leeds, , United Kingdom.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi There,

I know its been a while, but I have a MSR152 that I am trying to get data out of and don't quite know where to start... how did you setup the initial communication and what commands were you sending to get at the stream of numbers? Documentation on these things is unbelievably scarce considering how many of them must be out there!! Any help greatly appreciated!

Cheers

Mike
Reply With Quote
  #9 (permalink)  
Old September 3rd, 2008, 03:02 PM
Friend of Wrox
 
Join Date: Nov 2004
Location: Port Orchard, WA, USA.
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

As I understood from this thread, the device acts like a keyboard.

So you would write your program to get set for keyboard input, then, when the screen shows the input box you've prgrammed, or the textbox, then you would sent the card through.

The problem in this thread, was that Tsadok didn't want to set the program to listen, then give it the input, he wanted to be able to have the insertion of a card bring the program around to the listening state in time to actually capture the stream coming from the reader.

Does that help?
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
RF Card Reader Interfacing with windows App rajthilak General .NET 0 October 13th, 2007 07:47 AM
smart card reader on client using asp.net mkmustafa ASP.NET 2.0 Professional 3 July 4th, 2007 01:11 PM
USB Memory Card Reader support on FC5 crmpicco Linux 2 March 10th, 2007 09:50 AM
magnetic stripe read/write frankv25 Pro VB.NET 2002/2003 1 April 16th, 2004 03:44 PM
How to make stream reader read doc files? bcmaverik VB.NET 2002/2003 Basics 2 March 10th, 2004 10:28 AM



All times are GMT -4. The time now is 12:05 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.