Is it possible to read data directly from a usb input device

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
D_S
Junior Coder
Posts: 32
Joined: Sun Apr 24, 2005 6:43 pm

Is it possible to read data directly from a usb input device

Post by D_S » Wed May 31, 2006 1:21 pm

I'm trying to collect data from a usb barcode scanner that will run continuously though the data will be intermittent. I wrote a simple script that reads input then time stamps the data to file and then repeats itself. Easy enough.

The issue is if I lose focus from the script then the data goes to the bit bucket. Had thought about writing a script to constantly force focus to the input screen but thought that might not be best. Is there a way to receive this input directly from the usb port and write directly to the file bypassing standard input? To be reliable I can’t miss data.


label>start

Day>the_day
Month>the_month
Year>the_year
Let>NOW=%the_year%%the_month%%the_day%

Input>clock,Clock Number

TimeStamp>c:\clock.txt,%clock% %NOW%

goto>start


***sorry, when I initially posted I pasted the macro code twice....will look closer before I post.
Last edited by D_S on Wed May 31, 2006 5:22 pm, edited 2 times in total.

User avatar
Marcus Tettmar
Site Admin
Posts: 7389
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Wed May 31, 2006 4:00 pm

Probably not, but it's a bit hard to answer without knowing more about the device. Do you have information about the protocol it uses? Maybe it provides a virtual serial interface?
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
JRL
Automation Wizard
Posts: 3517
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Wed May 31, 2006 4:19 pm

Just a couple of quick observations.

You can't have two labels with the same name, you have two start labels.

The line "goto>star" needs to have a label to goto, I see no Label>star

Hope this helps,
Dick

D_S
Junior Coder
Posts: 32
Joined: Sun Apr 24, 2005 6:43 pm

Post by D_S » Wed May 31, 2006 5:38 pm

I'm using a symbol ls 9208 projection scanner. It is connected directly to a usb port and is detected as a human interface device (keyboard emulation). It will be scanning company id badges that contain a 5 digit code.

I can scan them now with the script I've written but if I lose focus I lose data. Want to find a way to either collect the data directly from the usb device bypassing the screen input or find a way to bullet proof screen focus.

thanks in advance

User avatar
JRL
Automation Wizard
Posts: 3517
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Wed May 31, 2006 6:36 pm

D_S,

Are the screen badge barcodes characters all numbers?

Does the barcode start and end with a character such as an asterisk (*)?

In other words when you scan a badge does the scanner actually type something like *00289* ?

Or do you only see 00289 ?

Are the badges always going to be 5 characters?

I think this can be done with OnEvent>. I have a script idea I just need to have a little more direction.

Let me know,
Dick

D_S
Junior Coder
Posts: 32
Joined: Sun Apr 24, 2005 6:43 pm

Post by D_S » Wed May 31, 2006 7:15 pm

The scan will always be 5 numbers and scan without an asterisk.

JRL wrote:D_S,

Are the screen badge barcodes characters all numbers?

Does the barcode start and end with a character such as an asterisk (*)?

In other words when you scan a badge does the scanner actually type something like *00289* ?

Or do you only see 00289 ?

Are the badges always going to be 5 characters?

I think this can be done with OnEvent>. I have a script idea I just need to have a little more direction.

Let me know,
Dick

User avatar
JRL
Automation Wizard
Posts: 3517
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Wed May 31, 2006 7:37 pm

Try something like this:

Code: Select all

OnEvent>KEY_DOWN,0,0,KeyPress0
OnEvent>KEY_DOWN,1,0,KeyPress1
OnEvent>KEY_DOWN,2,0,KeyPress2
OnEvent>KEY_DOWN,3,0,KeyPress3
OnEvent>KEY_DOWN,4,0,KeyPress4
OnEvent>KEY_DOWN,5,0,KeyPress5
OnEvent>KEY_DOWN,6,0,KeyPress6
OnEvent>KEY_DOWN,7,0,KeyPress7
OnEvent>KEY_DOWN,8,0,KeyPress8
OnEvent>KEY_DOWN,9,0,KeyPress9

Let>text=
Let>list=

Label>start
Length>%text%,len
  If>%len%>4
    GoSub>Process
	Let>text=
  EndIf
Wait>0.001
Goto>start

SRT>Process
Concat>list,%text%%CRLF%
MDL>%list%
//or what ever else might need to be done
END>Process

SRT>KeyPress0
  Concat>text,0
END>KeyPress0

SRT>KeyPress1
  Concat>text,1
END>KeyPress1

SRT>KeyPress2
  Concat>text.2
END>KeyPress2

SRT>KeyPress3
  Concat>text,3
END>KeyPress3

SRT>KeyPress4
  Concat>text,4
END>KeyPress4

SRT>KeyPress5
  Concat>text,5
END>KeyPress5

SRT>KeyPress6
  Concat>text,6
END>KeyPress6

SRT>KeyPress7
  Concat>text,7
END>KeyPress7

SRT>KeyPress8
  Concat>text,8
END>KeyPress8

SRT>KeyPress9
  Concat>text,9
END>KeyPress9

D_S
Junior Coder
Posts: 32
Joined: Sun Apr 24, 2005 6:43 pm

Post by D_S » Wed May 31, 2006 8:51 pm

Sorry, am not understanding what this will do for me. I copied and pasted this into a temp script and ran it. Any numeric key pressed I get popup with multiples of the key pressed..any other key no action.

User avatar
JRL
Automation Wizard
Posts: 3517
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Wed May 31, 2006 10:11 pm

It was an attempt to capture key strokes. I knew it would not work with a keyboard because of the keyboard scan rate but I thought it would work with a scanner. Rather than have you worry about it I set up a scanner on my PC and found that the scanner entered multiples of each number just like the keyboard. So the previous post will not work for you.

Another idea is to have a non-modal dialog that is perpetually on top. This will collect your data then write it to a file on exit of the program. Try to make some other window the focused window while this is running, I don't think you can. Be sure to remark or remove the MDL> line if you want this to run without user intervention.

Hope this is easier to understand and works better for you,
Dick

Code: Select all

Dialog>Dialog1
   Caption=Enter Badge Number
   Width=168
   Height=162
   Top=180
   Left=371
   Close=0
   Label=Badge Number,40,24
   Edit=msEdit1,32,40,97,
   Button=Close,40,88,75,25,2
//remove or remark the next line if the scanner sends a return
   Default=Close
EndDialog>Dialog1

Let>list=

Show>dialog1
Label>start
GetDialogAction>Dialog1,r1
If>r1=2,finish
Wait>0.001
Length>%Dialog1.msEdit1%,len
  If>%len%>4
    Concat>list,%Dialog1.msEdit1%%CRLF%
	//next line to be removed when not testing
	MDL>Current badge number = %Dialog1.msEdit1%%CRLF%Number list:%CRLF%%list%
	Let>Dialog1.msEdit1=
	ResetDialogAction>Dialog1
  EndIf
WindowAction>0,Enter Badge Number
Goto>start
Label>finish
  WriteLn>c:\~badgelist~.txt,wresult,%list%
Last edited by JRL on Thu Jun 01, 2006 4:07 am, edited 1 time in total.

D_S
Junior Coder
Posts: 32
Joined: Sun Apr 24, 2005 6:43 pm

Post by D_S » Wed May 31, 2006 11:50 pm

Thanks for the input, my original post had a non-modal dialog input that would capture the input from the scanner and immediately write it to file then return to the beginning of the script...continuous loop. This does a good job of capturing the scan but that's not my issue.

I intend for this program to run on a pc with little or nothing else on it. But in spite of that my concern is that if any other process writes to the screen and steals the focus from my program all scans are lost until the focus is returned to my program. So, my thought was can the usb input be diverted/captured directly to file.....looks to be over my head.

My other alternative was to write a small program to run in memory that will constantly...every couple of seconds set the focus to my program. Guess since the pc that will be in use will be dedicated to only this data collection purpose I can persue that approach.

The scanner, by changing to a different cable and some minor reprogramming could be an rs232 device....but that opens a different approach to data collection that am unsure if macro scheduler will accomadate.

thanks for the help will test with a program to continually set focus and see how it goes.

Wrote the following and compiled and this seems to ease my concerns. As I open other windows that steal focus from my program this puts it back in place on top of everything. Maybe a little coarse but seems to get the job done.

Label>START
SetFocus>Clock*
wait>.3
goto>START

User avatar
JRL
Automation Wizard
Posts: 3517
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Thu Jun 01, 2006 1:29 am

If you re-read my last post you'll see that I understand the focus loss concern. The script I posted cannot be upstaged except by user intervention and that could be fixed also.

FYI the part that keeps the dialog on top is the WindowAction>0,Windowname line embedded in the continuously running getdialogaction> loop.

Sorry I posted the first script. I should know better than to try to be helpful without testing first. Sometimes does more harm than good.

Good Luck,
Dick

User avatar
JRL
Automation Wizard
Posts: 3517
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Thu Jun 01, 2006 4:02 am

Another observation. If your original post was working except that it did not keep focus, then your scanner is also sending a "return" after sending the text. If this is the case, the last script that I posted will need to be modified to account for that "return" being sent at the end.

Later,
Dick

D_S
Junior Coder
Posts: 32
Joined: Sun Apr 24, 2005 6:43 pm

Post by D_S » Thu Jun 01, 2006 4:55 am

Modified your code so that it automatically writes to file each time after the 5th number is entered. You're right about the enter from the scanner but this can be turned off in the scanner...I turned it on to run the code I had written. Thanks for the help.

Dialog>Dialog1
Caption=Enter Badge Number
Width=168
Height=162
Top=180
Left=371
Close=0
Label=Badge Number,40,24
Edit=msEdit1,32,40,97,
Button=Close,40,88,75,25,2
Default=Close
EndDialog>Dialog1



Show>dialog1
Label>start

Day>the_day
Month>the_month
Year>the_year
Let>NOW=%the_year%%the_month%%the_day%

GetDialogAction>Dialog1,r1
If>r1=2,finish
Wait>0.001
Length>%Dialog1.msEdit1%,len
If>%len%>4
TimeStamp>c:\~badgelist~.txt,%Dialog1.msEdit1% %NOW%

Let>Dialog1.msEdit1=
ResetDialogAction>Dialog1
EndIf
WindowAction>0,Enter Badge Number
Goto>start
Label>finish

User avatar
Marcus Tettmar
Site Admin
Posts: 7389
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Thu Jun 01, 2006 6:35 am

Dick,

Many thanks for working on an elegant solution for D_S's requirements and for taking the time to test with a scanner attached. I am sure it will be much appreciated.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

D_S
Junior Coder
Posts: 32
Joined: Sun Apr 24, 2005 6:43 pm

Post by D_S » Thu Jun 01, 2006 4:10 pm

Have been working with macro scheduler on and off for about 2 years and know that whenever I'm stumped the board is the place to go. I really appreciate the help I receive from all !!!

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts