moha_sa Posted February 12, 2022 Share Posted February 12, 2022 Hi, I am receiving this error "implicit declaration of function 'malloc' " when using servoData = (char *)malloc(CHAR_BUF_SIZE_3*sizeof(unsigned char)); in a user-defined ServoCtrl algorithm in the Realtime Routines folder in the IDE. My goal is to use sprintf and send commands to be able to print a float variable to the unsolicited message window and monitor its value as below: char *servoData; servoData = (char *)malloc(CHAR_BUF_SIZE_3*sizeof(unsigned char)); sprintf(servoData,"desired position is %f \n", 230.5); Send(SEND1_PORT,servoData); Any idea how I can still use "malloc" without the error to run the "Send" command? Thanks. Quote Link to comment Share on other sites More sharing options...
Omron Forums Support Posted February 14, 2022 Share Posted February 14, 2022 The following user servo routine will run one time (if applied to motor 0) and send a message on buffer 1. double MyServo(struct MotorData *Mptr) { char MyCharArray[100]; MyCharArray[0]='H'; Send(1,&MyCharArray); pshm->Motor[0].ServoCtrl = 0; return 0; } Malloc should not be included in usercode.c. Any time malloc is used, free must also be used to free up that memory. free(servoData); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.