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;
gettimeofday(&tv, NULL);
return (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
}
#include "ljackul.h"
#define VERSION (float)1.181
#define LABJACK_VENDOR_ID (USHORT)3285
#define LABJACK_U12_PRODUCT_ID (USHORT)0001
#define INPUT_BUFFER_SIZE_LJ (ULONG)198
#define RAM_BUFF_ROWS 64
#define MAX_DEVICES_LJ 256 //local ID range determines this
#define FCDD_MAX 128
#define READ_TIMEOUT_MS 2000
#define MAX_LABJACKS 16
#define NO_ERROR_LJ (long)0 //must be 0
#define UNKNOWN_ERROR_LJ (long)1
#define NO_DEVICES_FOUND_LJ (long)2
#define DEVICE_N_NOT_FOUND_LJ (long)3
#define SET_BUFFER_ERROR_LJ (long)4
#define OPEN_HANDLE_ERROR_LJ (long)5
#define CLOSE_HANDLE_ERROR_LJ (long)6
#define INVALID_ID_LJ (long)7
( run in 0.545 second using v1.01-cache-2.11-cpan-39bf76dae61 )