20 #include <epicsTypes.h>
21 #include <epicsTime.h>
22 #include <epicsThread.h>
23 #include <epicsString.h>
24 #include <epicsTimer.h>
25 #include <epicsMutex.h>
26 #include <epicsEvent.h>
36 #include <epicsExport.h>
42 _snprintf(buffer,
sizeof(buffer),
"Win32StructuredException code 0x%x pExpCode 0x%x pExpAddress %p", code, pExp->ExceptionRecord->ExceptionCode, pExp->ExceptionRecord->ExceptionAddress);
43 buffer[
sizeof(buffer)-1] =
'\0';
44 return std::string(buffer);
70 int function = pasynUser->reason;
71 asynStatus status = asynSuccess;
72 const char *paramName = NULL;
74 getParamName(
function, ¶mName);
79 throw std::runtime_error(
"m_netvarint is NULL");
82 asynPrint(pasynUser, ASYN_TRACEIO_DRIVER,
83 "%s:%s: function=%d, name=%s, value=%s\n",
87 catch(
const std::exception& ex)
89 epicsSnprintf(pasynUser->errorMessage, pasynUser->errorMessageSize,
90 "%s:%s: status=%d, function=%d, name=%s, value=%s, error=%s",
105 int function = pasynUser->reason;
106 asynStatus status = asynSuccess;
107 const char *paramName = NULL;
109 getParamName(
function, ¶mName);
114 throw std::runtime_error(
"m_netvarint is NULL");
117 asynPrint(pasynUser, ASYN_TRACEIO_DRIVER,
118 "%s:%s: function=%d, name=%s, nElements=%d\n",
119 driverName, functionName,
function, paramName, nElements);
122 catch(
const std::exception& ex)
124 epicsSnprintf(pasynUser->errorMessage, pasynUser->errorMessageSize,
125 "%s:%s: status=%d, function=%d, name=%s, nElements=%d, error=%s",
126 driverName, functionName, status,
function, paramName, nElements, ex.what());
136 asynStatus status =
writeValue(pasynUser,
"writeFloat64", value);
137 return (status == asynSuccess ? asynPortDriver::writeFloat64(pasynUser, value) : status);
142 asynStatus status =
writeValue(pasynUser,
"writeInt32", value);
143 return (status == asynSuccess ? asynPortDriver::writeInt32(pasynUser, value) : status);
148 int function = pasynUser->reason;
149 asynStatus status = asynSuccess;
150 const char *paramName = NULL;
152 getParamName(
function, ¶mName);
153 const char* functionName =
"writeOctet";
154 std::string value_s(value, maxChars);
159 throw std::runtime_error(
"m_netvarint is NULL");
162 asynPrint(pasynUser, ASYN_TRACEIO_DRIVER,
163 "%s:%s: function=%d, name=%s, value=%s\n",
164 driverName, functionName,
function, paramName, value_s.c_str());
165 *nActual = value_s.size();
166 return asynPortDriver::writeOctet(pasynUser, value_s.c_str(), maxChars, nActual);
168 catch(
const std::exception& ex)
170 epicsSnprintf(pasynUser->errorMessage, pasynUser->errorMessageSize,
171 "%s:%s: status=%d, function=%d, name=%s, value=%s, error=%s",
172 driverName, functionName, status,
function, paramName, value_s.c_str(), ex.what());
180 return readArrayValue(pasynUser,
"readFloat64Array", value, nElements, nIn);
185 return readArrayValue(pasynUser,
"readFloat32Array", value, nElements, nIn);
190 return readArrayValue(pasynUser,
"readInt32Array", value, nElements, nIn);
195 return readArrayValue(pasynUser,
"readInt16Array", value, nElements, nIn);
200 return readArrayValue(pasynUser,
"readInt8Array", value, nElements, nIn);
206 int function = pasynUser->reason;
207 asynStatus status = asynSuccess;
208 const char *paramName = NULL;
210 getParamName(
function, ¶mName);
215 throw std::runtime_error(
"m_netvarint is NULL");
218 asynPrint(pasynUser, ASYN_TRACEIO_DRIVER,
219 "%s:%s: function=%d, name=%s, size=%d\n",
220 driverName, functionName,
function, paramName, nElements);
223 catch(
const std::exception& ex)
226 epicsSnprintf(pasynUser->errorMessage, pasynUser->errorMessageSize,
227 "%s:%s: status=%d, function=%d, name=%s, size=%d, error=%s",
228 driverName, functionName, status,
function, paramName, nElements, ex.what());
235 return writeArrayValue(pasynUser,
"writeInt32Array", value, nElements);
240 return writeArrayValue(pasynUser,
"writeInt16Array", value, nElements);
250 return writeArrayValue(pasynUser,
"writeFloat64Array", value, nElements);
255 return writeArrayValue(pasynUser,
"writeFloat32Array", value, nElements);
267 fprintf(fp,
"NetVarInt pointer is NULL\n");
269 asynPortDriver::report(fp, details);
280 : asynPortDriver(portName,
282 netvarint->nParams(),
283 asynInt32Mask | asynInt32ArrayMask | asynFloat64Mask | asynFloat64ArrayMask | asynOctetMask | asynDrvUserMask,
284 asynInt32Mask | asynInt32ArrayMask | asynFloat64Mask | asynFloat64ArrayMask | asynOctetMask,
289 m_netvarint(netvarint), m_poll_ms(poll_ms), m_shutting_down(false)
291 const char *functionName =
"NINetVarDriver";
296 std::cerr <<
"Warning: driver is not polling for buffered reads, only subscribers will see changes" << std::endl;
301 if (epicsThreadCreate(
"NINetVarDriverTask",
302 epicsThreadPriorityMedium,
303 epicsThreadGetStackSize(epicsThreadStackMedium),
306 printf(
"%s:%s: epicsThreadCreate failure\n",
driverName, functionName);
332 epicsThreadSleep(static_cast<double>(poll_ms) / 1000.0);
347 int NINetVarConfigure(
const char *portName,
const char* configSection,
const char *configFile,
int pollPeriod,
int options)
353 if (netvarint != NULL)
360 errlogSevPrintf(errlogFatal,
"NINetVarConfigure failed (NULL)\n");
365 catch(
const std::exception& ex)
367 errlogSevPrintf(errlogFatal,
"NINetVarConfigure failed: %s\n", ex.what());
374 static const iocshArg
initArg0 = {
"portName", iocshArgString};
375 static const iocshArg
initArg1 = {
"configSection", iocshArgString};
376 static const iocshArg
initArg2 = {
"configFile", iocshArgString};
377 static const iocshArg
initArg3 = {
"pollPeriod", iocshArgInt};
378 static const iocshArg
initArg4 = {
"options", iocshArgInt};
386 static const iocshFuncDef
initFuncDef = {
"NINetVarConfigure",
sizeof(
initArgs) /
sizeof(iocshArg*), initArgs};
390 NINetVarConfigure(args[0].sval, args[1].sval, args[2].sval, args[3].ival, args[4].ival);
virtual void report(FILE *fp, int details)
EPICS driver report function for iocsh dbior command.
virtual asynStatus readInt32Array(asynUser *pasynUser, epicsInt32 *value, size_t nElements, size_t *nIn)
static const iocshArg initArg4
options as per NINetVarOptions enum
virtual asynStatus writeOctet(asynUser *pasynUser, const char *value, size_t maxChars, size_t *nActual)
header for NINetVarInterface class.
static const iocshFuncDef initFuncDef
std::string convertToString(T t)
Convert a numeric type to a string.
static void initCallFunc(const iocshArgBuf *args)
static const iocshArg initArg3
poll period (ms)
static const iocshArg *const initArgs[]
epicsExportRegistrar(NINetVarRegister)
void setValue(const char *param, const T &value)
An STL exception describing a Win32 Structured Exception.
void setArrayValue(const char *param, const T *value, size_t nElements)
static const char * driverName
Name of driver for use in message printing.
void shuttingDown(bool state)
asynStatus writeValue(asynUser *pasynUser, const char *functionName, T value)
write a value to the driver
virtual asynStatus readFloat32Array(asynUser *pasynUser, epicsFloat32 *value, size_t nElements, size_t *nIn)
EPICS Asyn port driver class.
static void epicsExitFunc(void *arg)
static const iocshArg initArg0
The name of the asyn driver port we will create.
static void NINetVarRegister(void)
Register new commands with EPICS IOC shell.
static std::string win32_message(unsigned int code, EXCEPTION_POINTERS *pExp)
Helper function to map a win32 structured exception into a C++ standard exception.
virtual asynStatus readInt16Array(asynUser *pasynUser, epicsInt16 *value, size_t nElements, size_t *nIn)
virtual asynStatus writeInt8Array(asynUser *pasynUser, epicsInt8 *value, size_t nElements)
static const iocshArg initArg1
section name of configFile to use to configure this asyn port
int NINetVarConfigure(const char *portName, const char *configSection, const char *configFile, int pollPeriod, int options)
EPICS iocsh callable function to call constructor of NINetVarInterface().
void createParams(asynPortDriver *driver)
virtual asynStatus writeInt32(asynUser *pasynUser, epicsInt32 value)
virtual asynStatus readFloat64Array(asynUser *pasynUser, epicsFloat64 *value, size_t nElements, size_t *nIn)
virtual asynStatus writeInt16Array(asynUser *pasynUser, epicsInt16 *value, size_t nElements)
NINetVarDriver(NINetVarInterface *netvarint, int poll_ms, const char *portName)
Constructor for the NINetVarDriver class.
static void registerStructuredExceptionHandler()
Register a handler for Win32 strcutured exceptions. This needs to be done on a per thread basis...
static const iocshArg initArg2
Path to the XML input file to load configuration information from.
static void seTransFunction(unsigned int u, EXCEPTION_POINTERS *pExp)
Function to translate a Win32 structured exception into a standard C++ exception. ...
virtual asynStatus writeFloat32Array(asynUser *pasynUser, epicsFloat32 *value, size_t nElements)
NINetVarInterface * m_netvarint
asynStatus readArrayValue(asynUser *pasynUser, const char *functionName, T *value, size_t nElements, size_t *nIn)
void report(FILE *fp, int details)
Helper for EPICS driver report function.
Header for templated number to string conversion functions.
virtual asynStatus writeFloat64Array(asynUser *pasynUser, epicsFloat64 *value, size_t nElements)
Manager class for the NetVar Interaction. Parses an netvarconfig.xml file and provides access to the ...
virtual asynStatus writeFloat64(asynUser *pasynUser, epicsFloat64 value)
write a float to the driver
virtual asynStatus readInt8Array(asynUser *pasynUser, epicsInt8 *value, size_t nElements, size_t *nIn)
Header for NINetVarDriver class.
virtual asynStatus writeInt32Array(asynUser *pasynUser, epicsInt32 *value, size_t nElements)
static void NINetVarTask(void *arg)
void readArrayValue(const char *paramName, T *value, size_t nElements, size_t *nIn)
asynStatus writeArrayValue(asynUser *pasynUser, const char *functionName, T *value, size_t nElements)
write an array to the driver