I am writing a program that amongst other things needs to speak to an Alicat mass flow controller.
I have a packet structure that I'm passing from a Free Pascal program.
At the point where I have a problem I am passing a character array with "234567" - 6 digits.
The first digit is a unit number and identifies controller B correctly.
So now I have a string with "B" in it and I want to concatenate the 34567 ... I really can't see why the values in glCommandBody are not being copied across in the for loop.
I tried strcat and strncpy, but no joy.
And maybe I'm not doing the carriage return properly either ... (a newline is not required)
Thanks in advance.
void setAlicat ()
char emptyStr ;
char tStr ;
int unitNumber ;
int ido ;
unitNumber = glCommandBody - '0' ; //char glCommandBody  - global
strcpy (emptyStr,"") ;
case 1: strcpy (emptyStr, "A") ; break ; //works
case 2: strcpy (emptyStr, "B") ; break ;
case 3: strcpy (emptyStr, "C") ; break ;
} //end of switch
//Now extract flow setting to send
// Serial.println (glCommandBody) ; //contains "234567"
// Serial.println (strlen(glCommandBody)) ; //returns 6
for (ido=1; ido == strlen (glCommandBody) - 1; ido++)
emptyStr[ido] = glCommandBody[ido] ;
// Serial.println (emptyStr) ; //Returns "B" !
emptyStr [strlen (glCommandBody)] = '\0' ;
Serial.println (emptyStr) ; //Still "B"
// emptyStr [strlen(emptyStr)-1] = '\r' ; //Put a carriage return on
// Serial.println (emptyStr) ; //You guessed it: "B"
Serial2.print ( tStr ) ; //Alicat can't make head or tail of it
Serial.println ( tStr) ;