Re: [問題] 如何讀取條碼機所傳來的數據?

作者: dk1120 (Jason7123)   2018-06-12 20:57:52
我最後是用 Device::HID 來讀取條碼掃描機的輸入。
程式如下,接下來是程式收到數入的二進位碼要如何還原?
barcode 的格式是使用 code 39
條碼定義:
http://www.barcodeisland.com/code93.phtml
use Device::HID;
use Data::Hexdumper qw(hexdump);
my $dev = Device::HID->new(vendor => 0x04b4, product => 0x0100) or die "No such device !\n";
$dev->timeout = 0.1; # seconds (=100 ms)
my $buf;
my $len=128;
my $i=0;
while(defined(my $in = $dev->read_data($buf, $len))){
if ($in == 0) {
next;
}
$i++;
my $hex = unpack( 'H*', $buf );
print sprintf("%02d",$i)." => $hex\n";
}
輸出:
01 => 0200040000000000
02 => 0000000000000000
03 => 00001e0000000000
04 => 0000000000000000
05 => 00001f0000000000
06 => 0000000000000000
07 => 0000200000000000
08 => 0000000000000000
09 => 0000210000000000
10 => 0000000000000000
11 => 0000280000000000
12 => 0000000000000000
作者: dk1120 (Jason7123)   2018-06-12 21:01:00
A1234 => [Barcode SCANNRT] => [perl] => binary => ???

Links booklink

Contact Us: admin [ a t ] ucptt.com