Storing multiple int values as one int.

Hi there,

I'm wondering if it's possible to store multiple numbers as one int, without adding them up.

The reason I ask is because I am trying to communicate with a device over RS232, and have been asked to send the data as one package, so that I am not printing individually each value that must be sent. Instead a whole block of numbers will be sent at once.

I have tried looking into pointers, but I am unsure how to use it effectively. I guess I would need to make sure each intergers memory location was right next to eachother, so I could print from register address 0 to 7 lets say. But even then, will the print function still not be seperated as the pointer moves to each address?

Any help is appreciated,

DopeyS

Tell us what you want to do, not how you think you should do it.

Hi,

I am trying to send 7 integers from my Arduino Nano through a MAX232 to a RS232 device without individually printing each integer. I'm trying to avoid code where the Arduino finds the address, prints the value, finds new address, prints new value. Ideally it would find one address and print all data in it.

Kind Regards,
DopeyS

To send multiple values one after the other over serial you just have to Serial.print them in the order you want them, for example:

Serial.print(value1);
Serial.print(value3);
Serial.print(value4);

Doing that will send the ASCII values of each variable to the serial port in the order you list them.

I'm trying to avoid code where the Arduino finds the address, prints the value, finds new address, prints new value.

Why?

PerryBebbington:
Why?

Hi Thanks for helping :slight_smile:
This has been part of the instructions given to me by those using the RS232 device. I believe it is to do with how it's programmed and breaks in between will cause problems.
Cheers

DopeySnailS:
Hi Thanks for helping :slight_smile:
This has been part of the instructions given to me by those using the RS232 device. I believe it is to do with how it's programmed and breaks in between will cause problems.
Cheers

There won't be any breaks if you do as I suggested, it takes AGES in processor time to output a single byte over serial, let alone the whole string. The processor will probably have put all the data into the serial buffer ready to send before the first byte has finished sending.

That said, anything using serial / RS232 should be able to cope with short breaks without any difficultly, if it can't then it's crap baldly designed.

there are many forms of transmissions that send packets of binary data not at ascii characters. (packed) data structures may be used to describe specific packets. the structure elements populated with various data including a message ID, possibly a length field and transmitted.

data is received in binary form and copied into the same structure at the receiving end and value extracted as elements from that structure.

the difficulty with rs-232 transmission is recognizing the start/end of a packet and having some means to verify correctly capturing the packet possibly using some form of check bytes.

CMRInet is an example used for sending packets over serial interfaces between a PC and multiple nodes using hardware such as Arduinos

PerryBebbington:
To send multiple values one after the other over serial you just have to Serial.print them in the order you want them, for example:

Serial.print(value1);

Serial.print(value3);
Serial.print(value4);




Doing that will send the ASCII values of each variable to the serial port in the order you list them.

…but it’s tough to pick them apart at the far end. Use commas, or spaces, or…anything that doesn’t look like a number, or part of a number

This has been part of the instructions given to me by those using the RS232 device.

Can we see those ‘instructions’ ?
It really sounds like you may be over complicating things.

I’m wondering if it’s possible to store multiple numbers as one int

What is the range of numbers that you need to send ?

Is it 0 to 255, for instance ?

…but it’s tough to pick them apart at the far end. Use commas, or spaces, or…anything that doesn’t look like a number, or part of a number

Unless I missed it the OP has not said anything about that, just that s/he doesn’t want gaps, I’ve dealt with the gaps. Obviously there is more to it than we have been told.

Dopey, you will find this useful: Serial input basics

TheMemberFormerlyKnownAsAWOL:
Use commas, or spaces, or...anything that doesn't look like a number, or part of a number

That's only useful if you're sending them as ASCII. If you need binary format, then you must be a little more clever. Of course, the Problem Description and Requirements have been so poorly-state, who knows?