Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to Code for a Barcode Scanner

Status
Not open for further replies.

AbidingDude

Programmer
Oct 7, 2012
74
US
A while back, my brother found some abandoned items at his work place. One of the things he found was a barcode scanner. With me being more into computers and electronics than him, he figured I might have more use for it.

Apparently it's a SerialIO LaserChamp. It hooks up to a serial port, and connects to the scanner by a tip-ring-sleeve connector (tip to pin #2, ring to pin#3, and sleeve t pin #5).

I downloaded the developer guide PDF from SerialIO's website. I threw together some quick code using my old Borland library functions from bios.h, but I can't get much useful information out of the scanner.

The code was copied from an example file. If I take a battery out of the scanner and put it back in, the scanner initializes with legible text giving me the scanner ID, firmware version, etc. But everything I scan givers me the same output. It's always:
☻210720600210630001
That's all I can get from it. The guide said to send it any character to wake it up, then send it the character 'W' to invoke the "Who" command (so I can see it's config info). But it doesn't seem to respond to any input.

Here's what I compiled:

[pre]#include <bios.h>
#include <conio.h>
#include <dos.h>

#define DTR 0x01 // Data Terminal Ready
#define RTS 0x02 // Ready To Send
#define COM1PORT 0x0000 // Pointer to Location of COM1 port
#define COM2PORT 0x0002 // Pointer to Location of COM2 port
#define COM1 0
#define COM2 1
#define DATA_READY 0x100
#define FALSE 0
#define TRUE !FALSE

#define SETTINGS (_COM_4800 | _COM_NOPARITY | _COM_CHR8 | _COM_STOP1)

int main( void )
{
int in,out,status,DONE=FALSE;
int far *RS232_Addr;

/* Determine port location of COM1.
0x40:0x00 = COM1 I/O port address
0x40:0x02 = COM2 I/O port address
*/
RS232_Addr = MK_FP( 0x0040, COM1PORT );
if( !*RS232_Addr )
return -1;

_bios_serialcom( _COM_INIT, COM1, SETTINGS );
cprintf( "... BIOSCOM [ESC] to exit ...\n\r" );

while( !DONE ){
/*Reset DTR and RTS to prepare for send/receive of next character.*/
outportb( *RS232_Addr + 4, DTR | RTS );

/* Get status of com port.*/
status = _bios_serialcom( _COM_STATUS, COM1, 0 );

if( status & DATA_READY ){
/*There's a character on the port. Get it and echo.*/
if((out=_bios_serialcom(_COM_RECEIVE, COM1, 0)&0x7F) != 0)
putch( out );
}

if( kbhit() )
/* Key has been struck. Get it and send to port.*/
if( (in = getch()) == '\x1B' )
/* User pressed ESCAPE. Don't send to port.*/
DONE = TRUE;
else{
/* Send character to com port.*/
_bios_serialcom( _COM_SEND, COM1, in );
}
}

return 0;
}[/pre]

I've actually never coded anything for serial ports before, nor barcode scanners. I'd love to hear any insight on this!
 
What OS are you running on? The Borland code you've shown will only work in DOS or Win95/98/ME. It won't work on any of the NT family.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top