私はArduinoとCプログラミングにとても慣れていません。
GPSスピードメーターを作成していて、シリアルを読み込んで、サブストリングから値を保存し、シリアル経由でエコーバックしようとしています。
現在、部分文字列の保存に問題があります。
<
との間でデータを取得できるようになり>
ました。しかし、データはそのようには入りません。これはNMEAデータストリームであり、必要なデータはとの間,N,
です,K,
。
だから私はとで置き換えようとして,N,
き<
まし,K,
た>
。
それを機能させることはできません。私は得るerror: request for member 'replace' in 'c', which is of non-class type 'char'
これがこれまでの私のコードです...
int indata = 0;
int scrubdata = 0;
char inString[32];
int stringPos = 0;
boolean startRead = false; // is reading?
void setup() {
Serial.begin(4800);
}
void loop() {
String pageValue = readPage();
Serial.print(pageValue);
}
String readPage(){
//read the page, and capture & return everything between '<' and '>'
stringPos = 0;
memset( &inString, 0, 32 ); //clear inString memory
while(true){
if (Serial.available() > 0) {
char c = Serial.read();
c.replace(",N,", "<");
c.replace(",K,", ">");
if (c == '<' ) { //'<' is our begining character
startRead = true; //Ready to start reading the part
}
else if(startRead){
if(c != '>'){ //'>' is our ending character
inString[stringPos] = c;
stringPos ++;
}
else{
//got what we need here! We can disconnect now
startRead = false;
return inString;
}
}
}
}
}