Technical Information

Application Development Manual | Reading bar codes, writing them to data files, and sending files

Function

Read bar codes and write them to a data file (BDATA.DAT).
Pressing the M1 key sends the data file (BDATA.DAT) to the host and deletes that file.
Pressing the M2 key ends processing.

Sample Program

const BarFile = 1
const DatFile = 2
const ComFile = 3
const ProtBHT = 0           'BHT protocol
const ProtBIr = 2           'BHT-Ir protocol
const ProtYmd = 3           'Ymodem protocol
private datfname$
datfname$ = "bdata.dat"
'+---------------------------------------------------------------------------+
'|                                                                           |
'|  Function:   Wait for reading bar code                                    |
'|                f.no%      file number of bar code device file         |
'|                    bar$       read code                                   |
'|                    keylist$   list of key to end function                 |
'|               bar code data                                          |
'|                                                                           |
'|  Description:                                                             |
'|    When a bar code is read, returns the bar code data.                    |
'|    When specified key is pressed, returns the key data.                   |
'|                                                                           |
'+---------------------------------------------------------------------------+
function inpbar$(f.no%, bar$, keylist$)
private wk$
open "BAR:" as #f.no% code bar$
while 1
wait 0,&h03
if loc(#f.no%) then
beep
input #f.no%,wk$
inpbar$ = wk$
close #f.no%
exit function
else
wk$ = inkey$
if instr(1,keylist$,wk$) > 0 then
inpbar$ = wk$
close #f.no%
exit function
endif
endif
wend
end function
'+---------------------------------------------------------------------------+
'|                                                                           |
'|  Function:   Write data to file                                           |
'|                f.no%      file number of data file                    |
'|                    data$      write data                                  |
'|               None                                                   |
'|                                                                           |
'|  Description:                                                             |
'|    Write specified data to the data file.                                 |
'|                                                                           |
'+---------------------------------------------------------------------------+
sub putfile%(f.no%, data$)
private fdata$
open datfname$ as #f.no%
field  #f.no%,13 as fdata$
fdata$ = data$
put #f.no%
close #f.no%
end sub
'+---------------------------------------------------------------------------+
'|                                                                           |
'|  Function:   Send a data file                                             |
'|                f.no%      file number of communications device file   |
'|                    para$      communications parameter                    |
'|                    prot%      communications protocol                     |
'|                                0:BHT protocol                             |
'|                                1:BHT-Ir protocol                          |
'|                                2:Ymodem protocol                          |
'|                    flname$    file name                                   |
'|               returns 0 if it is successful                          |
'|                    returns error code if it fails                         |
'|                                                                           |
'|  Description:                                                             |
'|    Send the data file.                                                    |
'|                                                                           |
'+---------------------------------------------------------------------------+
function sendfile%(f.no%, para$, prot%, flname$)
out &h6060,prot%                'communications protocol
open para$ as #f.no%
on error goto err.xf
xfile flname$,"sp"              'send data file
on error goto 0
close #f.no%
sendfile% = 0
exit function
err.xf:
sendfile% = err
resume err.xf1
err.xf1:
close #f.no%
on error goto 0
end function
'===============================================================================
'   Main
'===============================================================================
private ibar$
private tmp%
key 30,"m"                                  'define M1 key
key 31,"n"                                  'define M2 key
while 1
locate 1,1 : print "Read bar code!";
locate 1,4 : print "M1:Transmit   ";
locate 1,5 : print "M2:End        ";
ibar$ = inpbar$(BarFile,"A:A","m,n")    'call function
'wait for reading bar code
'or M1 or M2 key is pressed
if len(ibar$) > 1 then
locate 1,2 : print ibar$
putfile%(Datfile,ibar$)
else
select ibar$
case "m"                            'when the M1 key is pressed
cls
locate 1,1: print "Transmitting...";
tmp% = sendfile%(ComFile, "com:115200,n,8,1", ProtBIr, datfname$)
'send the data file
if tmp% = 0 then
beep 10
locate 1,2: print "Completed";
kill datfname$                  'delete the data file
else
beep ,,3
locate 1,2 : print "Err";hex$(tmp%);"h"
endif
timea = 10 : wait 0,&h10
cls
case "n"                            'when the M1 key is pressed
end                                   'end
end select
endif
wend

Contact us

QBdirect