thijse / Arduino-CmdMessenger

CmdMessenger Communication library for Arduino & .NET
Other
208 stars 87 forks source link

The available() should return Current!=null; #13

Open MikeBlueIce opened 7 years ago

MikeBlueIce commented 7 years ago

For variable number of arguments, this code will not work:

while (cmdMessenger.available())
{
      int curNo=cmdMessenger.readInt16Arg();

      // Do something with this number.
}

It will skip 1 parameter at a time. Was this function intended for this?

thijse commented 7 years ago

Honestly, if forgett why I available goes to the next parameter. I do not see samples using it. I will think on your suggestion.

Palatis commented 7 years ago

I find this "feature" annoying, too... :-P

sigmaeo commented 6 years ago

Me too. Instead of: if( cmdMessenger.available() ) { value1 = cm.readInt32Arg(); if( cmdMessenger.available() ) value2 = cm.readInt32Arg(); }

One have to do it this way: ui32 = cm.readInt32Arg(); if( cm.isArgOk() ) { value1 = ui32; ui32 = cm.readInt32Arg(); if( cm.isArgOk() ) ui32 = cm.readInt32Arg(); }

If I send the command string (command-id=0): 0,1,2,3,4,5;

The first example catches: value1=2 and value2=4

The second example catches: value1=1 and value2=2 as expected.