[Sussex] cash drawer programming

Jim Nicholson newline.systems at btclick.com
Fri Aug 13 23:13:28 UTC 2004


Dominic / all

That document describes how to configure the serial ports on your Linux box,
once you've done that you need to talk to the serial port from your program.

How you control the cash drawer depends on whether it has an RS232 interface
or not.  The following examples are in C and are to demonstrate the
principles - I haven't compiled or tested them.

if it HAS RS232:

void open_drawer() {
	char[1] dummy={'A'}; /* something to write to the port, the value
doesn't matter */

	/* write one byte to the serial port to open the cash drawer */
	int fd = open("/dev/ttyS0", O_WRONLY);
	write(fd, dummy, 1);
	close(fd);
}

if it HAS SOLENOID control, have a look at
http://www.easysw.com/~mike/serial/serial.html#5_1
basically you wire up a circuit so that driving say the DTR line will drive
the solenoid to open the drawer

void open_drawer() {
	int status;
	int fd = open("/dev/ttyS0", O_RDWR);
	ioctl(fd, TIOCMGET, &status);	/* get the current state of the
modem control lines */
	status &= ~TIOCM_DTR;	/* turn off DTR */
	ioctl(fd, TIOCMSET, &status); /* set the new modem line state */
      /* wait for however long you need to wait */
	status |= TIOCM_DTR;	/* turn on DTR */
	ioctl(fd, TIOCMSET, &status); /* set the new modem line state */
	close(fd);
}

If you wire up the drawer-open sense contacts to drive say the CTS line, you
could test the relevant bit in status to see whether the drawer is open.

That's it near enough.

Jim

-----Original Message-----
From: sussex-bounces at mailman.lug.org.uk
[mailto:sussex-bounces at mailman.lug.org.uk] On Behalf Of Dominic Clay
Sent: 13 August 2004 11:47
To: LUG email list for the Sussex Counties
Subject: Re: [Sussex] cash drawer programming

For anyone else who might be interested... this howto seems to be very
thorough and readable :)

http://www.ibiblio.org/mdw/HOWTO/Serial-HOWTO.html

Dominic

[snip]






More information about the Sussex mailing list