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>
35 #include <epicsExport.h>
51 int function = pasynUser->reason;
52 asynStatus status = asynSuccess;
53 const char *paramName = NULL;
54 getParamName(
function, ¶mName);
59 throw std::runtime_error(
"m_netvarint is NULL");
62 asynPrint(pasynUser, ASYN_TRACEIO_DRIVER,
63 "%s:%s: function=%d, name=%s, value=%s\n",
67 catch(
const std::exception& ex)
69 epicsSnprintf(pasynUser->errorMessage, pasynUser->errorMessageSize,
70 "%s:%s: status=%d, function=%d, name=%s, value=%s, error=%s",
78 int function = pasynUser->reason;
79 const char *paramName = NULL;
80 getParamName(
function, ¶mName);
85 throw std::runtime_error(
"m_netvarint is NULL");
91 catch(
const std::exception& ex)
93 epicsSnprintf(pasynUser->errorMessage, pasynUser->errorMessageSize,
94 "%s:%s: function=%d, name=%s, error=%s",
95 driverName, functionName,
function, paramName, ex.what());
109 int function = pasynUser->reason;
110 asynStatus status = asynSuccess;
111 const char *paramName = NULL;
112 getParamName(
function, ¶mName);
117 throw std::runtime_error(
"m_netvarint is NULL");
120 asynPrint(pasynUser, ASYN_TRACEIO_DRIVER,
121 "%s:%s: function=%d, name=%s, nElements=%d\n",
122 driverName, functionName,
function, paramName, (
int)nElements);
125 catch(
const std::exception& ex)
127 epicsSnprintf(pasynUser->errorMessage, pasynUser->errorMessageSize,
128 "%s:%s: status=%d, function=%d, name=%s, nElements=%d, error=%s",
129 driverName, functionName, status,
function, paramName, (
int)nElements, ex.what());
139 asynStatus status =
writeValue(pasynUser,
"writeFloat64", value);
140 return (status == asynSuccess ? asynPortDriver::writeFloat64(pasynUser, value) : status);
145 asynStatus status =
writeValue(pasynUser,
"writeInt32", value);
146 return (status == asynSuccess ? asynPortDriver::writeInt32(pasynUser, value) : status);
151 static const char* functionName =
"readFloat64";
152 int function = pasynUser->reason;
153 const char *paramName = NULL;
154 getParamName(
function, ¶mName);
155 asynStatus status =
readValue(pasynUser, functionName);
156 if (status == asynSuccess)
158 asynPortDriver::readFloat64(pasynUser, value);
159 asynPrint(pasynUser, ASYN_TRACEIO_DRIVER,
160 "%s:%s: function=%d, name=%s, value=%f\n",
161 driverName, functionName,
function, paramName, *value);
168 static const char* functionName =
"readInt32";
169 int function = pasynUser->reason;
170 const char *paramName = NULL;
171 getParamName(
function, ¶mName);
172 asynStatus status =
readValue(pasynUser, functionName);
173 if (status == asynSuccess)
175 asynPortDriver::readInt32(pasynUser, value);
176 asynPrint(pasynUser, ASYN_TRACEIO_DRIVER,
177 "%s:%s: function=%d, name=%s, value=%d\n",
178 driverName, functionName,
function, paramName, *value);
185 static const char *functionName =
"readOctet";
186 int function = pasynUser->reason;
187 const char *paramName = NULL;
188 getParamName(
function, ¶mName);
189 asynStatus status =
readValue(pasynUser, functionName);
190 if (status == asynSuccess)
193 getStringParam(
function, value_s);
194 if ( value_s.size() > maxChars )
197 if (eomReason) { *eomReason = ASYN_EOM_CNT | ASYN_EOM_END; }
198 asynPrint(pasynUser, ASYN_TRACEIO_DRIVER,
199 "%s:%s: function=%d, name=%s, value=\"%s\" (TRUNCATED from %d chars)\n",
200 driverName, functionName,
function, paramName, value_s.substr(0,*nActual).c_str(), value_s.size());
204 *nActual = value_s.size();
205 if (eomReason) { *eomReason = ASYN_EOM_END; }
206 asynPrint(pasynUser, ASYN_TRACEIO_DRIVER,
207 "%s:%s: function=%d, name=%s, value=\"%s\"\n",
208 driverName, functionName,
function, paramName, value_s.c_str());
210 strncpy(value, value_s.c_str(), maxChars);
215 if (eomReason) { *eomReason = ASYN_EOM_END; }
223 int function = pasynUser->reason;
224 asynStatus status = asynSuccess;
225 const char *paramName = NULL;
226 getParamName(
function, ¶mName);
227 const char* functionName =
"writeOctet";
228 std::string value_s(value, maxChars);
233 throw std::runtime_error(
"m_netvarint is NULL");
236 asynPrint(pasynUser, ASYN_TRACEIO_DRIVER,
237 "%s:%s: function=%d, name=%s, value=%s\n",
238 driverName, functionName,
function, paramName, value_s.c_str());
239 *nActual = value_s.size();
240 return asynPortDriver::writeOctet(pasynUser, value_s.c_str(), maxChars, nActual);
242 catch(
const std::exception& ex)
244 epicsSnprintf(pasynUser->errorMessage, pasynUser->errorMessageSize,
245 "%s:%s: status=%d, function=%d, name=%s, value=%s, error=%s",
246 driverName, functionName, status,
function, paramName, value_s.c_str(), ex.what());
254 return readArrayValue(pasynUser,
"readFloat64Array", value, nElements, nIn);
259 return readArrayValue(pasynUser,
"readFloat32Array", value, nElements, nIn);
264 return readArrayValue(pasynUser,
"readInt32Array", value, nElements, nIn);
269 return readArrayValue(pasynUser,
"readInt16Array", value, nElements, nIn);
274 return readArrayValue(pasynUser,
"readInt8Array", value, nElements, nIn);
280 epicsTimeStamp epicsTS;
281 int function = pasynUser->reason;
282 asynStatus status = asynSuccess;
283 const char *paramName = NULL;
284 getParamName(
function, ¶mName);
289 throw std::runtime_error(
"m_netvarint is NULL");
292 getTimeStamp(&epicsTS);
293 pasynUser->timestamp = epicsTS;
294 asynPrint(pasynUser, ASYN_TRACEIO_DRIVER,
295 "%s:%s: function=%d, name=%s, size=%d\n",
296 driverName, functionName,
function, paramName, (
int)nElements);
299 catch(
const std::exception& ex)
302 epicsSnprintf(pasynUser->errorMessage, pasynUser->errorMessageSize,
303 "%s:%s: status=%d, function=%d, name=%s, size=%d, error=%s",
304 driverName, functionName, status,
function, paramName, (
int)nElements, ex.what());
311 return writeArrayValue(pasynUser,
"writeInt32Array", value, nElements);
316 return writeArrayValue(pasynUser,
"writeInt16Array", value, nElements);
326 return writeArrayValue(pasynUser,
"writeFloat64Array", value, nElements);
331 return writeArrayValue(pasynUser,
"writeFloat32Array", value, nElements);
345 fprintf(fp,
"NetVarInt pointer is NULL\n");
347 asynPortDriver::report(fp, details);
358 : asynPortDriver(portName,
360 static_cast<int>(netvarint->nParams()),
361 asynInt32Mask | asynInt8ArrayMask | asynInt16ArrayMask | asynInt32ArrayMask | asynFloat64Mask | asynFloat32ArrayMask | asynFloat64ArrayMask | asynOctetMask | asynDrvUserMask,
362 asynInt32Mask | asynInt8ArrayMask | asynInt16ArrayMask | asynInt32ArrayMask | asynFloat64Mask | asynFloat32ArrayMask | asynFloat64ArrayMask | asynOctetMask,
367 m_netvarint(netvarint), m_poll_ms(poll_ms), m_shutting_down(false)
369 const char *functionName =
"NetShrVarDriver";
374 std::cerr <<
"Warning: driver is not polling for buffered reads, only subscribers will see changes" << std::endl;
379 if (epicsThreadCreate(
"NetShrVarDriverTask",
380 epicsThreadPriorityMedium,
381 epicsThreadGetStackSize(epicsThreadStackMedium),
384 printf(
"%s:%s: epicsThreadCreate failure\n",
driverName, functionName);
412 catch (
const std::exception& ex)
414 std::cerr <<
"NetShrVarTask: " << ex.what() << std::endl;
418 std::cerr <<
"NetShrVarTask: unknown exception" << std::endl;
420 epicsThreadSleep(static_cast<double>(poll_ms) / 1000.0);
435 int NetShrVarConfigure(
const char *portName,
const char* configSection,
const char *configFile,
int pollPeriod,
int options)
440 if (netvarint != NULL)
447 errlogSevPrintf(errlogFatal,
"NetShrVarConfigure failed (NULL)\n");
452 catch(
const std::exception& ex)
454 errlogSevPrintf(errlogFatal,
"NetShrVarConfigure failed: %s\n", ex.what());
461 static const iocshArg
initArg0 = {
"portName", iocshArgString};
462 static const iocshArg
initArg1 = {
"configSection", iocshArgString};
463 static const iocshArg
initArg2 = {
"configFile", iocshArgString};
464 static const iocshArg
initArg3 = {
"pollPeriod", iocshArgInt};
465 static const iocshArg
initArg4 = {
"options", iocshArgInt};
473 static const iocshFuncDef
initFuncDef = {
"NetShrVarConfigure",
sizeof(
initArgs) /
sizeof(iocshArg*), initArgs};
477 NetShrVarConfigure(args[0].sval, args[1].sval, args[2].sval, args[3].ival, args[4].ival);
virtual asynStatus writeFloat64Array(asynUser *pasynUser, epicsFloat64 *value, size_t nElements)
static void epicsExitFunc(void *arg)
std::string convertToString(T t)
Convert a numeric type to a string.
virtual asynStatus writeInt8Array(asynUser *pasynUser, epicsInt8 *value, size_t nElements)
virtual asynStatus readOctet(asynUser *pasynUser, char *value, size_t maxChars, size_t *nActual, int *eomReason)
void shuttingDown(bool state)
NetShrVarInterface * m_netvarint
void setValue(const char *param, const T &value)
virtual asynStatus writeFloat32Array(asynUser *pasynUser, epicsFloat32 *value, size_t nElements)
virtual asynStatus readInt32(asynUser *pasynUser, epicsInt32 *value)
virtual asynStatus readFloat64Array(asynUser *pasynUser, epicsFloat64 *value, size_t nElements, size_t *nIn)
static const iocshArg initArg2
Path to the XML input file to load configuration information from.
static void NetShrVarTask(void *arg)
asynStatus readArrayValue(asynUser *pasynUser, const char *functionName, T *value, size_t nElements, size_t *nIn)
static const iocshArg *const initArgs[]
static const iocshArg initArg0
The name of the asyn driver port we will create.
virtual asynStatus writeInt32(asynUser *pasynUser, epicsInt32 value)
void report(FILE *fp, int details)
Helper for EPICS driver report function.
Manager class for the NetVar Interaction. Parses an netvarconfig.xml file and provides access to the ...
virtual void report(FILE *fp, int details)
EPICS driver report function for iocsh dbior command.
static void initCallFunc(const iocshArgBuf *args)
Header for NetShrVarDriver class.
void readValue(const char *param)
read a value and update corresponding asyn parameter
void createParams(asynPortDriver *driver)
static const iocshArg initArg4
options as per NetShrVarOptions enum
int NetShrVarConfigure(const char *portName, const char *configSection, const char *configFile, int pollPeriod, int options)
EPICS iocsh callable function to call constructor of NetShrVarInterface().
static const iocshArg initArg1
section name of configFile to use to configure this asyn port
virtual asynStatus readInt16Array(asynUser *pasynUser, epicsInt16 *value, size_t nElements, size_t *nIn)
static const iocshFuncDef initFuncDef
virtual asynStatus readInt32Array(asynUser *pasynUser, epicsInt32 *value, size_t nElements, size_t *nIn)
asynStatus readValue(asynUser *pasynUser, const char *functionName)
EPICS Asyn port driver class.
asynStatus writeArrayValue(asynUser *pasynUser, const char *functionName, T *value, size_t nElements)
write an array to the driver
void readArrayValue(const char *paramName, T *value, size_t nElements, size_t *nIn)
called externally with m_driver locked
Header for templated number to string conversion functions.
void setArrayValue(const char *param, const T *value, size_t nElements)
asynStatus writeValue(asynUser *pasynUser, const char *functionName, T value)
write a value to the driver
virtual asynStatus readFloat64(asynUser *pasynUser, epicsFloat64 *value)
NetShrVarDriver(NetShrVarInterface *netvarint, int poll_ms, const char *portName)
Constructor for the NetShrVarDriver class.
virtual asynStatus writeOctet(asynUser *pasynUser, const char *value, size_t maxChars, size_t *nActual)
virtual asynStatus readFloat32Array(asynUser *pasynUser, epicsFloat32 *value, size_t nElements, size_t *nIn)
header for NetShrVarInterface class.
virtual asynStatus writeInt32Array(asynUser *pasynUser, epicsInt32 *value, size_t nElements)
epicsExportRegistrar(NetShrVarRegister)
static void NetShrVarRegister(void)
Register new commands with EPICS IOC shell.
static const iocshArg initArg3
poll period (ms) for BufferedReaders
virtual asynStatus writeInt16Array(asynUser *pasynUser, epicsInt16 *value, size_t nElements)
virtual asynStatus writeFloat64(asynUser *pasynUser, epicsFloat64 value)
write a float to the driver
static const char * driverName
Name of driver for use in message printing.
virtual asynStatus readInt8Array(asynUser *pasynUser, epicsInt8 *value, size_t nElements, size_t *nIn)