I'm using my barcode scanner thru a COM port, with the below code, which simulates a POS terminal and prints the product name and its price to the screen pulled from a MySQL database. The problem is that while the com port is open, and ready to read data, the loop until inkey=chr(13)
won't work, when I want to quit "scan mode", and get the total amount due, for example.
This is written in FreeBasic, but I'm rather interested in the general concept as to how to solve this problem, not a language specific solution.
dim buffer as string*20 'reads a 20 character long string
do
if open com ("COM6:9600,N,,2" for input as #1) <> 0 then
print "Unable to open serial port. Press any key to quit application."
sleep
end
end if
get #1,,buffer
print buffer
close #1
loop