Barcode scanner instructions ============================ A while back I managed to get hold of a second hand barcode scanner which had previosly been used in a stationery store. It appears to be the equivalent to Maplin Electronics part number KV75S. It came with an unlabelled 5 pin DIN plug which would have connected to the host terminal. Assuming you have one of these scanner in front of you (from Maplin, a closed down shop, or 2nd hand from Micromart) then take the lid off. Some of the screws may be concealed by rubber grommets or labels so don't force the top off. Inside you'll see a massively integrated chip at the heart a handful of tiny electrolytic capacitors and what looks like a blank calculator display pointing up to a mirror. Don't get grubby fingerprints on this part - that blank grey rectangle is the CCD (charge-coupled-device) which converts light into charges. Where the DIN plug wire terminates there should be just 3 wires used. They may be colour coded in black/red/yellow (for example) for 0v/5v/data but don't rely on this! Look around at all the chips and the PCB tracks. You'll find that one of the wires goes to nearly all the parts so this is probably 0v. Another dead giveaway is that tracing it immediately it enters the board it should go to the '-' terminal of a supply smoothing capacitor and one of the remaining 2 wires will go to the '+' side. So that's the supply sorted. To make sure, attach it to a 5v supply QUICKLY and the row of red or green scanning LEDs will light. You wont (generally) damage anything if you did get it wrong if you did it quick enough. The last of the 3 leads is data out. If you have an oscilloscope that can be triggering in 'once only' mode then when you scan a valid barcode a waveform like that in the diagram will occur. It consists of a wide sync pulse (data line drops from 5v to 0v) then a stream of data which (using your artistic judgement) exactly aligns with the black and white stripes on the barcode. PARTS... Page 435 of the User Guide shows the pinouts of the user port, in addition you will need to have the following parts: 1x CCD barcode scanner (eg.KV75S from Maplin Electronics) 1x 20 pin female IDC plug In addition it may be necessary to have some strong glue DETAIL... *Monitor stock levels in a store of some kind (eg.Scouts/Library) *Hardware recognises all known barcode formats automatically *Hardware automatically rights a code if it was scanned up-side-down *The hardware generates no clock pulse, so data must be read in by polling the port and not by clocking in under interrupts. BUILD... 1.Cut off the useless DIN plug as that wont fit in the user port 2.Attach the line discovered to be 5v to the 5v line on the user port 3.Likewise for 0v 4.Ensure that the data is clocked in on PB0 5.It may be necessary to solder these into place carefully as the cable is not true IDC cable and probably wont splice properly onto the connectors 6.As the cable is round and not ribbon cable, apply some glue to the cable so that tugs on it wont cause stress to the joints made in 3, 4, 5 above. SOFTWARE... The program CODE13 should be available to you, which demonstrates how to read a code 13 type barcode with the hardware. If there is a particular coding method you wish to be able to read then the end half of the program will need to be altered to suit. To use the software CHAIN"CODE13" or the equivalent command. The message 'Waiting for scan...' appears as a machine code loop polls the user port until the sync pulse is found. It will then (as fast as it can) build a table of the number of reads to the user port that occured before the data changed, and hence these are directly proportional to the width of the pulse. The machine code returns to the caller when the same value is read from the port 255 times. It is then assumed that no more transmissions follow. A value is returned in X which is the length of the table created. Since data always starts at 1 so a typical table might consist of Logic value on PB0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 etc... Number of loops 20 4F 20 20 65 20 20 4F 4F 20 63 23 22 4D 20 etc... As you can see the timing coming from the scanner is not crisp and clean so some filtering is needed. For demonstration purposes only code 13 barcodes are handled and rather crudely too! The following is applied: Find average unit length of bar by averaging the end 3 bits and start 3 bits (start/stop bars) Go through each table entry assigning a normalised length of between 1 and 4 long as the maximum code 13 repeat length is 4 consecutive digits. So for example above Logic value on PB0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 etc... Number of loops 20 4F 20 20 65 20 20 4F 4F 87 63 23 22 4D 20 etc... Normalised value 1 2 1 1 3 1 1 2 2 4 3 1 1 2 1 etc... Which means that the scanned code must have been 10010111010011000011101001... This is then checked for start/stop/guard bits and correct length and then decoded. You'll need to tell the computer what the first number of the barcode is (this is norally printed underneath!) which is the combination number. When and ONLY when this number is correct will all the digits decode properly. It is left to the reader to add an extra loop from 0 to 9 to try by guessing to find what that digit is, and hence get the whole barcode without needing end user input. Note that scans wont always be accepted the first time, due to an incorrect length code 13 barcode. Keep trying, it's because the filtering is so crude. Try using a standard deviation instead of averaging the start/stop bit lengths. Or adjust the size of the window you look through. CODE 13 BARCODES... Using the EAN (European article number) encoding the barcode consists of 1.Combination number. This is the first digit, in our example is 5. It refers to how the next 6 digits are encrypted as follows COMB # PATTERN TO FOLLOW 0 A A A A A A 1 A A B A B B 2 A A B B A B 3 A A B B B A 4 A B A A B B 5 A B B A A B 6 A B B B A A 7 A B A B A B 8 A B A B B A 9 A B B A B A 2.The start bit. Two parallel bars 3.The following 6. Encrypted as above, then (taking '1' as black and '0' as white) are converted onto 7 bit binary digits. REPRESENTS... SET A SET B SET C 0 0001101 0100111 1110010 1 0011001 0110011 1100110 2 0010011 0011011 1101100 3 0111101 0100001 1000010 4 0100011 0011101 1011100 Notice that not C = A and that 5 0110001 0111001 1001110 reverse of C = B 6 0101111 0000101 1010000 7 0111011 0010001 1000100 8 0110111 0001001 1001000 9 0001011 0010111 1110100 4.The guard bit. Two parallel bars 5.The following 6. Encrypted in set C always, then (taking '1' as black and white as '0') are converted onto 7 bit binary digits. 6.The end bit. Two parallel bars 7.The checksum. For the barcode 123456782093C where C is the check bit to be determined by the following calculation 1.Add up the alternate numbers starting at the 12th: [3+0+8+6+4+2=23] 2.Times (1) by 3 => 69 3.Add up the alternate numbers starting at the 11th: [9+2+7+5+3+1=27] 4.Add parts (2) and (3) => 96 5.Find the smallest number needed to make part (4) evenly divisible by ten [100-96=4 so C=4 as 100x10 is even and 4 < 14 which would be the next] FROM... Robert Sprowson. Happy soldering!