[comp.unix.xenix] serial port

john@bby-bc.UUCP (john) (07/10/87)

I tried to hook up my mouse the other day to the second serial
port (modem is on first) and I could not get it to work.  An

open("/dev/tty1", O_RDONLY) just blocked and if I added NDELAY
it didn't block but all the subsequent reads returned 0 bytes.

I know the mouse is ok (I just boot msdos and it works fine).
The microport docs say tty0 & tty1 ignore the serial control
lines but I thought it might still be a problem.  My serial
card lets me force cts, dtr, and dcd true but this had no effect.

I stty'd the port to cs8 -parenb 1200 -ixoff -ixon raw
but this seemed to have no effect either.

I would really like to use the mouse for a particular application
so if anyone has any suggestions I would be quite receptive.

thanks in advance,
			john

...{watmath,seismo,uw-beaver}!ubc-vision!fornax!bby-bc!john

john@bby-bc.UUCP (john) (07/12/87)

In article <140@bby-bc.UUCP>, john@bby-bc.UUCP (john) writes:
> I tried to hook up my mouse the other day to the second serial
> port (modem is on first) and I could not get it to work.  An
> 
It nows works; thanks all.
john

 ...{watmath,seismo,uw-beaver}!ubc-vision!fornax!bby-bc!john
 

john@bby-bc.UUCP (john) (07/19/87)

A week or so ago I posted a request for help with connecting a mouse
on a Microport SysV system.  Several people sent mail asking how I
got it to work so I thought I would post the solution since it is
very short. Mice run at 1200 baud, no parity, 1 stop bit and one
packet of information is 5 bytes

 b dx1 dy1 dx2 dy2

where dx{n} and dy{n} are signed 8 bit numbers and b has the format

1 0 0 0 0 b1 b2 b3

and b{n} == 1 if the button is UP.

I don't claim the code below is great, it could easily be improved,
but it works.

john
-----

/* sinmple mouse routines */
#include	<fcntl.h>
#include	<stdio.h>
#include	<termio.h>

static int mfd;

MouseInit()

{
struct termio t;
int i;

mfd = open("/dev/tty1",O_RDONLY);
if (mfd < 1) fprintf(stderr," couldn't open mouse \n");

i=ioctl(mfd,TCGETA, &t);
if (i < 0 ) fprintf(stderr,"ioctl error\n");
t.c_iflag = t.c_iflag & ~(IXON|IXOFF|ISTRIP|INLCR|IGNCR|ICRNL|IUCLC|INPCK);
t.c_cflag = B1200 | CS8 | CLOCAL | CREAD ;
t.c_lflag = 0;

i=ioctl(mfd,TCSETA, &t);
if (i < 0 ) fprintf(stderr,"ioctl error\n");
}

/* wait for mouse to send something then return change in x, y and the
   status of the buttons with bn==1 if the button is down
*/
MouseRead(dx, dy, b1, b2, b3)

int	*dx, *dy, *b1, *b2, *b3;

{
unsigned char	b;
char		bs[4];
int	j;

for (b=0; (b&0370) != 0200 ; ) read(mfd, &b, 1);
/* get here with button byte */
for (j=0; j<4; j++) read(mfd,&(bs[j]),1); /* get coords */

*b3 =  (~b)  & 1;
*b2 =  (~(b>>1)) & 1;
*b1 =  (~(b>>2)) & 1;

*dx = (int ) bs[0];
*dy = (int ) bs[1];
*dx = *dx + (int ) bs[2];
*dy = *dy + (int ) bs[3];

}