Using a buffer of strings to send serial commands

Hello,

With an Arduino Mega, I am communicating with a motor controller that provides an acknowledge char after it receives a command. Sending subsequent commands without an Ack is not recommended.

I want to create a function that uses a buffer to store strings (commands) that need to be transmitted. The transmission will only occur when the drive is ready for it via receiving an Ack char.

Can someone give me some direction? Should this be a FILO structure? Should I put it in a timer or can I run it continuously in the main loop. Are there any functions that can help with this, or do I have to implement this bluntly.

Thank you

HI gelman,

which solution fits best depends on the details how thi scommunication shall work.
What's the minimum time between two commands?
From what you have described so far
I understand

a "command" (how many characters?) is send to the motor-controller
motorcontroller sends an ACK-answer (how many characters?) back
your code should wait for the ACK and then send the next command

best regards Stefan

I would suggest using the "F" macro for your strings. Serial.print(F(Hello World)); then put the print statement etc in a function. When your main code determines the response it simply calls the appropriate function. Example:
void wilber(){Serial.print(F(Hello World));}. In your main code wilber(); will call the function. You can simply set it up as if this then do this else .... or use a switch case structure (switch...case - Arduino Reference" or whatever you like. The link will explain the switch case. The "F" macro uses minimal RAM and unless you have a lot of code you will have a surplus of flash which is where this will go. On a side note if you do not use the "F" macro the strings still are stored in flash but moved to RAM when it starts up.