Perl code to generate a Telepen barcode by Markus Kuhn
Code:
#!/usr/bin/perl
# Markus.Kuhn@cl.cam.ac.uk, 2002-11-22
# Encode 7-bit ASCII string into Telepen barcode
# http://www.telepen-barcode.co.uk/barcode_symbol.asp
# Output: string in which '.' and 'B' represent equally wide white and
# black vertical strokes.
sub telepen
{
my ($text) = @_;
my $bits;
my $barcode;
my $checksum = 0;
# Append checksum byte to $text
for ($i = 0; $i < length($text); $i++) {
$checksum += ord(substr($text, $i, 1)) & 0x7f;
}
$text .= chr(~($checksum % 127) & 0x7f);
# Convert $text to LSB-first bit sequence with even parity
while (length($text) > 0) {
my $char = ord($text);
my $ones = 0;
$text = substr($text, 1);
$checksum += $char;
for ($i = 0; $i < 7; $i++) {
$ones += ($char >> $i) & 1;
$bits .= (($char >> $i) & 1) ? '1' : '0';
}
$bits .= ($ones & 1) ? '1' : '0';
};
# Add start and stop codes
$bits = "11111010${bits}01011111";
# Now apply Telepen encoding state machine
my $state = 0;
while (length($bits) > 0) {
if ($bits =~ /^010/ && $state == 0) {
$barcode .= 'BBB...';
$bits = $';
} elsif ($bits =~ /^00/ && $state == 0) {
$barcode .= 'BBB.';
$bits = $';
} elsif ($bits =~ /^01/ && $state == 0) {
$barcode .= 'B...';
$bits = $';
$state = 1;
} elsif ($bits =~ /^10/ && $state == 1) {
$barcode .= 'B...';
$bits = $';
$state = 0;
} elsif ($bits =~ /^1/) {
$barcode .= 'B.';
$bits = $';
} else {
die("Oops, something impossible happend!\n$bits\n");
}
}
return $barcode;
}
See also:
| file: /Techref/barcode/telepen.htm, 2KB, , updated: 2009/1/19 14:10, local time: 2012/5/21 21:07,
38.107.179.232:LOG IN |
| ©2012 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions? <A HREF="http://www.ecomorder.com/techref/barcode/telepen.htm"> Barcode, telpen</A> |
| Did you find what you needed? |
|
Ashley Roll has put together a really nice little unit here. Leave off the MAX232 and keep these handy for the few times you need true RS232! |
Robotics nuts!Check out http://users.frii.com/dlc/robotics/projects/botproj.htm from Dennis Clark. This guy ROCKS! He has made (and sells but also releases code, docs, etc...) for a number of cool little robotic modules including whiskers, IR proximity detect and remote control, Sonar proximity detect, PWM, Servo, compass. Most of these use the little PIC 12C508 controller which costs basically nothing and is soooo tiny.The 4 servos, 2400 baud serial servo controller is a wonder of magic and he sells the programmed chip for $8. Wow! |
.