41 #define _CRT_SECURE_NO_DEPRECATE //do not use windows secure crt 49 #define __FILE_ID__ "steppermotor" 53 ,_motorState(MOTORSTATE_INVALID)
54 ,_diags(DIAGS_INVALID)
55 ,_stepPos(STEPPOS_INVALID)
56 ,_speed(SPEED_INVALID)
57 ,_pullinSpeed(PULLINSPEED_INVALID)
58 ,_maxAccel(MAXACCEL_INVALID)
59 ,_maxSpeed(MAXSPEED_INVALID)
60 ,_stepping(STEPPING_INVALID)
61 ,_overcurrent(OVERCURRENT_INVALID)
62 ,_tCurrStop(TCURRSTOP_INVALID)
63 ,_tCurrRun(TCURRRUN_INVALID)
64 ,_alertMode(ALERTMODE_INVALID)
65 ,_auxMode(AUXMODE_INVALID)
66 ,_auxSignal(AUXSIGNAL_INVALID)
67 ,_command(COMMAND_INVALID)
68 ,_valueCallbackStepperMotor(NULL)
92 if(json_val->
has(
"motorState")) {
95 if(json_val->
has(
"diags")) {
98 if(json_val->
has(
"stepPos")) {
101 if(json_val->
has(
"speed")) {
102 _speed = floor(json_val->
getDouble(
"speed") * 1000.0 / 65536.0 + 0.5) / 1000.0;
104 if(json_val->
has(
"pullinSpeed")) {
107 if(json_val->
has(
"maxAccel")) {
110 if(json_val->
has(
"maxSpeed")) {
113 if(json_val->
has(
"stepping")) {
116 if(json_val->
has(
"overcurrent")) {
119 if(json_val->
has(
"tCurrStop")) {
122 if(json_val->
has(
"tCurrRun")) {
125 if(json_val->
has(
"alertMode")) {
128 if(json_val->
has(
"auxMode")) {
131 if(json_val->
has(
"auxSignal")) {
134 if(json_val->
has(
"command")) {
163 }
catch (std::exception) {
192 }
catch (std::exception) {
220 char buf[32]; sprintf(buf,
"%.2f", floor(newval * 100.0)/100.0); rest_val = string(buf);
221 res =
_setAttr(
"stepPos", rest_val);
222 }
catch (std::exception) {
252 }
catch (std::exception) {
282 }
catch (std::exception) {
306 char buf[32]; sprintf(buf,
"%d", (
int)floor(newval * 65536.0 + 0.5)); rest_val = string(buf);
307 res =
_setAttr(
"pullinSpeed", rest_val);
308 }
catch (std::exception) {
338 }
catch (std::exception) {
362 char buf[32]; sprintf(buf,
"%d", (
int)floor(newval * 65536.0 + 0.5)); rest_val = string(buf);
363 res =
_setAttr(
"maxAccel", rest_val);
364 }
catch (std::exception) {
393 }
catch (std::exception) {
416 char buf[32]; sprintf(buf,
"%d", (
int)floor(newval * 65536.0 + 0.5)); rest_val = string(buf);
417 res =
_setAttr(
"maxSpeed", rest_val);
418 }
catch (std::exception) {
447 }
catch (std::exception) {
477 }
catch (std::exception) {
501 char buf[32]; sprintf(buf,
"%d", newval); rest_val = string(buf);
502 res =
_setAttr(
"stepping", rest_val);
503 }
catch (std::exception) {
532 }
catch (std::exception) {
555 char buf[32]; sprintf(buf,
"%d", newval); rest_val = string(buf);
556 res =
_setAttr(
"overcurrent", rest_val);
557 }
catch (std::exception) {
586 }
catch (std::exception) {
610 char buf[32]; sprintf(buf,
"%d", newval); rest_val = string(buf);
611 res =
_setAttr(
"tCurrStop", rest_val);
612 }
catch (std::exception) {
641 }
catch (std::exception) {
665 char buf[32]; sprintf(buf,
"%d", newval); rest_val = string(buf);
666 res =
_setAttr(
"tCurrRun", rest_val);
667 }
catch (std::exception) {
689 }
catch (std::exception) {
704 res =
_setAttr(
"alertMode", rest_val);
705 }
catch (std::exception) {
727 }
catch (std::exception) {
742 res =
_setAttr(
"auxMode", rest_val);
743 }
catch (std::exception) {
772 }
catch (std::exception) {
796 char buf[32]; sprintf(buf,
"%d", newval); rest_val = string(buf);
797 res =
_setAttr(
"auxSignal", rest_val);
798 }
catch (std::exception) {
820 }
catch (std::exception) {
835 res =
_setAttr(
"command", rest_val);
836 }
catch (std::exception) {
884 }
catch (std::exception) {
906 if (callback != NULL) {
913 if (callback != NULL && this->
isOnline()) {
939 id = (id).substr( 12, 1);
943 res = ((u8)retBin[0]);
1136 vector<YFUN_DESCR> v_fundescr;
1138 string serial, funcId, funcName, funcVal, errmsg;
1141 v_fundescr.size() == 0 ||
YStepperMotorValueCallback _valueCallbackStepperMotor
double getDouble(const string &key)
yCRITICAL_SECTION _this_cs
static const double MAXACCEL_INVALID
Y_MOTORSTATE_enum get_motorState(void)
double get_pullinSpeed(void)
virtual int emergencyStop(void)
YRETCODE _load_unsafe(int msValidity)
int set_stepping(Y_STEPPING_enum newval)
static const int AUXSIGNAL_INVALID
static const string AUXMODE_INVALID
virtual int abortAndHiZ(void)
static const double MAXSPEED_INVALID
virtual int moveRel(double relPos)
static int DefaultCacheValidity
string getString(const string &key)
void(* YStepperMotorValueCallback)(YStepperMotor *func, const string &functionValue)
double get_maxAccel(void)
YStepperMotor * nextStepperMotor(void)
void _throw(YRETCODE errType, string errMsg)
int set_alertMode(const string &newval)
int set_pullinSpeed(double newval)
static const int TCURRRUN_INVALID
void yLeaveCriticalSection(yCRITICAL_SECTION *cs)
static YStepperMotor * FindStepperMotor(string func)
int set_auxMode(const string &newval)
string _download(const string &url)
static YRETCODE getFunctionInfo(YFUN_DESCR fundesc, YDEV_DESCR &devdescr, string &serial, string &funcId, string &funcName, string &funcVal, string &errmsg)
double get_maxSpeed(void)
virtual int _parseAttr(YJSONObject *json_val)
virtual int sendCommand(string command)
virtual int changeSpeed(double speed)
#define YAPI_INVALID_STRING
string get_functionId(void)
virtual int _parseAttr(YJSONObject *json_val)
static const int OVERCURRENT_INVALID
virtual int pause(int waitMs)
int set_stepPos(double newval)
virtual int abortAndBrake(void)
YStepperMotor(const string &func)
static const int DIAGS_INVALID
int getInt(const string &key)
static u64 GetTickCount(void)
static void _AddToCache(const string &classname, const string &func, YFunction *obj)
int set_maxAccel(double newval)
#define YAPI_INVALID_DOUBLE
virtual int findHomePosition(double speed)
static YFunction * _FindFromCache(const string &classname, const string &func)
static const int TCURRSTOP_INVALID
static const double STEPPOS_INVALID
virtual int alertStepDir(int dir)
virtual int alertStepOut(void)
virtual int moveTo(double absPos)
static string ysprintf(const char *fmt,...)
Y_STEPPING_enum _stepping
void yEnterCriticalSection(yCRITICAL_SECTION *cs)
static yCRITICAL_SECTION _global_cs
Y_MOTORSTATE_enum _motorState
static int getFunctionsByClass(const string &class_str, YFUN_DESCR prevfundesc, vector< YFUN_DESCR > &buffer, int maxsize, string &errmsg)
int set_maxSpeed(double newval)
Y_STEPPING_enum get_stepping(void)
int set_tCurrRun(int newval)
static const double PULLINSPEED_INVALID
int set_overcurrent(int newval)
static const string ALERTMODE_INVALID
int set_tCurrStop(int newval)
int set_auxSignal(int newval)
static const string COMMAND_INVALID
static const double SPEED_INVALID
virtual int _invokeValueCallback(string value)
int get_overcurrent(void)
virtual int moveRelSlow(double relPos, double maxSpeed)
static bool _apiInitialized
YRETCODE _nextFunction(string &hwId)
static void _UpdateValueCallbackList(YFunction *func, bool add)
virtual int registerValueCallback(YStepperMotorValueCallback callback)
bool has(const string &key)
YRETCODE _setAttr(string attrname, string newvalue)
int set_command(const string &newval)
static const Y_MOTORSTATE_enum MOTORSTATE_INVALID
static YStepperMotor * FirstStepperMotor(void)
static const Y_STEPPING_enum STEPPING_INVALID
virtual int _invokeValueCallback(string value)
string get_alertMode(void)