I need a command buffer, where do I start?

I'm pretty new to programming a large project.

My project needs a command buffer to keep a list of commands until the current one finishes.

What type of object do I use for this? The commands are strings coming in from a serial connection.

Basically the project is like a 3D printer but smaller scale and difficulty.

Why not operate on a command, when it finishes, request the next command?

You could store a large number of commands to an SD card, read them back as needed.

You want a queue or FIFO.

naps1saps:
My project needs a command buffer to keep a list of commands until the current one finishes.

Why?

Where will the commands be coming from?

Give some examples of the commands?

How many commands do you want to store in your buffer? There is not much memory on an Arduino.

I must say I am inclined to agree with @LarryD.

…R

Do you have examples of the strings? If the target device interprets them as data, you might save memory recording/storing that rather than the strings, if you can pass the data to them.

Frinstance...if strings are left, right, up, and down but machine translates to 0001, 0010, 0100 and 1000...

Beware, I’m new to this myself, entirely possible I’m talking crap...

There aren't a lot of places in arduino where you might want to use a dynamically-allocated linked list, but this might be one of them. The list item would either contain the raw command string, or some sort of structure containing the parts of the command parsed out. Might even be worthwhile using a union for the different commands, if they have different structures.

If you use dynamic allocation, remember a) to free things, and b) to handle the case when there is no available memory.

The serial device itself already does buffering, so you should not require a separate command queue. If you can't process the commands fast enough to keep the serial buffer from over-flowing, then implement some kind of handshake with the sender, to tell it to stop sending commands until you catch up. That can be something like XON/XOFF, or a simple ACK sent as each command completes, which tells the sender it's ok to send the next command. I've written Arduino code for devices that process text-based commands from a dozen or more sources simultaneously, and NONE of them queue commands on the Arduino.

Regards,
Ray L.

RayLivingston:
If you can't process the commands fast enough to keep the serial buffer from over-flowing, then implement some kind of handshake with the sender, to tell it to stop sending commands until you catch up.

There seems to be another Thread running in parallel that has a somewhat similar theme so I am getting mixed up :slight_smile:

I have a small CNC system in which each message for a single move fits comfortably in the serial input buffer and the Arduino asks for a new message BEFORE it starts implementing the current move. Then when the current move completes the data for the next move is already in the buffer.

...R