41 #define _CRT_SECURE_NO_DEPRECATE //do not use windows secure crt 49 #define __FILE_ID__ "digitalio" 53 ,_portState(PORTSTATE_INVALID)
54 ,_portDirection(PORTDIRECTION_INVALID)
55 ,_portOpenDrain(PORTOPENDRAIN_INVALID)
56 ,_portPolarity(PORTPOLARITY_INVALID)
57 ,_portDiags(PORTDIAGS_INVALID)
58 ,_portSize(PORTSIZE_INVALID)
59 ,_outputVoltage(OUTPUTVOLTAGE_INVALID)
60 ,_command(COMMAND_INVALID)
61 ,_valueCallbackDigitalIO(NULL)
78 if(json_val->
has(
"portState")) {
81 if(json_val->
has(
"portDirection")) {
84 if(json_val->
has(
"portOpenDrain")) {
87 if(json_val->
has(
"portPolarity")) {
90 if(json_val->
has(
"portDiags")) {
93 if(json_val->
has(
"portSize")) {
96 if(json_val->
has(
"outputVoltage")) {
99 if(json_val->
has(
"command")) {
127 }
catch (std::exception) {
151 char buf[32]; sprintf(buf,
"%d", newval); rest_val = string(buf);
152 res =
_setAttr(
"portState", rest_val);
153 }
catch (std::exception) {
183 }
catch (std::exception) {
208 char buf[32]; sprintf(buf,
"%d", newval); rest_val = string(buf);
209 res =
_setAttr(
"portDirection", rest_val);
210 }
catch (std::exception) {
241 }
catch (std::exception) {
266 char buf[32]; sprintf(buf,
"%d", newval); rest_val = string(buf);
267 res =
_setAttr(
"portOpenDrain", rest_val);
268 }
catch (std::exception) {
298 }
catch (std::exception) {
325 char buf[32]; sprintf(buf,
"%d", newval); rest_val = string(buf);
326 res =
_setAttr(
"portPolarity", rest_val);
327 }
catch (std::exception) {
358 }
catch (std::exception) {
387 }
catch (std::exception) {
417 }
catch (std::exception) {
442 char buf[32]; sprintf(buf,
"%d", newval); rest_val = string(buf);
443 res =
_setAttr(
"outputVoltage", rest_val);
444 }
catch (std::exception) {
466 }
catch (std::exception) {
481 res =
_setAttr(
"command", rest_val);
482 }
catch (std::exception) {
530 }
catch (std::exception) {
552 if (callback != NULL) {
559 if (callback != NULL && this->
isOnline()) {
590 if (!(bitstate >= 0)) {
594 if (!(bitstate <= 1)) {
614 return ((((portVal) >> (bitno))) & (1));
644 if (!(bitdirection >= 0)) {
648 if (!(bitdirection <= 1)) {
668 return ((((portDir) >> (bitno))) & (1));
685 if (!(bitpolarity >= 0)) {
689 if (!(bitpolarity <= 1)) {
710 return ((((portPol) >> (bitno))) & (1));
727 if (!(opendrain >= 0)) {
731 if (!(opendrain <= 1)) {
753 return ((((portOpenDrain) >> (bitno))) & (1));
803 vector<YFUN_DESCR> v_fundescr;
805 string serial, funcId, funcName, funcVal, errmsg;
808 v_fundescr.size() == 0 ||
int get_portPolarity(void)
yCRITICAL_SECTION _this_cs
int set_portState(int newval)
virtual int get_bitDirection(int bitno)
static const int PORTDIRECTION_INVALID
YRETCODE _load_unsafe(int msValidity)
virtual int _parseAttr(YJSONObject *json_val)
virtual int get_bitPolarity(int bitno)
static int DefaultCacheValidity
YDigitalIO(const string &func)
string getString(const string &key)
int get_portOpenDrain(void)
void(* YDigitalIOValueCallback)(YDigitalIO *func, const string &functionValue)
static const int PORTOPENDRAIN_INVALID
void _throw(YRETCODE errType, string errMsg)
void yLeaveCriticalSection(yCRITICAL_SECTION *cs)
int set_portPolarity(int newval)
static YRETCODE getFunctionInfo(YFUN_DESCR fundesc, YDEV_DESCR &devdescr, string &serial, string &funcId, string &funcName, string &funcVal, string &errmsg)
static const int PORTSTATE_INVALID
virtual int delayedPulse(int bitno, int ms_delay, int ms_duration)
virtual int get_bitState(int bitno)
Y_OUTPUTVOLTAGE_enum get_outputVoltage(void)
#define YAPI_INVALID_STRING
virtual int _parseAttr(YJSONObject *json_val)
int getInt(const string &key)
static u64 GetTickCount(void)
static void _AddToCache(const string &classname, const string &func, YFunction *obj)
Y_OUTPUTVOLTAGE_enum _outputVoltage
int set_portOpenDrain(int newval)
virtual int toggle_bitState(int bitno)
static const int PORTDIAGS_INVALID
static YFunction * _FindFromCache(const string &classname, const string &func)
static string ysprintf(const char *fmt,...)
virtual int set_bitOpenDrain(int bitno, int opendrain)
void yEnterCriticalSection(yCRITICAL_SECTION *cs)
static yCRITICAL_SECTION _global_cs
virtual int registerValueCallback(YDigitalIOValueCallback callback)
static const int PORTPOLARITY_INVALID
static const string COMMAND_INVALID
virtual int _invokeValueCallback(string value)
static const Y_OUTPUTVOLTAGE_enum OUTPUTVOLTAGE_INVALID
static const int PORTSIZE_INVALID
int set_outputVoltage(Y_OUTPUTVOLTAGE_enum newval)
static int getFunctionsByClass(const string &class_str, YFUN_DESCR prevfundesc, vector< YFUN_DESCR > &buffer, int maxsize, string &errmsg)
YDigitalIOValueCallback _valueCallbackDigitalIO
virtual int set_bitPolarity(int bitno, int bitpolarity)
virtual int set_bitDirection(int bitno, int bitdirection)
static YDigitalIO * FirstDigitalIO(void)
int set_command(const string &newval)
YDigitalIO * nextDigitalIO(void)
virtual int set_bitState(int bitno, int bitstate)
static bool _apiInitialized
int get_portDirection(void)
YRETCODE _nextFunction(string &hwId)
static void _UpdateValueCallbackList(YFunction *func, bool add)
virtual int get_bitOpenDrain(int bitno)
bool has(const string &key)
virtual int pulse(int bitno, int ms_duration)
YRETCODE _setAttr(string attrname, string newvalue)
int set_portDirection(int newval)
virtual int _invokeValueCallback(string value)
static YDigitalIO * FindDigitalIO(string func)