This commit is contained in:
Anders Sandstrom
2022-01-20 16:32:18 +01:00
parent aa5b5f8267
commit 002221ccf1
11 changed files with 223 additions and 478 deletions

View File

@@ -0,0 +1,7 @@
{
"files.associations": {
"queue": "cpp",
"typeindex": "cpp",
"typeinfo": "cpp"
}
}

View File

@@ -20,6 +20,7 @@
#include "ecmcAsynPortDriver.h"
#include "ecmcAsynPortDriverUtils.h"
#include "epicsThread.h"
extern "C" {
#include "grbl.h"
}
@@ -47,6 +48,17 @@ void f_worker_read(void *obj) {
grblObj->doReadWorker();
}
// Thread that writes commands to grbl
void f_worker_write(void *obj) {
if(!obj) {
printf("%s/%s:%d: Error: Worker read thread ecmcGrbl object NULL..\n",
__FILE__, __FUNCTION__, __LINE__);
return;
}
ecmcGrbl * grblObj = (ecmcGrbl*)obj;
grblObj->doWriteWorker();
}
// Start worker for socket connect()
void f_worker_main(void *obj) {
if(!obj) {
@@ -92,7 +104,12 @@ ecmcGrbl::ecmcGrbl(char* configStr,
cfgZAxisId_ = -1;
cfgSpindleAxisId_ = -1;
grblInitDone_ = 0;
if(!(grblCommandBufferMutex_ = epicsMutexCreate())) {
throw std::runtime_error("Error: Failed create mutex thread for write().");
}
parseConfigStr(configStr); // Assigns all configs
//Check atleast one valid axis
@@ -101,17 +118,23 @@ ecmcGrbl::ecmcGrbl(char* configStr,
}
// Create worker thread for reading socket
std::string threadname = "ecmc." ECMC_PLUGIN_ASYN_PREFIX ".read";
std::string threadname = "ecmc.grbl.read";
if(epicsThreadCreate(threadname.c_str(), 0, 32768, f_worker_read, this) == NULL) {
throw std::runtime_error("Error: Failed create worker thread for read().");
}
// Create worker thread for connecting socket
threadname = "ecmc." ECMC_PLUGIN_ASYN_PREFIX ".main";
// Create worker thread for main grbl loop
threadname = "ecmc.grbl.main";
if(epicsThreadCreate(threadname.c_str(), 0, 32768, f_worker_main, this) == NULL) {
throw std::runtime_error("Error: Failed create worker thread for main().");
}
// Create worker thread for write socket
threadname = "ecmc.grbl.write";
if(epicsThreadCreate(threadname.c_str(), 0, 32768, f_worker_write, this) == NULL) {
throw std::runtime_error("Error: Failed create worker thread for write().");
}
// wait for grblInitDone_!
printf("Waiting for grbl init..");
while(!grblInitDone_) {
@@ -119,9 +142,6 @@ ecmcGrbl::ecmcGrbl(char* configStr,
printf(".");
}
delay_ms(100);
printf("\n");
printf("\n grbl ready for commands!\n");
sleep(1);
testGrbl();
}
@@ -193,6 +213,32 @@ void ecmcGrbl::doReadWorker() {
}
}
// Write socket worker
void ecmcGrbl::doWriteWorker() {
// simulate serial connection here (need mutex)
printf("%s:%s:%d\n",__FILE__,__FUNCTION__,__LINE__);
for(;;) {
if(grblCommandBuffer_.size()>0) {
printf("%s:%s:%d: Command in buffer!!!\n",__FILE__,__FUNCTION__,__LINE__);
epicsMutexLock(grblCommandBufferMutex_);
std::string command = grblCommandBuffer_.front() + '\n';
grblCommandBuffer_.pop();
epicsMutexUnlock(grblCommandBufferMutex_);
printf("%s:%s:%d: Command length %d!!!\n",__FILE__,__FUNCTION__,__LINE__,strlen(command.c_str()));
printf("%s:%s:%d: Used bytes %d!!!\n",__FILE__,__FUNCTION__,__LINE__,serial_get_rx_buffer_available());
// wait for grbl
while(RX_BUFFER_SIZE-serial_get_rx_buffer_available()<=strlen(command.c_str())) {
delay_ms(1);
}
printf("%s:%s:%d: Writing!!\n",__FILE__,__FUNCTION__,__LINE__);
ecmc_write_command_serial(strdup(command.c_str()));
}
else {
delay_ms(5);
}
}
}
// Main grbl worker (copied from grbl main.c)
void ecmcGrbl::doMainWorker() {
printf("%s:%s:%d\n",__FILE__,__FUNCTION__,__LINE__);
@@ -282,27 +328,35 @@ std::string ecmcGrbl::to_string(int value) {
return os.str();
}
void ecmcGrbl::addCommand(std::string command) {
printf("%s:%s:%d:\n",__FILE__,__FUNCTION__,__LINE__);
epicsMutexLock(grblCommandBufferMutex_);
grblCommandBuffer_.push(command.c_str());
epicsMutexUnlock(grblCommandBufferMutex_);
printf("%s:%s:%d: Buffer size %d\n",__FILE__,__FUNCTION__,__LINE__,grblCommandBuffer_.size());
}
void ecmcGrbl::testGrbl() {
// test some commands
printf("Test command:$\n");
ecmc_write_command_serial("$\n");
sleep(1);
printf("Test command:G0X10Y100\n");
ecmc_write_command_serial("G0X10Y100\n");
sleep(1);
printf("Test command:$G\n");
ecmc_write_command_serial("$G\n");
sleep(1);
printf("Test command:G4P4\n");
ecmc_write_command_serial("G4P4\n");
printf("Test command:G1X20Y200F20\n");
ecmc_write_command_serial("G1X20Y200F20\n");
printf("Test command:G4P4\n");
ecmc_write_command_serial("G4P4\n");
printf("Test command:G2X40Y220R20\n");
ecmc_write_command_serial("G2X40Y220R20\n");
printf("Test command:$\n");
ecmc_write_command_serial("$\n");
//printf("Test command:$\n");
//ecmc_write_command_serial("$\n");
//sleep(1);
//printf("Test command:G0X10Y100\n");
//ecmc_write_command_serial("G0X10Y100\n");
//sleep(1);
//printf("Test command:$G\n");
//ecmc_write_command_serial("$G\n");
//sleep(1);
//printf("Test command:G4P4\n");
//ecmc_write_command_serial("G4P4\n");
//printf("Test command:G1X20Y200F20\n");
//ecmc_write_command_serial("G1X20Y200F20\n");
//printf("Test command:G4P4\n");
//ecmc_write_command_serial("G4P4\n");
//printf("Test command:G2X40Y220R20\n");
//ecmc_write_command_serial("G2X40Y220R20\n");
//printf("Test command:$\n");
//ecmc_write_command_serial("$\n");
}

View File

@@ -0,0 +1 @@
registrar("ecmcGrblPluginDriverRegister")

View File

@@ -17,10 +17,12 @@
#include "ecmcGrblDefs.h"
#include "inttypes.h"
#include <epicsMutex.h>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <queue>
#include <string.h>
class ecmcGrbl : public asynPortDriver {
@@ -40,8 +42,11 @@ class ecmcGrbl : public asynPortDriver {
void doReadWorker();
void doMainWorker();
void doWriteWorker();
void grblRTexecute();
void addCommand(std::string command);
private:
void testGrbl();
@@ -57,6 +62,8 @@ class ecmcGrbl : public asynPortDriver {
int errorCode_;
double exeSampleTimeMs_;
int grblInitDone_;
std::queue<std::string> grblCommandBuffer_;
epicsMutexId grblCommandBufferMutex_;
};
#endif /* ECMC_GRBL_H_ */

View File

@@ -19,6 +19,17 @@
#include "ecmcGrbl.h"
#include "ecmcGrblDefs.h"
#include "ecmcGrblWrap.h"
#include <epicsTypes.h>
#include <epicsTime.h>
#include <epicsThread.h>
#include <epicsString.h>
#include <epicsTimer.h>
#include <epicsMutex.h>
#include <epicsExport.h>
#include <epicsEvent.h>
#include <iocsh.h>
#define ECMC_PLUGIN_MAX_PORTNAME_CHARS 64
#define ECMC_PLUGIN_PORTNAME_PREFIX "PLUGIN.GRBL"
@@ -62,415 +73,60 @@ void deleteGrbl() {
/**
* EPICS iocsh shell command: ecmcCANOpenAddMaster
* EPICS iocsh shell command: ecmcGrblAddCommand
*/
//void ecmcCANOpenAddMasterPrintHelp() {
// printf("\n");
// printf(" Use ecmcCANOpenAddMaster(<name>, <node id>,....)\n");
// printf(" <name> : Name of master device.\n");
// printf(" <node id> : CANOpen node id of master.\n");
// printf(" <LSS sample time ms> : Sample time for LSS.\n");
// printf(" <Sync sample time ms> : Sample time for SYNC.\n");
// printf(" <NMT Heartbeat sample time ms> : Sample time for NMT Heartbeat.\n");
// printf("\n");
//}
//
//int ecmcCANOpenAddMaster(const char* name,
// int nodeId,
// int lssSampleTimeMs,
// int syncSampleTimeMs,
// int heartSampleTimeMs) {
//
// if(!name) {
// printf("Error: name.\n");
// ecmcCANOpenAddMasterPrintHelp();
// return asynError;
// }
//
// if(strcmp(name,"-h") == 0 || strcmp(name,"--help") == 0 ) {
// ecmcCANOpenAddMasterPrintHelp();
// return asynSuccess;
// }
//
// if(!grbl) {
// printf("Plugin not initialized/loaded.\n");
// return asynError;
// }
//
// try {
// grbl->addMaster((uint32_t)nodeId,
// name,
// lssSampleTimeMs,
// syncSampleTimeMs,
// heartSampleTimeMs);
// }
// catch(std::exception& e) {
// printf("Exception: %s. Add master failed.\n",e.what());
// return asynError;
// }
//
// return asynSuccess;
//}
//
//static const iocshArg initArg0_0 =
//{ "Name", iocshArgString };
//static const iocshArg initArg1_0 =
//{ "Node Id", iocshArgInt };
//static const iocshArg initArg2_0 =
//{ "LSS sample time ms", iocshArgInt };
//static const iocshArg initArg3_0 =
//{ "Sync sample time ms", iocshArgInt };
//static const iocshArg initArg4_0 =
//{ "NMT Heart sample time ms", iocshArgInt };
//
//static const iocshArg *const initArgs_0[] = { &initArg0_0,
// &initArg1_0,
// &initArg2_0,
// &initArg3_0,
// &initArg4_0};
//
//static const iocshFuncDef initFuncDef_0 = { "ecmcCANOpenAddMaster", 5, initArgs_0 };
//static void initCallFunc_0(const iocshArgBuf *args) {
// ecmcCANOpenAddMaster(args[0].sval,
// args[1].ival,
// args[2].ival,
// args[3].ival,
// args[4].ival);
//}
//
///**
// * EPICS iocsh shell command: ecmcCANOpenAddDevice
//*/
//
//void ecmcCANOpenAddDevicePrintHelp() {
// printf("\n");
// printf(" Use ecmcCANOpenAddDevice(<name>, <node id>)\n");
// printf(" <name> : Name of device.\n");
// printf(" <node id> : CANOpen node id of device.\n");
// printf(" <NMT Heartbeat timeout ms> : Timeout for NMT Heartbeat.\n");
// printf("\n");
//}
//
//int ecmcCANOpenAddDevice(const char* name, int nodeId,int heartTimeOutMs) {
// if(!name) {
// printf("Error: name.\n");
// ecmcCANOpenAddDevicePrintHelp();
// return asynError;
// }
//
// if(strcmp(name,"-h") == 0 || strcmp(name,"--help") == 0 ) {
// ecmcCANOpenAddDevicePrintHelp();
// return asynSuccess;
// }
//
// if(!grbl) {
// printf("Plugin not initialized/loaded.\n");
// return asynError;
// }
//
// if(heartTimeOutMs < 0) {
// printf("Invalid NMT heartbeat timeout.\n");
// return asynError;
// }
//
// try {
// grbl->addDevice((uint32_t)nodeId,name,heartTimeOutMs);
// }
// catch(std::exception& e) {
// printf("Exception: %s. Add device failed.\n",e.what());
// return asynError;
// }
//
// return asynSuccess;
//}
//
//static const iocshArg initArg0_1 =
//{ "Name", iocshArgString };
//static const iocshArg initArg1_1 =
//{ "Node Id", iocshArgInt };
//static const iocshArg initArg2_1 =
//{ "NMT Heart timeout ms", iocshArgInt };
//
//static const iocshArg *const initArgs_1[] = { &initArg0_1,
// &initArg1_1,
// &initArg2_1};
//
//static const iocshFuncDef initFuncDef_1 = { "ecmcCANOpenAddDevice", 3, initArgs_1 };
//static void initCallFunc_1(const iocshArgBuf *args) {
// ecmcCANOpenAddDevice(args[0].sval, args[1].ival, args[2].ival);
//}
//
///**
// * EPICS iocsh shell command: ecmcCANOpenAddSDO
//*/
//
//void ecmcCANOpenAddSDOPrintHelp() {
// printf("\n");
// printf(" Use ecmcCANOpenAddSDO(<name>, <node id>,.....)\n");
// printf(" <name> : Name of master device.\n");
// printf(" <node id> : CANOpen node id of device/master.\n");
// printf(" <cob id tx> : CANOpen cob id of Tx of slave SDO.\n");
// printf(" <cob id rx> : CANOpen cob id of Rx of slave SDO.\n");
// printf(" <dir> : Direction 1=write and 2=read.\n");
// printf(" <ODIndex> : OD index of SDO.\n");
// printf(" <ODSubIndex> : OD sub index of SDO.\n");
// printf(" <ODSize> : OS Size.\n");
// printf(" <readSampleTimeMs>: Sample time for read in ms (write is always on demand).\n");
// printf("\n");
//}
//
//int ecmcCANOpenAddSDO(const char* name,
// int nodeId,
// int cobIdTx,
// int cobIdRx,
// int dir,
// int ODIndex,
// int ODSubIndex,
// int ODSize,
// int readSampleTimeMs) {
// if(!name) {
// printf("Error: name.\n");
// ecmcCANOpenAddSDOPrintHelp();
// return asynError;
// }
//
// if(strcmp(name,"-h") == 0 || strcmp(name,"--help") == 0 ) {
// ecmcCANOpenAddSDOPrintHelp();
// return asynSuccess;
// }
//
// if(cobIdRx < 0) {
// printf("Error: invalid cobIdRx.\n");
// ecmcCANOpenAddSDOPrintHelp();
// return asynError;
// }
//
// if(cobIdTx < 0) {
// printf("Error: invalid cobIdTx.\n");
// ecmcCANOpenAddSDOPrintHelp();
// return asynError;
// }
//
// if(dir > 2 || dir <= 0) {
// printf("Error: invalid dir.\n");
// ecmcCANOpenAddSDOPrintHelp();
// return asynError;
// }
//
// if(ODIndex < 0) {
// printf("Error: invalid ODIndex.\n");
// ecmcCANOpenAddSDOPrintHelp();
// return asynError;
// }
//
// if(ODSubIndex < 0) {
// printf("Error: invalid ODSubIndex.\n");
// ecmcCANOpenAddSDOPrintHelp();
// return asynError;
// }
//
// if(ODSize < 0) {
// printf("Error: invalid ODSize.\n");
// ecmcCANOpenAddSDOPrintHelp();
// return asynError;
// }
//
// if(readSampleTimeMs < 0) {
// printf("Error: invalid readSampleTimeMs.\n");
// ecmcCANOpenAddSDOPrintHelp();
// return asynError;
// }
//
// ecmc_can_direction tempDir = DIR_READ;
// if(dir == 1) {
// tempDir = DIR_WRITE;
// }
//
// try {
// grbl->addSDO((uint32_t)nodeId,
// cobIdTx,
// cobIdRx,
// tempDir,
// ODIndex,
// ODSubIndex,
// ODSize,
// readSampleTimeMs,
// name);
//
//
// }
// catch(std::exception& e) {
// printf("Exception: %s. Add PDO failed.\n",e.what());
// return asynError;
// }
// return asynSuccess;
//}
//
//static const iocshArg initArg0_2 =
//{ "Name", iocshArgString };
//static const iocshArg initArg1_2 =
//{ "Node Id", iocshArgInt };
//static const iocshArg initArg2_2 =
//{ "COB id TX", iocshArgInt };
//static const iocshArg initArg3_2 =
//{ "COB id RX", iocshArgInt };
//static const iocshArg initArg4_2 =
//{ "Direction", iocshArgInt };
//static const iocshArg initArg5_2 =
//{ "OD Index", iocshArgInt };
//static const iocshArg initArg6_2 =
//{ "OD sub index", iocshArgInt };
//static const iocshArg initArg7_2 =
//{ "OD size", iocshArgInt };
//static const iocshArg initArg8_2 =
//{ "Read sample time ms", iocshArgInt };
//
//static const iocshArg *const initArgs_2[] = { &initArg0_2,
// &initArg1_2,
// &initArg2_2,
// &initArg3_2,
// &initArg4_2,
// &initArg5_2,
// &initArg6_2,
// &initArg7_2,
// &initArg8_2};
//
//static const iocshFuncDef initFuncDef_2 = { "ecmcCANOpenAddSDO", 9, initArgs_2 };
//static void initCallFunc_2(const iocshArgBuf *args) {
// ecmcCANOpenAddSDO(args[0].sval,
// args[1].ival,
// args[2].ival,
// args[3].ival,
// args[4].ival,
// args[5].ival,
// args[6].ival,
// args[7].ival,
// args[8].ival);
//}
//
///**
// * EPICS iocsh shell command: ecmcCANOpenAddPDO
//*/
//void ecmcCANOpenAddPDOPrintHelp() {
// printf("\n");
// printf(" Use \"ecmcCANOpenAddPDO(<name>, <node id>\n");
// printf(" <name> : Name of master device.\n");
// printf(" <node id> : CANOpen node id of device/master.\n");
// printf(" <cob id> : CANOpen cob id of PDO.\n");
// printf(" <dir> : Direction 1=write and 2=read.\n");
// printf(" <ODSize> : Size of PDO (max 8 bytes).\n");
// printf(" <readTimeoutMs> : Readtimeout in ms.\n");
// printf(" <writeCycleMs> : Cycle time for write (if <= 0 then only write on change).\n");
// printf("\n");
//}
//
//int ecmcCANOpenAddPDO(const char* name,
// int nodeId,
// int cobId,
// int dir,
// int ODSize,
// int readTimeoutMs,
// int writeCycleMs) {
// if(!name) {
// printf("Error: name.\n");
// ecmcCANOpenAddPDOPrintHelp();
// return asynError;
// }
//
// if(strcmp(name,"-h") == 0 || strcmp(name,"--help") == 0 ) {
// ecmcCANOpenAddPDOPrintHelp();
// return asynSuccess;
// }
//
// if(dir > 2 || dir <= 0) {
// printf("Error: invalid dir.\n");
// ecmcCANOpenAddPDOPrintHelp();
// return asynError;
// }
//
// if(ODSize < 0) {
// printf("Error: invalid ODSize.\n");
// ecmcCANOpenAddPDOPrintHelp();
// return asynError;
// }
//
// if(readTimeoutMs < 0) {
// printf("Error: invalid readTimeoutMs.\n");
// ecmcCANOpenAddPDOPrintHelp();
// return asynError;
// }
//
// if(writeCycleMs < 0) {
// printf("Error: invalid writeCycleMs.\n");
// ecmcCANOpenAddPDOPrintHelp();
// return asynError;
// }
//
// ecmc_can_direction tempDir = DIR_READ;
// if(dir == 1) {
// tempDir = DIR_WRITE;
// }
//
// try {
// grbl->addPDO((uint32_t)nodeId,
// cobId,
// tempDir,
// ODSize,
// readTimeoutMs,
// writeCycleMs,name);
// }
// catch(std::exception& e) {
// printf("Exception: %s. Add PDO failed.\n",e.what());
// return asynError;
// }
// return asynSuccess;
//}
//
//static const iocshArg initArg0_3 =
//{ "Name", iocshArgString };
//static const iocshArg initArg1_3 =
//{ "Node Id", iocshArgInt };
//static const iocshArg initArg2_3 =
//{ "COB Id", iocshArgInt };
//static const iocshArg initArg3_3 =
//{ "Direction", iocshArgInt };
//static const iocshArg initArg4_3 =
//{ "ODSize", iocshArgInt };
//static const iocshArg initArg5_3 =
//{ "Read Timeout ms", iocshArgInt };
//static const iocshArg initArg6_3 =
//{ "Write cycle ms", iocshArgInt };
//
//static const iocshArg *const initArgs_3[] = { &initArg0_3,
// &initArg1_3,
// &initArg2_3,
// &initArg3_3,
// &initArg4_3,
// &initArg5_3,
// &initArg6_3
// };
//
//static const iocshFuncDef initFuncDef_3 = { "ecmcCANOpenAddPDO", 7, initArgs_3 };
//static void initCallFunc_3(const iocshArgBuf *args) {
// ecmcCANOpenAddPDO(args[0].sval,
// args[1].ival,
// args[2].ival,
// args[3].ival,
// args[4].ival,
// args[5].ival,
// args[6].ival);
//}
//
void ecmcGrblAddCommandPrintHelp() {
printf("\n");
printf(" Use ecmcGrblAddCommand(<command>)\n");
printf(" <command> : Grbl command.\n");
printf("\n");
}
int ecmcGrblAddCommand(const char* command) {
if(!command) {
printf("Error: command.\n");
ecmcGrblAddCommandPrintHelp();
return asynError;
}
if(strcmp(command,"-h") == 0 || strcmp(command,"--help") == 0 ) {
ecmcGrblAddCommandPrintHelp();
return asynSuccess;
}
if(!grbl) {
printf("Plugin not initialized/loaded.\n");
return asynError;
}
try {
grbl->addCommand(command);
}
catch(std::exception& e) {
printf("Exception: %s. Add command failed.\n",e.what());
return asynError;
}
return asynSuccess;
}
static const iocshArg initArg0_0 =
{ " Grbl Command", iocshArgString };
static const iocshArg *const initArgs_0[] = { &initArg0_0};
static const iocshFuncDef initFuncDef_0 = { "ecmcGrblAddCommand", 1, initArgs_0 };
static void initCallFunc_0(const iocshArgBuf *args) {
ecmcGrblAddCommand(args[0].sval);
}
///**
// * Register all functions
//*/
//void ecmcCANPluginDriverRegister(void) {
// iocshRegister(&initFuncDef_0, initCallFunc_0); // ecmcCANOpenAddMaster
// iocshRegister(&initFuncDef_1, initCallFunc_1); // ecmcCANOpenAddDevice
// iocshRegister(&initFuncDef_2, initCallFunc_2); // ecmcCANOpenAddSDO
// iocshRegister(&initFuncDef_3, initCallFunc_3); // ecmcCANOpenAddPDO
//}
//
//epicsExportRegistrar(ecmcCANPluginDriverRegister);
//
void ecmcGrblPluginDriverRegister(void) {
iocshRegister(&initFuncDef_0, initCallFunc_0); // ecmcCANOpenAddMaster
}
epicsExportRegistrar(ecmcGrblPluginDriverRegister);

View File

@@ -47,56 +47,56 @@ char buffer[EEPROM_MEM_SIZE];
/* Define to reduce code size. */
//#define EEPROM_IGNORE_SELFPROG //!< Remove SPM flag polling.
unsigned char ecmc_mem_to_file();
//unsigned char ecmc_mem_to_file();
// Init file
void ecmc_init_file() {
printf("%s:%s:%d\n",__FILE__,__FUNCTION__,__LINE__);
memset(&buffer[0],0,EEPROM_MEM_SIZE);
ecmc_mem_to_file();
//ecmc_mem_to_file();
}
// Read file to buffer[]
unsigned char ecmc_file_to_mem()
{
//printf("%s:%s:%d EEPROM simulated by file..\n",__FILE__,__FUNCTION__,__LINE__);
FILE* fh = fopen(EEPROM_DUMMY_FILE, "rd");
if (fh == NULL)
{
printf("something went wrong and file could not be opened");
return 1;
}
unsigned char c = 0;
for (int i = 0; i < EEPROM_MEM_SIZE ; i++) {
// Get the characters
buffer[i] = fgetc(fh);
}
fclose(fh);
return 0;
}
//unsigned char ecmc_file_to_mem()
//{
// //printf("%s:%s:%d EEPROM simulated by file..\n",__FILE__,__FUNCTION__,__LINE__);
//
// FILE* fh = fopen(EEPROM_DUMMY_FILE, "rd");
//
// if (fh == NULL)
// {
// printf("something went wrong and file could not be opened");
// return 1;
// }
// unsigned char c = 0;
// for (int i = 0; i < EEPROM_MEM_SIZE ; i++) {
// // Get the characters
// buffer[i] = fgetc(fh);
// }
//
// fclose(fh);
// return 0;
//}
// Write buffer[] to file
unsigned char ecmc_mem_to_file()
{
// printf("%s:%s:%d EEPROM simulated by file..\n",__FILE__,__FUNCTION__,__LINE__);
FILE* fh = fopen(EEPROM_DUMMY_FILE, "w");
if (fh == NULL)
{
printf("something went wrong and file could not be opened");
return 1;
}
for (int i = 0; i < EEPROM_MEM_SIZE ; i++) {
// Get the characters
fputc (buffer[i], fh);
}
fclose(fh);
return 0;
}
//unsigned char ecmc_mem_to_file()
//{
//// printf("%s:%s:%d EEPROM simulated by file..\n",__FILE__,__FUNCTION__,__LINE__);
//
// FILE* fh = fopen(EEPROM_DUMMY_FILE, "w");
//
// if (fh == NULL)
// {
// printf("something went wrong and file could not be opened");
// return 1;
// }
// for (int i = 0; i < EEPROM_MEM_SIZE ; i++) {
// // Get the characters
// fputc (buffer[i], fh);
// }
//
// fclose(fh);
// return 0;
//}
/*! \brief Read byte from EEPROM.
@@ -110,7 +110,7 @@ unsigned char ecmc_mem_to_file()
*/
unsigned char eeprom_get_char( unsigned int addr )
{
ecmc_file_to_mem();
//ecmc_file_to_mem();
//printf("%s:%s:%d addr: %ud, value %d..\n",__FILE__,__FUNCTION__,__LINE__,addr,buffer[addr]);
return buffer[addr];
@@ -142,9 +142,9 @@ void eeprom_put_char( unsigned int addr, unsigned char new_value )
{
//printf("%s:%s:%d addr: %ud, value %d..\n",__FILE__,__FUNCTION__,__LINE__,addr,new_value);
ecmc_file_to_mem();
//ecmc_file_to_mem();
buffer[addr] = new_value;
ecmc_mem_to_file();
//ecmc_mem_to_file();
//char old_value; // Old EEPROM value.
//char diff_mask; // Difference mask, i.e. old value XOR new value.

View File

@@ -57,7 +57,6 @@ void gc_init()
void gc_sync_position()
{
printf("%s:%s:%d:\n",__FILE__,__FUNCTION__,__LINE__);
system_convert_array_steps_to_mpos(gc_state.position,sys_position);
}

View File

@@ -76,7 +76,8 @@ void protocol_main_loop()
for (;;) {
// Process one line of incoming serial data, as the data becomes available. Performs an
// initial filtering by removing spaces and comments and capitalizing all letters.
while((c = serial_read()) != SERIAL_NO_DATA) {
delay_ms(1);
while((c = serial_read()) != SERIAL_NO_DATA) {
if ((c == '\n') || (c == '\r')) { // End of line reached
//printf("NEW_CHAR\n");
protocol_execute_realtime(); // Runtime command check point.

View File

@@ -215,6 +215,7 @@ void ecmc_write_command_serial(char* line) {
for(int i=0; i<strlen(line);i++) {
ecmc_add_char_to_buffer(line[i]);
}
free(line);
}
void serial_reset_read_buffer()

View File

@@ -234,6 +234,7 @@ void *ecmc_dummy_thread(void *ptr) {
}
ecmc_grbl_main_rt_thread();
}
printf("%s:%s:%d Positions(x,y,z)=%d,%d,%d..\n",__FILE__,__FUNCTION__,__LINE__,sys_position[X_AXIS], sys_position[Y_AXIS],sys_position[Z_AXIS] );
delay_ms(1);
}

View File

@@ -30,6 +30,24 @@ ${SCRIPTEXEC} ${ecmccfg_DIR}loadPlugin.cmd, "PLUGIN_ID=0,FILE=${ECMC_PLUGIN_FILN
epicsEnvUnset(ECMC_PLUGIN_FILNAME)
epicsEnvUnset(ECMC_PLUGIN_CONFIG)
ecmcGrblAddCommand("G0X10Y100");
ecmcGrblAddCommand("$");
ecmcGrblAddCommand("G0X10Y100");
ecmcGrblAddCommand("$G");
ecmcGrblAddCommand("G4P4");
ecmcGrblAddCommand("G1X20Y200F20");
ecmcGrblAddCommand("G4P4");
ecmcGrblAddCommand("G2X40Y220R20");
ecmcGrblAddCommand("$");
##############################################################################
## PLC 0
# $(SCRIPTEXEC) $(ecmccfg_DIR)loadPLCFile.cmd, "PLC_ID=0, SAMPLE_RATE_MS=1000,FILE=./plc/can.plc")