0
我使用我的條碼掃描器,通過一個COM端口,下面的代碼模擬POS終端,並將產品名稱和價格打印到從MySQL數據庫中提取的屏幕上。問題是,當com端口打開並準備好讀取數據時,loop until inkey=chr(13)
將不起作用,例如,當我想退出「掃描模式」並獲得總金額時。如何通過點擊輸入退出通過COM端口讀取條形碼?
這是用FreeBasic編寫的,但我對如何解決這個問題的一般概念非常感興趣,而不是語言特定的解決方案。
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
我可以退出循環是把IF語句與特定的條形碼循環的唯一方法,通過讀循環退出,但這是最尷尬的解決方案。 – Gabe