Hi guys.
I'm trying desperately to figure this out.
In Visual Basic I use split() function. In C there is none!
Or is it?
VB.net code
Dim txtData As String = SerialPort1.ReadLine
RichTextBox1.Text = txtData
Dim myFile As String = txtData
myFile = Replace(myFile, " ", "")
Dim i As Integer
Dim aryTextFile() As String
aryTextFile = myFile.Split(",")
'Sett inn sensorene her
For i = 0 To UBound(aryTextFile)
MsgBox(i)
Next i
MMh, you want to read Serial and get its values into an array... it seems so to me.
So you have to declare an array, and then simply put the values into it.
ahm, seems that you want to get rid of " "....
First Step I think...
char myvalues[count of Values]; // Declare a Array with X cells.
int counter=0; // Declare a counter which holds ints
void setup(){
Serial.beginn(19200); //Serial.open with 19200 Speed.
}
void loop(){
myvalues[counter]=Serial.read(); //Read a Value and put it into the Array.
counter++; // Increase Counter to get to the next Arraycell.
delay(50); // This slows down, to avoid a bufferoverrun.
}
Thats maybe buggy (not tested),
AND it's NOT the best way....
but with this in scheme you should get
the serial incomming Values into a onedimensional Array.
The strtok function can be used, in a while loop, to extract tokens that are delimited by any character(s).
char test[] = "This is a string with many words";
char *token = strtok(test, " ");
// token will be "This"
while(token)
{
// Do something with this word
token = strtok(NULL, " "); // Use NULL as the 1st argument to keep parsing the same string
// token will be is, a, string, etc. in order
}