Device-LabJack

 view release on metacpan or  search on metacpan

linux-labjack/liblabjack/ljackul.c  view on Meta::CPAN

//---------------------------------------------------------------------------
//
//  ljackul.c        
//
//  support@labjack.com
//  6/2004
//
// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 2 of the License, or (at your option)
// any later version.
//----------------------------------------------------------------------
//
// Based on Windows ljackuw.dll V1.16 and ljackv112.c (modified by 
// Eric Sorton) template code
//
//
// The key functions that will require customization for a
// particular OS are:
//
// OpenLabJack
// WriteLabJack
// ReadLabJack
// CloseAll
//
// The LabJack U12 is an HID V1.1 device.  Input and Output reports
// are both 8 bytes (although Windows throws on an extra byte
// at the beginning).  Feature reports are used to transfer stream
// and burst data from the LabJack to the PC, and are 16*8 or 128
// bytes (plus the extra Windows byte at the beginning).
//
// The first time after enumeration that the LabJack is supposed to
// write 8 bytes to the interrupt IN endpoint, the write does not
// happen.  Windows reads nothing. This initial non-response provides
// a good test of the thread timeout we use in our Windows HID
// read function.  You will probably see this behavior on other
// operating systems.
//
//----------------------------------------------------------------------
//
// Changes
// 
// (08/18/2005) Fixed problem in OpenLabJack when *idnum is 0.  Updated
//              version to 1.181.
// 
// (01/17/2005) Added a read after the dummy write in OpenLabJack and 
//              ListAll.  Should help with programs only working once.
//
//-----------------------------------------------------------------------

#include <stdio.h>
#include <math.h>
#include <sys/time.h>
#include <unistd.h>
#include <string.h>
//#include <pthread.h>

/* (efs) Macros to replace those lost in bitops.h
 */
#define BitSet(arg,posn) ((arg) | (1L << (posn)))
#define BitClr(arg,posn) ((arg) & ~(1L << (posn)))
#define BitFlp(arg,posn) ((arg) ^ (1L << (posn)))
#define BitTst(arg,posn) (!(!((arg) & (1L << (posn)))))

/* (efs) added include files, these are probably needed in the real driver for
 * standards compliance */
#include <stdlib.h>

/* (efs) Needed for open
 */
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

/* (efs) typedefs to convert from windows to Linux */
typedef int HANDLE;
typedef long DWORD;
typedef unsigned short USHORT;
typedef unsigned long ULONG;
#define WINAPI
#define _stdcall

/* (efs) Are these defined somewhere standard? */
#define TRUE 1
#define FALSE 0

/* (efs) sleep in windows is milliseconds, convert to microseconds for Linux */
#define Sleep(a) usleep((a)*1000)

/* (efs) implement GetTickCount() for Linux */
long GetTickCount() {
	struct timeval tv;



( run in 0.689 second using v1.01-cache-2.11-cpan-39bf76dae61 )