ISIS Logo
VISAdrv
ASYN driver for National Instruments VISA
Classes | Macros | Functions | Variables
drvAsynVISAPort.cpp File Reference

ASYN driver for National Instruments VISA. More...

#include <string.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <osiUnistd.h>
#include <cantProceed.h>
#include <errlog.h>
#include <iocsh.h>
#include <epicsAssert.h>
#include <epicsExit.h>
#include <epicsStdio.h>
#include <epicsString.h>
#include <epicsThread.h>
#include <epicsTime.h>
#include <iostream>
#include <string>
#include <visa.h>
#include "asynDriver.h"
#include "asynOctet.h"
#include "asynOption.h"
#include "asynInterposeCom.h"
#include "asynInterposeEos.h"
#include <epicsExport.h>
#include "drvAsynVISAPort.h"

Go to the source code of this file.

Classes

struct  visaDriver_t
 driver private data structure More...
 

Macros

#define VI_CHECK_ERROR(__command, __err)
 

Functions

static std::string errMsg (ViSession vi, ViStatus err)
 translate VISA error code to readable string More...
 
static asynStatus getOption (void *drvPvt, asynUser *pasynUser, const char *key, char *val, int valSize)
 asynOption interface - get options More...
 
static asynStatus setOption (void *drvPvt, asynUser *pasynUser, const char *key, const char *val)
 asynOption interface - set options More...
 
static asynStatus closeConnection (asynUser *pasynUser, visaDriver_t *driver, const char *reason)
 close a VISA session More...
 
static void asynCommonReport (void *drvPvt, FILE *fp, int details)
 asynCommon interface - Report link parameters More...
 
static void visaCleanup (void *arg)
 
static void driverCleanup (visaDriver_t *driver)
 
static asynStatus connectIt (void *drvPvt, asynUser *pasynUser)
 create a link More...
 
static asynStatus asynCommonConnect (void *drvPvt, asynUser *pasynUser)
 
static asynStatus asynCommonDisconnect (void *drvPvt, asynUser *pasynUser)
 
static asynStatus writeIt (void *drvPvt, asynUser *pasynUser, const char *data, size_t numchars, size_t *nbytesTransfered)
 write values to device More...
 
static asynStatus readIt (void *drvPvt, asynUser *pasynUser, char *data, size_t maxchars, size_t *nbytesTransfered, int *gotEom)
 read values from device More...
 
static asynStatus flushIt (void *drvPvt, asynUser *pasynUser)
 flush device More...
 
epicsShareFunc int drvAsynVISAPortConfigure (const char *portName, const char *resourceName, unsigned int priority, int noAutoConnect, int noProcessEos, int readIntTmoMs, const char *termCharIn, int deviceSendsEOM)
 Create a VISA device. More...
 
static void drvAsynVISAPortConfigureCallFunc (const iocshArgBuf *args)
 
static void drvAsynVISAPortConfigureRegister (void)
 
 epicsExportRegistrar (drvAsynVISAPortConfigureRegister)
 

Variables

static struct asynOption asynOptionMethods = { setOption, getOption }
 
static asynOctet asynOctetMethods = { writeIt, readIt, flushIt }
 
static struct asynCommon asynCommonMethods
 
static const iocshArg drvAsynVISAPortConfigureArg0 = { "portName",iocshArgString}
 A name for the asyn driver instance we will create e.g. "L0". More...
 
static const iocshArg drvAsynVISAPortConfigureArg1 = { "resourceName",iocshArgString}
 VISA resource name to connect to e.g. "GPIB0::3::INSTR" or "COM10". More...
 
static const iocshArg drvAsynVISAPortConfigureArg2 = { "priority",iocshArgInt}
 Driver priority. More...
 
static const iocshArg drvAsynVISAPortConfigureArg3 = { "noAutoConnect",iocshArgInt}
 Should the driver automatically connect to the device (0=yes) More...
 
static const iocshArg drvAsynVISAPortConfigureArg4 = { "noProcessEos",iocshArgInt}
 Should the driver interpose layer be called for EOS (termination) character processing (0=yes) If you have no termination character specified to asyn, then passing 1 (=no) may improve efficiency. More...
 
static const iocshArg drvAsynVISAPortConfigureArg5 = { "readIntTmoMs",iocshArgInt}
 internal read timeout (ms) used instead of a zero timeout immediate read. More...
 
static const iocshArg drvAsynVISAPortConfigureArg6 = { "termCharIn",iocshArgString}
 read termination character, this is purely to improve read efficiency and is independent of any characters specified at the asyn or stream device later. More...
 
static const iocshArg drvAsynVISAPortConfigureArg7 = { "deviceSendsEOM",iocshArgInt}
 Indicates that the device signals an "end of message". More...
 
static const iocshArg * drvAsynVISAPortConfigureArgs []
 
static const iocshFuncDef drvAsynVISAPortConfigureFuncDef
 

Detailed Description

ASYN driver for National Instruments VISA.

Definition in file drvAsynVISAPort.cpp.

Macro Definition Documentation

#define VI_CHECK_ERROR (   __command,
  __err 
)
Value:
if (__err < 0) \
{ \
epicsSnprintf(pasynUser->errorMessage,pasynUser->errorMessageSize, \
"%s: %s %s", driver->resourceName, __command, errMsg(driver->vi, err).c_str()); \
return asynError; \
}
static std::string errMsg(ViSession vi, ViStatus err)
translate VISA error code to readable string

Definition at line 67 of file drvAsynVISAPort.cpp.

Referenced by connectIt(), getOption(), readIt(), setOption(), and writeIt().

Function Documentation

static asynStatus asynCommonConnect ( void *  drvPvt,
asynUser *  pasynUser 
)
static

Definition at line 559 of file drvAsynVISAPort.cpp.

References connectIt().

static asynStatus asynCommonDisconnect ( void *  drvPvt,
asynUser *  pasynUser 
)
static

Definition at line 570 of file drvAsynVISAPort.cpp.

References closeConnection().

static void asynCommonReport ( void *  drvPvt,
FILE *  fp,
int  details 
)
static
static asynStatus closeConnection ( asynUser *  pasynUser,
visaDriver_t driver,
const char *  reason 
)
static

close a VISA session

Definition at line 371 of file drvAsynVISAPort.cpp.

References visaDriver_t::connected, visaDriver_t::resourceName, and visaDriver_t::vi.

Referenced by asynCommonDisconnect(), readIt(), and writeIt().

static asynStatus connectIt ( void *  drvPvt,
asynUser *  pasynUser 
)
static
static void driverCleanup ( visaDriver_t driver)
static

Definition at line 445 of file drvAsynVISAPort.cpp.

References visaDriver_t::portName, and visaDriver_t::resourceName.

Referenced by drvAsynVISAPortConfigure().

epicsShareFunc int drvAsynVISAPortConfigure ( const char *  portName,
const char *  resourceName,
unsigned int  priority,
int  noAutoConnect,
int  noProcessEos,
int  readIntTmoMs,
const char *  termCharIn,
int  deviceSendsEOM 
)

Create a VISA device.

Parameters
[in]portNameA name for the asyn driver instance we will create e.g. "L0".
[in]resourceNameVISA resource name to connect to e.g. "GPIB0::3::INSTR" or "COM10".
[in]priorityDriver priority.
[in]noAutoConnectShould the driver automatically connect to the device (0=yes)
[in]noProcessEosShould the driver interpose layer be called for EOS (termination) character processing (0=yes) If you have no termination character specified to asyn, then passing 1 (=no) may improve efficiency.
[in]readIntTmoMsinternal read timeout (ms) used instead of a zero timeout immediate read. Stream device will use such a timeout to flush the input buffer prior to a write, also the driver may use it internally to check for bytes. If you get problems with 0 as this value, try either a small positive number, or if you set it to a negative number then any read call with zero timeout will be replaced with a viFlush() call to clear the input buffer. Such an assumption is valid for stream device, not necessarily for other drivers. Note that for GPIB/ENET we found that such zero timeout reads of no data took much longer than normal reads, hence the option to skip them via a negative timeout.
[in]termCharInread termination character, this is purely to improve read efficiency and is independent of any characters specified at the asyn or stream device later. It allows a read to terminate early without waiting for a timeout, if the calling layer is stream device then it will still decide whether it has all the correct characters or not.
[in]deviceSendsEOMIndicates that the device signals an "end of message". If this is true, then the driver can assume that a VI_SUCCESS call translate to ASYN_EOM_END and this will stop a further call from Stream device if there are no termination characters to otherwise know all output has been received. GPIB devices usually signal END, RS232 serial devices do not and you need to look for a termination character instead etc.

Definition at line 893 of file drvAsynVISAPort.cpp.

References asynCommonMethods, asynOctetMethods, asynOptionMethods, visaDriver_t::common, visaDriver_t::connected, visaDriver_t::defaultRM, visaDriver_t::deviceSendsEOM, driverCleanup(), visaDriver_t::flush_on_write, visaDriver_t::isGPIB, visaDriver_t::isSerial, visaDriver_t::octet, visaDriver_t::option, visaDriver_t::pasynUser, visaDriver_t::portName, visaDriver_t::readIntTimeout, visaDriver_t::resourceName, visaDriver_t::termCharIn, visaDriver_t::timeout, and visaCleanup().

Referenced by drvAsynVISAPortConfigureCallFunc().

static void drvAsynVISAPortConfigureCallFunc ( const iocshArgBuf *  args)
static

Definition at line 1069 of file drvAsynVISAPort.cpp.

References drvAsynVISAPortConfigure().

Referenced by drvAsynVISAPortConfigureRegister().

static void drvAsynVISAPortConfigureRegister ( void  )
static
epicsExportRegistrar ( drvAsynVISAPortConfigureRegister  )
static std::string errMsg ( ViSession  vi,
ViStatus  err 
)
static

translate VISA error code to readable string

Definition at line 60 of file drvAsynVISAPort.cpp.

Referenced by connectIt(), readIt(), and writeIt().

static asynStatus flushIt ( void *  drvPvt,
asynUser *  pasynUser 
)
static

flush device

Definition at line 849 of file drvAsynVISAPort.cpp.

References visaDriver_t::connected, and visaDriver_t::resourceName.

static asynStatus getOption ( void *  drvPvt,
asynUser *  pasynUser,
const char *  key,
char *  val,
int  valSize 
)
static
static asynStatus readIt ( void *  drvPvt,
asynUser *  pasynUser,
char *  data,
size_t  maxchars,
size_t *  nbytesTransfered,
int *  gotEom 
)
static
static asynStatus setOption ( void *  drvPvt,
asynUser *  pasynUser,
const char *  key,
const char *  val 
)
static
static void visaCleanup ( void *  arg)
static
static asynStatus writeIt ( void *  drvPvt,
asynUser *  pasynUser,
const char *  data,
size_t  numchars,
size_t *  nbytesTransfered 
)
static

Variable Documentation

struct asynCommon asynCommonMethods
static
Initial value:
= {
}
static asynStatus asynCommonConnect(void *drvPvt, asynUser *pasynUser)
static asynStatus asynCommonDisconnect(void *drvPvt, asynUser *pasynUser)
static void asynCommonReport(void *drvPvt, FILE *fp, int details)
asynCommon interface - Report link parameters

Definition at line 876 of file drvAsynVISAPort.cpp.

Referenced by drvAsynVISAPortConfigure().

asynOctet asynOctetMethods = { writeIt, readIt, flushIt }
static

Definition at line 871 of file drvAsynVISAPort.cpp.

Referenced by drvAsynVISAPortConfigure().

struct asynOption asynOptionMethods = { setOption, getOption }
static

Definition at line 367 of file drvAsynVISAPort.cpp.

Referenced by drvAsynVISAPortConfigure().

const iocshArg drvAsynVISAPortConfigureArg0 = { "portName",iocshArgString}
static

A name for the asyn driver instance we will create e.g. "L0".

Definition at line 1031 of file drvAsynVISAPort.cpp.

const iocshArg drvAsynVISAPortConfigureArg1 = { "resourceName",iocshArgString}
static

VISA resource name to connect to e.g. "GPIB0::3::INSTR" or "COM10".

Definition at line 1033 of file drvAsynVISAPort.cpp.

const iocshArg drvAsynVISAPortConfigureArg2 = { "priority",iocshArgInt}
static

Driver priority.

Definition at line 1035 of file drvAsynVISAPort.cpp.

const iocshArg drvAsynVISAPortConfigureArg3 = { "noAutoConnect",iocshArgInt}
static

Should the driver automatically connect to the device (0=yes)

Definition at line 1037 of file drvAsynVISAPort.cpp.

const iocshArg drvAsynVISAPortConfigureArg4 = { "noProcessEos",iocshArgInt}
static

Should the driver interpose layer be called for EOS (termination) character processing (0=yes) If you have no termination character specified to asyn, then passing 1 (=no) may improve efficiency.

Definition at line 1040 of file drvAsynVISAPort.cpp.

const iocshArg drvAsynVISAPortConfigureArg5 = { "readIntTmoMs",iocshArgInt}
static

internal read timeout (ms) used instead of a zero timeout immediate read.

Stream device will use such a timeout to flush the input buffer prior to a write, also the driver may use it internally to check for bytes. If you get problems with 0 as this value, try either a small positive number, or if you set it to a negative number then any read call with zero timeout will be replaced with a viFlush() call to clear the input buffer. Such an assumption is valid for stream device, not necessarily for other drivers. Note that for GPIB/ENET we found that such zero timeout reads of no data took much longer than normal reads, hence the option to skip them via a negative timeout.

Definition at line 1048 of file drvAsynVISAPort.cpp.

const iocshArg drvAsynVISAPortConfigureArg6 = { "termCharIn",iocshArgString}
static

read termination character, this is purely to improve read efficiency and is independent of any characters specified at the asyn or stream device later.

It allows a read to terminate early without waiting for a timeout, if the calling layer is stream device then it will still decide whether it has all the correct characters or not.

Definition at line 1052 of file drvAsynVISAPort.cpp.

const iocshArg drvAsynVISAPortConfigureArg7 = { "deviceSendsEOM",iocshArgInt}
static

Indicates that the device signals an "end of message".

If this is true, then the driver can assume that a VI_SUCCESS call translate to ASYN_EOM_END and this will stop a further call from Stream device if there are no termination characters to otherwise know all output has been received. GPIB devices usually signal END, RS232 serial devices do not and you need to look for a termination character instead etc.

Definition at line 1057 of file drvAsynVISAPort.cpp.

const iocshArg* drvAsynVISAPortConfigureArgs[]
static
Initial value:
= {
}
static const iocshArg drvAsynVISAPortConfigureArg4
Should the driver interpose layer be called for EOS (termination) character processing (0=yes) If you...
static const iocshArg drvAsynVISAPortConfigureArg3
Should the driver automatically connect to the device (0=yes)
static const iocshArg drvAsynVISAPortConfigureArg7
Indicates that the device signals an &quot;end of message&quot;.
static const iocshArg drvAsynVISAPortConfigureArg0
A name for the asyn driver instance we will create e.g. &quot;L0&quot;.
static const iocshArg drvAsynVISAPortConfigureArg2
Driver priority.
static const iocshArg drvAsynVISAPortConfigureArg5
internal read timeout (ms) used instead of a zero timeout immediate read.
static const iocshArg drvAsynVISAPortConfigureArg1
VISA resource name to connect to e.g. &quot;GPIB0::3::INSTR&quot; or &quot;COM10&quot;.
static const iocshArg drvAsynVISAPortConfigureArg6
read termination character, this is purely to improve read efficiency and is independent of any chara...

Definition at line 1059 of file drvAsynVISAPort.cpp.

const iocshFuncDef drvAsynVISAPortConfigureFuncDef
static
Initial value:
=
{"drvAsynVISAPortConfigure",sizeof(drvAsynVISAPortConfigureArgs)/sizeof(iocshArg*),drvAsynVISAPortConfigureArgs}
static const iocshArg * drvAsynVISAPortConfigureArgs[]

Definition at line 1066 of file drvAsynVISAPort.cpp.

Referenced by drvAsynVISAPortConfigureRegister().

Copyright © 2013 Science and Technology Facilities Council | Generated by   doxygen 1.8.5