Files
sics/site_ansto/hardsup/sct_usbtmcprot.c
Douglas Clowes 4ac338f4af replace stropts.h with sys/ioctl.h to define ioctl
r3020 | dcl | 2010-08-13 15:00:40 +1000 (Fri, 13 Aug 2010) | 1 line
2012-11-15 17:06:04 +11:00

54 lines
1.1 KiB
C

/** @file USBTMC protocol handler for script-context based controllers.
*
*/
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <ascon.h>
#include <ascon.i>
#include <dynstring.h>
#include "usbtmc.h"
static void USBTMC_Connect(Ascon *a) {
struct usbtmc_instrument inst;
struct usbtmc_attribute attr;
a->fd = open(a->hostport, O_RDWR);
if (a->fd == -1) exit(1);
// Tell the driver we are using read(2), not fread(2)
attr.attribute=USBTMC_ATTRIB_READ_MODE;
attr.value=USBTMC_ATTRIB_VAL_READ;
ioctl(a->fd,USBTMC_IOCTL_SET_ATTRIBUTE,&attr);
attr.attribute=USBTMC_ATTRIB_NUM_INSTRUMENTS;
ioctl(a->fd,USBTMC_IOCTL_GET_ATTRIBUTE,&attr);
return;
}
/**
* @brief USBTMC protocol handler.
*/
int USBTMC_ProtHandler(Ascon *a) {
switch(a->state){
case AsconConnectStart:
USBTMC_Connect(a);
break;
default:
return AsconStdHandler(a);
}
return 1;
}
void AddUSBTMCProtocoll(){
AsconProtocol *prot = NULL;
prot = calloc(sizeof(AsconProtocol), 1);
prot->name = strdup("usbtmc");
prot->init = AsconStdInit;
prot->handler = USBTMC_ProtHandler;
AsconInsertProtocol(prot);
}