54 lines
1.1 KiB
C
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);
|
|
}
|