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 |
ASYN driver for National Instruments VISA.
Definition in file drvAsynVISAPort.cpp.
#define VI_CHECK_ERROR | ( | __command, | |
__err | |||
) |
Definition at line 67 of file drvAsynVISAPort.cpp.
Referenced by connectIt(), getOption(), readIt(), setOption(), and writeIt().
|
static |
Definition at line 559 of file drvAsynVISAPort.cpp.
References connectIt().
|
static |
Definition at line 570 of file drvAsynVISAPort.cpp.
References closeConnection().
|
static |
asynCommon interface - Report link parameters
Definition at line 396 of file drvAsynVISAPort.cpp.
References visaDriver_t::connected, visaDriver_t::deviceSendsEOM, visaDriver_t::isGPIB, visaDriver_t::isSerial, visaDriver_t::nReadBytes, visaDriver_t::nReadCalls, visaDriver_t::nWriteBytes, visaDriver_t::nWriteCalls, visaDriver_t::readIntTimeout, visaDriver_t::resourceName, and visaDriver_t::termCharIn.
|
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 |
create a link
Definition at line 457 of file drvAsynVISAPort.cpp.
References visaDriver_t::connected, visaDriver_t::defaultRM, errMsg(), visaDriver_t::isGPIB, visaDriver_t::isSerial, visaDriver_t::resourceName, visaDriver_t::termCharIn, visaDriver_t::vi, and VI_CHECK_ERROR.
Referenced by asynCommonConnect().
|
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.
[in] | portName | A name for the asyn driver instance we will create e.g. "L0". |
[in] | resourceName | VISA resource name to connect to e.g. "GPIB0::3::INSTR" or "COM10". |
[in] | priority | Driver priority. |
[in] | noAutoConnect | Should the driver automatically connect to the device (0=yes) |
[in] | noProcessEos | 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. |
[in] | readIntTmoMs | 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. |
[in] | termCharIn | 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. |
[in] | deviceSendsEOM | 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 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 |
Definition at line 1069 of file drvAsynVISAPort.cpp.
References drvAsynVISAPortConfigure().
Referenced by drvAsynVISAPortConfigureRegister().
|
static |
Definition at line 1079 of file drvAsynVISAPort.cpp.
References drvAsynVISAPortConfigureCallFunc(), and drvAsynVISAPortConfigureFuncDef.
epicsExportRegistrar | ( | drvAsynVISAPortConfigureRegister | ) |
|
static |
translate VISA error code to readable string
Definition at line 60 of file drvAsynVISAPort.cpp.
Referenced by connectIt(), readIt(), and writeIt().
|
static |
flush device
Definition at line 849 of file drvAsynVISAPort.cpp.
References visaDriver_t::connected, and visaDriver_t::resourceName.
|
static |
asynOption interface - get options
Definition at line 79 of file drvAsynVISAPort.cpp.
References visaDriver_t::connected, visaDriver_t::isSerial, visaDriver_t::pasynUser, visaDriver_t::portName, visaDriver_t::resourceName, visaDriver_t::vi, and VI_CHECK_ERROR.
|
static |
read values from device
Definition at line 662 of file drvAsynVISAPort.cpp.
References closeConnection(), visaDriver_t::connected, visaDriver_t::deviceSendsEOM, errMsg(), visaDriver_t::nReadBytes, visaDriver_t::nReadCalls, visaDriver_t::readIntTimeout, visaDriver_t::resourceName, visaDriver_t::timeout, visaDriver_t::vi, and VI_CHECK_ERROR.
|
static |
asynOption interface - set options
Definition at line 198 of file drvAsynVISAPort.cpp.
References visaDriver_t::connected, visaDriver_t::flush_on_write, visaDriver_t::isSerial, visaDriver_t::pasynUser, visaDriver_t::portName, visaDriver_t::resourceName, visaDriver_t::vi, and VI_CHECK_ERROR.
|
static |
Definition at line 428 of file drvAsynVISAPort.cpp.
References visaDriver_t::defaultRM, visaDriver_t::pasynUser, and visaDriver_t::portName.
Referenced by drvAsynVISAPortConfigure().
|
static |
write values to device
Definition at line 579 of file drvAsynVISAPort.cpp.
References closeConnection(), visaDriver_t::connected, errMsg(), visaDriver_t::flush_on_write, visaDriver_t::nWriteBytes, visaDriver_t::nWriteCalls, visaDriver_t::resourceName, visaDriver_t::timeout, visaDriver_t::vi, and VI_CHECK_ERROR.
|
static |
Definition at line 876 of file drvAsynVISAPort.cpp.
Referenced by drvAsynVISAPortConfigure().
Definition at line 871 of file drvAsynVISAPort.cpp.
Referenced by drvAsynVISAPortConfigure().
Definition at line 367 of file drvAsynVISAPort.cpp.
Referenced by drvAsynVISAPortConfigure().
|
static |
A name for the asyn driver instance we will create e.g. "L0".
Definition at line 1031 of file drvAsynVISAPort.cpp.
|
static |
VISA resource name to connect to e.g. "GPIB0::3::INSTR" or "COM10".
Definition at line 1033 of file drvAsynVISAPort.cpp.
|
static |
Driver priority.
Definition at line 1035 of file drvAsynVISAPort.cpp.
|
static |
Should the driver automatically connect to the device (0=yes)
Definition at line 1037 of file drvAsynVISAPort.cpp.
|
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.
|
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.
|
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.
|
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.
|
static |
Definition at line 1059 of file drvAsynVISAPort.cpp.
|
static |
Definition at line 1066 of file drvAsynVISAPort.cpp.
Referenced by drvAsynVISAPortConfigureRegister().