Hi there.
i have on Serial port data with 17bytes long... it 17 bytes long constantly.... But i need to get last 4 of those 17 in do some work on it.... They are always difrent each time you read...
Like i understand it has to be assighned by arrays. But i can't get it how it happans at all.
This is some one else code it doesn't work for me but explains a lot of im trying to work on..
inChar=Serial1.read();
rxData[rxIndex]='\0';
Seems like it is assignment but it so stuped way and don't get it how thought it's assighns..
Again the inChar contains the answer from device which is 17 characters long always
but 4 of those alwaus difrent each time you read and those 4 needs to be a variables for some more code...
So how i breake the Serial read basicly in bytes and assign them by numbers???
char rxData[20];
char rxIndex=0;
void getResponse(void){
char inChar=0;
//Keep reading characters until we get a carriage return
while(inChar != '\r'){
//If a character comes in on the serial port, we need to act on it.
if(Serial1.available() > 0){
//Start by checking if we've received the end of message character ('\r').
if(Serial1.peek() == '\r'){
//Clear the Serial buffer
inChar=Serial1.read();
//Put the end of string character on our data string
rxData[rxIndex]='\0';
//Reset the buffer index so that the next character goes back at the beginning of the string.
rxIndex=0;
}
//If we didn't get the end of message character, just add the new character to the string.
else{
//Get the new character from the Serial port.
inChar = Serial1.read();
//Add the new character to the string, and increment the index variable.
rxData[rxIndex++]=inChar;
}
}
}
}