Add some plc commands

This commit is contained in:
Anders Sandstrom
2022-01-31 17:04:08 +01:00
parent 33898dd058
commit 64132b6fe7
5 changed files with 95 additions and 7 deletions

View File

@@ -731,7 +731,7 @@ int ecmcGrbl::setReset(int reset) {
if(!resetCmd_ && reset) {
mc_reset();
}
resetCmd_ = reset;
resetCmd_ = reset;
return 0;
}
@@ -739,6 +739,14 @@ int ecmcGrbl::getBusy() {
return getEcmcEpicsIOCState()!=16 || writerBusy_ || stepperInterruptEnable;
}
int ecmcGrbl::getParserBusy() {
return getEcmcEpicsIOCState()!=16 || writerBusy_;
}
int ecmcGrbl::getCodeRowNum() {
return grblCommandBufferIndex_;
}
// Avoid issues with std:to_string()
std::string ecmcGrbl::to_string(int value) {
std::ostringstream os;

View File

@@ -52,7 +52,9 @@ class ecmcGrbl : public asynPortDriver {
int setResume(int resume);
int setReset(int reset);
int getBusy();
int getParserBusy();
int getCodeRowNum();
private:
void parseConfigStr(char *configStr);
void preExeAxes();

View File

@@ -99,6 +99,21 @@ int getBusy() {
return 0;
}
int getParserBusy() {
if(grbl){
return grbl->getParserBusy();
}
return 0;
}
int getCodeRowNum() {
if(grbl){
return grbl->getCodeRowNum();
}
return 0;
}
int setReset(int reset) {
if(grbl){
return grbl->setReset(reset);

View File

@@ -58,6 +58,15 @@ int setReset(int reset);
*/
int getBusy();
/** \brief get grbl g-code parser busy\n
*/
int getParserBusy();
/** \brief get grbl g-code row number\n
*/
int getCodeRowNum();
// Delete object
void deleteGrbl();

View File

@@ -119,12 +119,21 @@ double grbl_mc_reset(double halt) {
return setReset((int)halt);
}
// Plc function for reset grbl
double grbl_get_busy() {
return getBusy();
}
// Plc function for reset grbl
double grbl_get_parser_busy() {
return getParserBusy();
}
// Plc function for reset grbl
double grbl_get_code_row_num() {
return getCodeRowNum();
}
// Register data for plugin so ecmc know what to use
struct ecmcPluginData pluginDataDef = {
// Allways use ECMC_PLUG_VERSION_MAGIC
@@ -248,11 +257,11 @@ struct ecmcPluginData pluginDataDef = {
.funcGenericObj = NULL,
},
.funcs[4] =
{ /*----can_connect----*/
{ /*----grbl_get_busy----*/
// Function name (this is the name you use in ecmc plc-code)
.funcName = "grbl_get_busy",
// Function description
.funcDesc = "double grbl_get_busy() : Get grbl system busy",
.funcDesc = "double grbl_get_busy() : Get grbl system busy (still executing motion code)",
/**
* 7 different prototypes allowed (only doubles since reg in plc).
* Only funcArg${argCount} func shall be assigned the rest set to NULL.
@@ -270,8 +279,53 @@ struct ecmcPluginData pluginDataDef = {
.funcArg10 = NULL,
.funcGenericObj = NULL,
},
.funcs[5] = {0}, // last element set all to zero..
.funcs[5] =
{ /*----grbl_get_parser_busy----*/
// Function name (this is the name you use in ecmc plc-code)
.funcName = "grbl_get_parser_busy",
// Function description
.funcDesc = "double grbl_get_parser_busy() : Get g-code parser busy.",
/**
* 7 different prototypes allowed (only doubles since reg in plc).
* Only funcArg${argCount} func shall be assigned the rest set to NULL.
**/
.funcArg0 = grbl_get_parser_busy,
.funcArg1 = NULL,
.funcArg2 = NULL,
.funcArg3 = NULL,
.funcArg4 = NULL,
.funcArg5 = NULL,
.funcArg6 = NULL,
.funcArg7 = NULL,
.funcArg8 = NULL,
.funcArg9 = NULL,
.funcArg10 = NULL,
.funcGenericObj = NULL,
},
.funcs[6] =
{ /*----grbl_get_code_row_num----*/
// Function name (this is the name you use in ecmc plc-code)
.funcName = "grbl_get_code_row_num",
// Function description
.funcDesc = "double grbl_get_code_row_num() : Get g-code row number currently preparing for exe.",
/**
* 7 different prototypes allowed (only doubles since reg in plc).
* Only funcArg${argCount} func shall be assigned the rest set to NULL.
**/
.funcArg0 = grbl_get_code_row_num,
.funcArg1 = NULL,
.funcArg2 = NULL,
.funcArg3 = NULL,
.funcArg4 = NULL,
.funcArg5 = NULL,
.funcArg6 = NULL,
.funcArg7 = NULL,
.funcArg8 = NULL,
.funcArg9 = NULL,
.funcArg10 = NULL,
.funcGenericObj = NULL,
},
.funcs[7] = {0}, // last element set all to zero..
// PLC consts
.consts[0] = {0}, // last element set all to zero..
};