我将尝试从条形码扫描仪捕获数据。条形码格式为cade 93。
CODE 93 SYMBOLOGY:http://www.barcodeisland.com/code93.phtml
我成功通过perl程序从条形码扫描仪捕获日期,但我不知道 了解如何将二进制转换为字符串或ascii?
我的测试条形码是' TEST93' 。使用CODE 93进行编码 101011110 110100110 110010010 110101100 110100110 100001010 101000010 101011110
我得到了hexdump:
0x0000 : 02 00 17 00 00 00 00 00 00 00 00 00 00 00 00 00 : ................
0x0000 : 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 : ................
0x0000 : 02 00 08 00 00 00 00 00 00 00 00 00 00 00 00 00 : ................
0x0000 : 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 : ................
0x0000 : 02 00 16 00 00 00 00 00 00 00 00 00 00 00 00 00 : ................
0x0000 : 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 : ................
0x0000 : 02 00 17 00 00 00 00 00 00 00 00 00 00 00 00 00 : ................
0x0000 : 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 : ................
0x0000 : 00 00 26 00 00 00 00 00 00 00 00 00 00 00 00 00 : ..&.............
0x0000 : 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 : ................
0x0000 : 00 00 20 00 00 00 00 00 00 00 00 00 00 00 00 00 : .. .............
0x0000 : 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 : ................
0x0000 : 00 00 28 00 00 00 00 00 00 00 00 00 00 00 00 00 : ..(.............
0x0000 : 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 : ................
代码93编码示例
The START character (*): 101011110.
The digit "T": enocded as 110100110.
The digit "E": enocded as 110010010.
The digit "S": enocded as 110101100.
The digit "T": enocded as 110100110.
The digit "9": enocded as 100001010.
The digit "3": enocded as 101000010.
The STOP character (*): 101011110.
$char2bin{'T'} = '110100110'
$value2char{'29'} = 'T'
I recieve the barcode scanner binary and get hexdump :
0x0000 : 02 00 17 00 00 00 00 00 00 00 00 00 00 00 00 00 : ................
0x0000 : 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 : ................
如何将二进制转换为字符串?
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;
my %char2bin=(
'T' => '110100110',
'E' => '110010010',
'S' => '110101100',
'9' => '100001010',
'3' => '101000010',
'*' => '101011110', # start/stop
);
my %value2char=(
'29' => 'T',
'14' => 'E',
'28' => 'S',
'9' => '9',
'3' => '3',
'-' => '*', # start/stop
);
while(defined(my $in = $dev->read_data($buf, $len))){
if ($in == 0) {
next;
}
print hexdump(
data => $buf, # what to dump
suppress_warnings => false,
space_as_space=> true,
);
}