Sending multiple Hex commands

Sorry if I'm asking another retarded question, but I'm trying to create a library to control a DVR and am having some prgramming issues in setting up the constants.

Its fine if I only need to send a command such as 0x20, but cant understand how to contruct the rest of it to incorporate a string of commands such as 0x20 0x02 0x22. I used the code as below but get errors:

const unsigned char RECSTART = 0x20 0x02 0x22;

but no luck, even if I encapsulate it in brackets. I have a huge lis tof these commands and have so far just been doing some testing to see how they get sent out..Ideally I need to send those 3 bytes as if I was entering 20 02 22 into the RS232 terminal program..

Any ideas?

const unsigned char RECSTART = 0x20 0x02 0x22;

Its a char it is only one byte so that won't work.

but no luck, even if I encapsulate it in brackets.

It's still a char, you want a string.

It's still a char, you want a string.

I think you want an array. The character array does not necessarily need to be NULL terminated, which is what would make it a string.

True but if you want to encapsulate it in brackets then you need a string.

There actually isn't enough information to give a real answer as to what he needs to do because it is not clear what he wants to do.

Sorry for the confusion as I dont think I have explained myself correctly.

I need to send a range of commands over the serial link to a device according to its protocol listing. For instance, for me to intialise a record on this DVR I need to send 0x20 0x02 0x22 together for it to carry out the operation.
If I use the code as I showed earlier:

const unsigned char RECSTART = 0x20 0x02 0x22;

and I call it later in the code using:

Serial1.print(RECSTART);

but it throws up errors. I have tried the string theory (:P) but it also throws up errors. So far the only way I can get it to work is to split the command in to 3 different variables and indiviually send them over the port, which seems long winded but is the only way, with my limited knowledge it seems to work. i.e.

const unsigned char RECSTART1 = 0x20;
const unsigned char RECSTART2 = 0x02;
const unsigned char RECSTART3 = 0x22;

and then send it using:

Serial1.print(RECSTART1); Serial1.print(RECSTART2); Serial1.print(RECSTART3);

I am looking for a better way to do this, as there are other commands later on which are much longer than just 3 bytes, and I cant be doing it like this.

Thanks in advance.

P.S. Does anybody of a decent book I could buy on the Arduino?

If I use the code as I showed earlier:
const unsigned char RECSTART = 0x20 0x02 0x22;
and I call it later in the code using:
Serial1.print(RECSTART);
but it throws up errors.

Yes and I told you why.

I am looking for a better way to do this

You can use a string to output all the commands in one instruction.

I have tried the string theory but it also throws up errors.

That is because you are doing it wrong, the errors tell you what the compiler doesn't like. That is what they are for.
How are you constructing the string?

try this:-

  char command [] = { 0x20,  0x20, 0x22 ,'\0' };

Then you can just print it.

try this:-
There needs to be a comma before the \0.

Corrected. :slight_smile: