Device-LaCrosse-WS23xx

 view release on metacpan or  search on metacpan

WS23xx.xs  view on Meta::CPAN

	    croak("malloc failed");
	strcpy(trace_path,path);

int
_ws_open(path)
	char *     path
    INIT:
	int fh;
	struct termios adtio;
	int portstatus, fdflags;
    PPCODE:
	//Setup serial port
	if ((fh = open(path, O_RDWR | O_NONBLOCK | O_SYNC)) < 0)
	{
//	    fprintf(stderr,"\nUnable to open serial device %s\n", path);
	    XSRETURN_UNDEF;
	}

	if ( flock(fh, LOCK_EX|LOCK_NB) < 0 ) {
	    fprintf(stderr,"Serial device is locked by other program\n");
	    close(fh);

WS23xx.xs  view on Meta::CPAN

	flock(fh, LOCK_UN);
	RETVAL = close(fh);

void
_ws_read(fh, addr, nybble_count)
	int fh
	unsigned short addr
	unsigned char nybble_count
    PREINIT:
	uchar buf[40];
    PPCODE:
#if	DEBUG
	printf("got here: fh=%d addr=%04X nybbles=%d\n",fh,addr,nybble_count);
#endif
	if (read_safe(fh, addr, (nybble_count+1)/2, buf)) {
	    int i;

	    for (i=0; i < nybble_count; i += 2) {
		XPUSHs(sv_2mortal(newSVnv(buf[i/2] & 0x0F)));
		if (i < nybble_count-1)
		    XPUSHs(sv_2mortal(newSVnv(buf[i/2] >> 4)));



( run in 1.738 second using v1.01-cache-2.11-cpan-71847e10f99 )