看板 Perl 關於我們 聯絡資訊
我最後是用 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 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 1.34.112.98 ※ 文章網址: https://www.ptt.cc/bbs/Perl/M.1528808276.A.B8A.html
dk1120: A1234 => [Barcode SCANNRT] => [perl] => binary => ??? 06/12 21:01