Transmit Long 4Byte Int. with Simple Message Syst.


i have the problem to transmit a 4byte integer (some millis) from my computer to arduino. transmit integers to 32767 are no problem, but bigger ones are.

i'm using the simple message system library at the rest from the arduino application.

is there any way to extend the simp. mess. sys.?

eny idea how to work a round this limitation?

thx maximars

I’m not sure about the byte ordering you want, but something like this should work:

void messageSendLong( long msg ) {
  messageSendInt( (int) (msg & 65535) ); // Send LSW
  messageSendInt( (int) (msg >> 16) );   // Send MSW

long messageGetLong() {
  long ans;
  ans = messageGetInt();        // Get LSW
  ans |= (messageGetInt() << 16); // Get MSW
  return ans;

It should really be integrated into SimpleMessageSystem to allow decent error checking (do we even have an entire long sitting in the input buffer?)

I haven’t tried this code myself, so it’ll want some testing. Hope it helps.

EDIT: Having scanned the SMS code for a little longer, I see that this method is possibly not in keeping with the whole SMS philosophy, (it sends two messages, but uses them as one value) but it should still work for now.

hi jlaw

i did runn into some problems with your solution. i think i did some mistakes to turn your code in to basic. i’m interfacing with realbasic to arduino. i found this solution.

on the realbasic side:

 dim msg as string
 dim m As memoryBlock
  m.long(0)=millisec // assign the 4 byte integer to send

  // concatenate the message to send 
  msg="s"+str(m.byte(0))+" "+str(m.byte(1))+" "+str(m.byte(2))+" "+str(m.byte(3))+chr(13) // first char i use to dedect wich function to call

  serial1.write msg
on the arduino side i did something like this:

void setRaceTime(){
  RaceTime = messageGetInt();
  RaceTime <<= 8;
  RaceTime |= messageGetInt();
  RaceTime <<= 8;
  RaceTime |= messageGetInt();
  RaceTime <<= 8;
  RaceTime |= messageGetInt();

   Serial.println(RaceTime); // just to check the result


perhaps you have to check the bytes fist so you dont send a CR on the wrong position mistakenly.
i don’t know.

thank you