try to write a simple program to read barcode on win7 pc

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
avengine
Posts: 6
Joined: Tue Apr 29, 2014 3:15 pm

try to write a simple program to read barcode on win7 pc

Post by avengine » Tue Apr 29, 2014 3:21 pm

I want to start using livecode to write the simple program to read normal barcode using USB barcode reader and put them in a database for attendance application.
please give me some direction or sample how do I start something like this.
if there is something like this available, can let me know and I don't mind to learn and modify the code to fit my need.
thanks.

magice
Posts: 457
Joined: Wed Mar 18, 2009 12:57 am

Re: try to write a simple program to read barcode on win7 pc

Post by magice » Tue Apr 29, 2014 4:18 pm

Most barcode readers come with the software for reading. All you have to do, is have focus for the field in which you want the numbers to show and activate the scanner.

bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 937
Joined: Fri Aug 15, 2008 7:15 am

Re: try to write a simple program to read barcode on win7 pc

Post by bangkok » Tue Apr 29, 2014 4:19 pm

Easy.

First : set up your reader
-> start with...no special parameters

Second : barcode choice ?
Code 128 or 39 ?
-> start with a regular Code 39
It's the easiest.

Third : the principle
-> add prefix and suffix to your bacoded data :
For instance : *+MYDATA$*

(the "*" is the official delimiter for code 39)

Then in the script of a card with one field, something like this

Code: Select all

global gReadBC

on keyDown theKey
   if thekey is "+" then
      put empty into field "decodedData"
      put 2 into gReadBC
      exit keydown
   end if
   if gReadBC=2 then
      put theKey after field "decodedData"
   end if
   
   if thekey is "$" and gReadBC=2 then
      put 1 into lectureBC
      delete last char of field "decodedData"
      manageData
      exit to  top
   end if
end keyDown 

on manageData
---- this script will be executed when the reading of the barcode is finished
------ here you can write the data to your database etc.
end manageData
-scan the barcode
-data will be decoded as keyboard stroke, hence the message keyDown
-the script is looking for your special prefix and suffix

That's the easiest way, if you have the control over the data your print with barcodes.

Other ways are possible involving settings on the reader itself (with most of readers, you can set special suffix and/or prefix directly), when you can't modify the data.

viro
Posts: 52
Joined: Fri Jul 05, 2013 6:59 pm

Re: try to write a simple program to read barcode on win7 pc

Post by viro » Thu May 01, 2014 7:40 pm

Try this in card script:

Code: Select all

global tBarcode, tBarcodevergleich
-- this routine reads the barcode
-- one character at a time
--
on keyDown theKey
  if the hilite of btn "Pause" = false then
    put theKey after fld "Barcodes"
  else
    pass keyDown
  end if
end keyDown


-- this routine looks for the barcodes end of line character
-- in this tester, it just adds a linefeed
-- but in a real application, this is where
-- you would handle the barcode information
--

on rawKeyDown theKey
   global tSecs
   if the hilite of btn "Show raw data" = false then
      if theKey = 65293 and the hilite of btn "Pause"=false then
         -- 65293 is das enterZeichen vom Scanner--end of line char from scanner
         if tSecs +5 > the seconds then
            put empty into fld "Barcodes"
            exit to top
         end if
         if fld "Barcodes" is empty then exit to top
         checkBarcodes#check for double barcodes
         put the seconds into tSecs
         put empty into fld "Barcodes"
      else
         pass rawKeyDown
      end if
   else
      #ab hier werden rawkeys erfasst wenns häckchen steht--rawkey detection
      put theKey & cr after fld "Barcodes"
   end if
end rawKeyDown

on checkBarcodes
   repeat for each line tLine in fld "Barcodes"
      if tLine is among the lines of tBarcode then
         beep
         put empty into fld "Barcodes"
         set the visible of fld "lblFlash" to true
         set the uFlash of fld "lblFlash" to true
         set the uFlashRepeat of fld "lblFlash" to 10
         send "flash" to fld "lblFlash"
      else
         put fld "Barcodes"&cr after tBarcode
         set the uFlash of fld "lblFlash" to false
         set the visible of fld "lblFlash" to false
         Scan#Scan Barcode
      end if
   end repeat
end checkBarcodes
took it from sample stack and added double barcode detection...
the funniest thing about this particular signature is that by the time you realize it doesn't say anything it's too late to stop reading it

avengine
Posts: 6
Joined: Tue Apr 29, 2014 3:15 pm

Re: try to write a simple program to read barcode on win7 pc

Post by avengine » Thu May 01, 2014 9:31 pm

Sorry that I am really the beginning in this program, how to put the sample script that you mention into the card. You can send me the link for me to learn the process too.

My whole idea is to use this program for the church fellowship to take the attendance of the children that come to the class, at what time they come in, and also read the barcode again when they are checking out, put all this into a report or export to excel for anyone to use after ward.
if possible, I also want to put this into a simple database, as you know the student might move from 1 class to another.
thanks.

viro
Posts: 52
Joined: Fri Jul 05, 2013 6:59 pm

Re: try to write a simple program to read barcode on win7 pc

Post by viro » Fri May 02, 2014 1:31 pm

Hey
I think this link might sort out some problems for you:
http://livecodesupersite.com/tutorials.html
There you can find How to use database, working with fields and Export Text to CSV.

Good luck!
the funniest thing about this particular signature is that by the time you realize it doesn't say anything it's too late to stop reading it

Post Reply