Jump to content

Input/Output Java, C or C++

BrownZeus

Hey guys,

 

I'm a fairly novice programmer, and I've taken on (well, thought of and assigned myself) a project. Long story short, it's meant to automatically pull data from a Driver's License and output the data into fields, for say Name, DOB etc.

 

THe scanner I'm using is a Honeywell Voyager 1450g, and out of the box it behaves much like a keyboard. It'll scan the licenses and output the data into a text box all in one shot. I've scanned my own license into a blank word document and am able to read the data/

 

Now the scanned input is legible to a certain degree, there is some apparent irrelevent data coded in. I've scanned other people's licenses (approximately 25 license, all from the same state, varying addresses and name lengths) and I've been able to discern at which points in the data I could pull specific data from. For example each piece of data has correspond tag of sorts before it, so for last name it'll look like "DCS[Last Name Here]", DCS being the data tag.

 

SO what I wanna know is, can I write my program to get this scanned input, but instead of writing it to a field immediately, have the input analyzed and pull the specific data out before having it outputted to a field?

 

I would love to post an example of the data that gets written by the barcode, but I'm not sure what the other non-text data encodes and therefore I won't risk making my personal information public.

 

If anyone needs clarification in any aspect of my inquiry please let me know and I will try to elaborate more.

Link to comment
Share on other sites

Link to post
Share on other sites

are you using something liek WinForms/WPF/Spring - do you have a GUI or is that a console application?

either way if it's an event based GUI then just add your logic in "OnChange" event and update the textboxes value afterwards should be quick enough for the user to not even notice

if you don't want the user to focus text box beforehand then you can try using keyboard hooks and add events to that

 

if it's a console app, then pretty much treat it as a regular keyboard input and then spit out your values

CPU: Intel i7 5820K @ 4.20 GHz | MotherboardMSI X99S SLI PLUS | RAM: Corsair LPX 16GB DDR4 @ 2666MHz | GPU: Sapphire R9 Fury (x2 CrossFire)
Storage: Samsung 950Pro 512GB // OCZ Vector150 240GB // Seagate 1TB | PSU: Seasonic 1050 Snow Silent | Case: NZXT H440 | Cooling: Nepton 240M
FireStrike // Extreme // Ultra // 8K // 16K

 

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, DXMember said:

are you using something liek WinForms/WPF/Spring - do you have a GUI or is that a console application?

It will be a gui with the following TEXT(String) Fields.

-Last Name

-First Name

-Address

-DOB

-Date of Expiry

 

By default the barcode scanner outputs some like the foillowing into a text field:

 

123456789123456789123456789 DCAB  DCDNONE

[more misclelaneuous data]DCS[Last Name] + more data with all the other things I need

 

So what I wanna do is take all the string data^ analayze to say the last name, get the last name, and input the last name to its' respective field, and then move on to the next piece of data I'm looking for in the string.

Link to comment
Share on other sites

Link to post
Share on other sites

12 minutes ago, BrownZeus said:

It will be a gui with the following TEXT(String) Fields.

-Last Name

-First Name

-Address

-DOB

-Date of Expiry

 

By default the barcode scanner outputs some like the foillowing into a text field:

 

123456789123456789123456789 DCAB  DCDNONE

[more misclelaneuous data]DCS[Last Name] + more data with all the other things I need

 

So what I wanna do is take all the string data^ analayze to say the last name, get the last name, and input the last name to its' respective field, and then move on to the next piece of data I'm looking for in the string.

quickest/easiest way would be to add another text field like "MRZ (Machine Readable Zone)" - make the user focus that field, scan the license, and you just add an event "OnChange" where you parse the MRZ and update the other textboxes with respective values

alternatively - instead of "OnChange" event you could also add a button for user to click

or a more advanced way if you don't want an MRZ input field would be to use keyboard hooks and analyze each keystroke individually

 

I don't really follow, which part do you feel like is the hardest? Do you need help with the basics or the hints I wrote down could be enough?

CPU: Intel i7 5820K @ 4.20 GHz | MotherboardMSI X99S SLI PLUS | RAM: Corsair LPX 16GB DDR4 @ 2666MHz | GPU: Sapphire R9 Fury (x2 CrossFire)
Storage: Samsung 950Pro 512GB // OCZ Vector150 240GB // Seagate 1TB | PSU: Seasonic 1050 Snow Silent | Case: NZXT H440 | Cooling: Nepton 240M
FireStrike // Extreme // Ultra // 8K // 16K

 

Link to comment
Share on other sites

Link to post
Share on other sites

2 minutes ago, DXMember said:

quickest/easiest way would be to add another text field like "MRZ (Machine Readable Zone)" - make the user focus that field, scan the license, and you just add an event "OnChange" where you parse the MRZ and update the other textboxes with respective values instead of "OnChange" event you could also add a button for user to click

or a more advanced way if you don't want an MRZ input field would be to use keyboard hooks and analyze each keystroke individually

I was able to identify data markers (Characters in the data that indicate specific piece of data), like 'DCS" that indicates last name. I was hoping to have the data read to maybe a buffer or something that'll analyze the data and pull the data from the markers I point it at. Is there anything like that maybe? For ease of use I'd rather that then having my end user scanning something to another field and hitting a button

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, BrownZeus said:

I was able to identify data markers (Characters in the data that indicate specific piece of data), like 'DCS" that indicates last name. I was hoping to have the data read to maybe a buffer or something that'll analyze the data and pull the data from the markers I point it at. Is there anything like that maybe? For ease of use I'd rather that then having my end user scanning something to another field and hitting a button

depending on the environment you use for development - Visual Studio definitely has - there should be a global KeyPress event that you can use to do that sort of thing

but I still feel like having a separate MRZ text box (without buttons) with "OnChange" event would be the easiest to do

CPU: Intel i7 5820K @ 4.20 GHz | MotherboardMSI X99S SLI PLUS | RAM: Corsair LPX 16GB DDR4 @ 2666MHz | GPU: Sapphire R9 Fury (x2 CrossFire)
Storage: Samsung 950Pro 512GB // OCZ Vector150 240GB // Seagate 1TB | PSU: Seasonic 1050 Snow Silent | Case: NZXT H440 | Cooling: Nepton 240M
FireStrike // Extreme // Ultra // 8K // 16K

 

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, DXMember said:

depending on the environment you use for development - Visual Studio definitely has - there should be a global KeyPress event that you can use to do that sort of thing

but I still feel like having a separate MRZ text box (without buttons) with "OnChange" event would be the easiest to do

Definitely does sound simple enough. But I'm going to keep doing my research and see if I can find something closer to what I'm looking for.

 

If I can't, I'll do it your way for sure.

 

Sincerely, thank you, it very much appreciated.

Link to comment
Share on other sites

Link to post
Share on other sites

2 minutes ago, BrownZeus said:

Definitely does sound simple enough. But I'm going to keep doing my research and see if I can find something closer to what I'm looking for.

 

If I can't, I'll do it your way for sure.

 

Sincerely, thank you, it very much appreciated.

https://docs.microsoft.com/en-us/dotnet/framework/winforms/using-keyboard-events

https://msdn.microsoft.com/en-us/library/system.windows.forms.control.keypress(v=vs.110).aspx

CPU: Intel i7 5820K @ 4.20 GHz | MotherboardMSI X99S SLI PLUS | RAM: Corsair LPX 16GB DDR4 @ 2666MHz | GPU: Sapphire R9 Fury (x2 CrossFire)
Storage: Samsung 950Pro 512GB // OCZ Vector150 240GB // Seagate 1TB | PSU: Seasonic 1050 Snow Silent | Case: NZXT H440 | Cooling: Nepton 240M
FireStrike // Extreme // Ultra // 8K // 16K

 

Link to comment
Share on other sites

Link to post
Share on other sites

I could've sworn most barcode scanners these days act like virtual serial ports and they just dump data out as basically an ASCII string.

 

Either way, if the data is well formatted, such as you know a field is x number of bytes or fields are delimited by some character or pattern, you can pluck out the data you need from the string. The problem is knowing what those bits are.

Link to comment
Share on other sites

Link to post
Share on other sites

1 hour ago, M.Yurizaki said:

I could've sworn most barcode scanners these days act like virtual serial ports and they just dump data out as basically an ASCII string.

 

Either way, if the data is well formatted, such as you know a field is x number of bytes or fields are delimited by some character or pattern, you can pluck out the data you need from the string. The problem is knowing what those bits are.

There are limits via characters, so for example between "DCS" and "DCT" will where I will find the last name of a scanned client. What I want to know is how to pluck the data without having to have the scanner write to a text field first. I want the string to basically just input to an algorithm and then the algorithm will do the plucking.

Link to comment
Share on other sites

Link to post
Share on other sites

1 hour ago, BrownZeus said:

There are limits via characters, so for example between "DCS" and "DCT" will where I will find the last name of a scanned client. What I want to know is how to pluck the data without having to have the scanner write to a text field first. I want the string to basically just input to an algorithm and then the algorithm will do the plucking.

How is the scanner sending in data? It can't be "I know there's a text box so I'll write directly to it"

Link to comment
Share on other sites

Link to post
Share on other sites

2 hours ago, M.Yurizaki said:

How is the scanner sending in data? It can't be "I know there's a text box so I'll write directly to it"

Its acting as a keyboard. Any barcode I scan will type out data if a text field is focused. The scanner can be reprogrammed to behave differently, I even have it running on a serial driver just in-case I would need to treat it as a serial device. So theoretically I can have it behave as not a keyboard, but then I won't know how to treat the data or even get the input stream from.

Link to comment
Share on other sites

Link to post
Share on other sites

2 hours ago, BrownZeus said:

Its acting as a keyboard. Any barcode I scan will type out data if a text field is focused. The scanner can be reprogrammed to behave differently, I even have it running on a serial driver just in-case I would need to treat it as a serial device. So theoretically I can have it behave as not a keyboard, but then I won't know how to treat the data or even get the input stream from.

You should treat it as a serial device, because the data handling will be much easier. The problem with making it a keyboard device is that the app must be in focus. You can get away with having the app interrupt on key presses, but if the app goes out of focus, you lose those key presses. With it acting as a serial port, you can still get the data in something like an array (or a string in this case), you don't have to service every "event" because most of the time serial data is sent as one chunk of data, and it has the added benefit of working regardless if the app is in focus or not.

 

As for getting the input stream, it depends on the environment. In C# this is stupid easy since there's a serial port class. The others, I'm not sure, but I'm also certain it's not that hard to find something considering that serial ports are still widely used in programming (embedded devices for instance basically default to serial of some sort).

Link to comment
Share on other sites

Link to post
Share on other sites

8 hours ago, M.Yurizaki said:

You should treat it as a serial device, because the data handling will be much easier. The problem with making it a keyboard device is that the app must be in focus. You can get away with having the app interrupt on key presses, but if the app goes out of focus, you lose those key presses. With it acting as a serial port, you can still get the data in something like an array (or a string in this case), you don't have to service every "event" because most of the time serial data is sent as one chunk of data, and it has the added benefit of working regardless if the app is in focus or not.

 

As for getting the input stream, it depends on the environment. In C# this is stupid easy since there's a serial port class. The others, I'm not sure, but I'm also certain it's not that hard to find something considering that serial ports are still widely used in programming (embedded devices for instance basically default to serial of some sort).

Thanks, I'll do my research

Link to comment
Share on other sites

Link to post
Share on other sites

11 hours ago, M.Yurizaki said:

You should treat it as a serial device, because the data handling will be much easier. The problem with making it a keyboard device is that the app must be in focus. You can get away with having the app interrupt on key presses, but if the app goes out of focus, you lose those key presses. With it acting as a serial port, you can still get the data in something like an array (or a string in this case), you don't have to service every "event" because most of the time serial data is sent as one chunk of data, and it has the added benefit of working regardless if the app is in focus or not.

 

As for getting the input stream, it depends on the environment. In C# this is stupid easy since there's a serial port class. The others, I'm not sure, but I'm also certain it's not that hard to find something considering that serial ports are still widely used in programming (embedded devices for instance basically default to serial of some sort).

Forgot to mention I'm using Java.

 

So I prgrammed the scanner as a serial device and the Input looks fine in my console. I wrote the program to open the serial port, and pointed the port to an Input stream and its writing to my console by printing the input as a character stream. 

 

System.out.print((char)in.read());

 

And the data is coming in better than when I had the scanner as a keyboard and was writing the data in a document.

 

Each piece of information has its own line. Which is troubling me now.

 

Since I was casting the read method as chars I chose the ".print" method in java versus the ".prntln" method because the latter would have printed each character in its own line. The data SHOULD have printed all in one line, but each piece of data has its own line, precicsely where one piece of discernable data ends a new line begins, which shouldn't be happening. Its quite baffling.

 

I know my explanation isn't very clear so here is the best example I can give.

 

As a Keyboard the Scanner wrote like this:

 

DCB DCS[Last Name] DCT[First Name]

 

until all the data was read, with only 2 or 3 "enter" strokes from the scanner.

 

What I'm getting to my console now is:

 

DCB

DCS[Last Name]

DCT[First Name]

 

until all the data is read.

 

The console should look more like what it did in the word document, except no "enter" strokes.

 

Also when I have the program write to a txt file instead of the console, everything prints as one line like it should have in console.

Edited by BrownZeus
Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, BrownZeus said:

So I prgrammed the scanner as a serial device and the Input looks fine in my console. I wrote the program to open the serial port, and pointed the port to an Input stream and its writing to my console by printing the input as a character stream. 

 

System.out.print((char)in.read());

 

And the data is coming in better than when I had the scanner as a keyboard and was writing the data in a document.

 

Each piece of information has its own line. Which is troubling me now.

 

Since I was casting the read method as chars I chose the ".print" method in java versus the ".prntln" method because the latter would have printed each character in its own line. The data SHOULD have printed all in one line, but each piece of data has its own line, precicsely where one piece of discernable data ends a new line begins, which shouldn't be happening. Its quite baffling.

 

I know my explanation isn't very clear so here is the best example I can give.

 

As a Keyboard the Scanner wrote like this:

 

DCB DCS[Last Name] DCT[First Name]

 

until all the data was read, with only 2 or 3 "enter" strokes from the scanner.

 

What I'm getting to my console now is:

 

DCB

DCS[Last Name]

DCT[First Name]

 

until all the data is read.

 

The console should look more like what it did in the word document, except no "enter" strokes.

If I can figure out whats cause the new lines to occur I could parse the lines into an array which would make life extremely easy.

Link to comment
Share on other sites

Link to post
Share on other sites

If the scanner is sending a \n or \r (ASCII 0x0A or 0x0D), then it'll have new lines regardless of which print method you use. Though I guess that also depends on the OS (since Linux newlines just on \n and Windows on \r\n) or how the environment handles new lines (it may new line on just \n)

Link to comment
Share on other sites

Link to post
Share on other sites

3 minutes ago, M.Yurizaki said:

If the scanner is sending a \n or \r (ASCII 0x0A or 0x0D), then it'll have new lines regardless of which print method you use. Though I guess that also depends on the OS (since Linux newlines just on \n and Windows on \r\n) or how the environment handles new lines (it may new line on just \n)

would /n show if I wrote the stream to a text file?

 

Cause I did exactly that and in the txt file shows the data all as one line.

Link to comment
Share on other sites

Link to post
Share on other sites

7 minutes ago, BrownZeus said:

would /n show if I wrote the stream to a text file?

 

Cause I did exactly that and in the txt file shows the data all as one line.

\n does not show up as that. It's a special character. If you're not familiar with the new line (\n) or carriage return (\r) characters, they're holdovers from type writers. A new line technically means going down one line (advancing the paper one row). A carriage return means putting the cursor to the left (moving the paper to the right so the type head is on the left side). But basically they're supposed to be the thing that makes a new line in a text printout.

 

Anyway, these two characters are treated differently depending on the OS or application. Windows uses the sequence \r\n. If you do not have that sequence or only one of the characters, the text printout will not have new lines. In UNIX or UNIX-like OSes like Linux, they only use \n to print a new line.

 

So to put it simply, if the barcode scanner is spitting out \n as the new line (or new data field I would presume), it will be a single line if you opened the text file in say Notepad on Windows, but it will be multiple lines in GEdit on Linux. However, more advanced text editors are aware of this. Notepad++ will likely display the text file as multiple lines even on Windows.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×