0

I have a question for splitting engine control system string data from a serial port. The communication protocol description is below.

Example: To retrieve the data displayed on the LCD screen of the FADEC. If the command is RSD, then the output would be:

**C7h 2Ch 52h 53h 44h 2Ch 0Dh**

C7h -> Sync
2Ch -> “,” Separator
52h -> “R”
53h -> “S”
44h -> “D”
2Ch -> “,” Separator
0Dh -> CR, last byte.

The ECU will return two strings. The first, a copy of the command received, followed by the data requested. In the above example, it will return:

**C7h, RSD, 0Dh**
C7h -> Sync byte
2Ch -> “,” Separator

Payload in ASCII “TrimLow EGT 20CRpm 50.000Pw=124”
2Ch -> “,” Separator
0Dh -> CR, last byte.

I read all the data on the screen in string format. When I send RCV to the ECU, it will return RPM, temperature, pump voltage, battery voltage and throttle according to the above form.

Xicoy description: ( Command, Meaning, Payload)

RCV Read Current Values RPM, EGT in ºC, Pump Power, Voltage of Battery,Throttle %

    byte veri[]= { 0xC7, 0x2C, 0x52, 0x43, 0x56, 0x2C, 0x0D }; // for RCV 

And datasheet (page 5-6-7): http://www.xicoy.com/SerialAdapt1_0.pdf

#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX, TX
int i=0;
byte veri[]= { 0xC7, 0x2C, 0x52, 0x43, 0x56, 0x2C, 0x0D }; // RCV
int myTimeout = 100;

void setup() {
  Serial.begin(9600);
  mySerial.begin(9600);
  mySerial.setTimeout(myTimeout);
}

void loop() {
  Serial.println(mySerial.readString());
  for(i=0;i<7;i++)
  {
    mySerial.write(veri[i]);
  }
}

How can I separate RPM, EGT °C, pump voltage, battery voltage and throttle % in the data packet that is coming back from the ECU? After the discrimination process, I will send it to LabView via the second serial port. The RPM values can be 6 digits (approx. 120000 RPM) and the exhaust gas temperature is 3 digits (EGT 800 °C), the figures may be missing because all are zero except throttle value. Can you share a sample? Thanks.

Picture:

2
  • Does arduino have CSV parsing library? I am not very much familiar with Arduinos. Commented Jul 10, 2017 at 11:25
  • 1
    A normal sscanf could work. Since Arduino uses a variant of C++ there might be other ways to get the substrings. Commented Jul 10, 2017 at 11:26

1 Answer 1

-1

Also answer is ;

#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11); // RX, TX

int i=0;
byte veri[]= { 0xC7, 0x2C, 0x52, 0x43, 0x56, 0x2C, 0x0D }; // RCV
int myTimeout = 10;  
String veri2[]={};
void setup() {
Serial.begin(9600);
while (!Serial) {
}
analogWrite(5,250);
mySerial.begin(9600);
mySerial.setTimeout(myTimeout);
}

void loop() { // run over and over

for(i=0;i<7;i++)
{
mySerial.write(veri[i]);
}

String split = mySerial.readString();
String word3 = getValue(split, ',',0);
Serial.println(word3);
for(i=0;i<7;i++)
{
mySerial.write(veri[i]);
}

String  split2 = mySerial.readString();
String word4= getValue(split2, ',',1);
Serial.println(word4);
 /*
split = mySerial.readString();
word3 = getValue(split, ',',2);
Serial.println(word3);
split = mySerial.readString();
word3 = getValue(split, ',',3);
Serial.println(word3);
split = mySerial.readString();
word3 = getValue(split, ',',4);
Serial.println(word3);
split = mySerial.readString();
word3 = getValue(split, ',',5);
Serial.println(word3);
split = mySerial.readString();
word3 = getValue(split, ',',6);
Serial.println(word3);
split = mySerial.readString();
word3 = getValue(split, ',',7);
Serial.println(word3);
}

*/

 String getValue(String data, char separator, int index)
 {
 int found = 0;
 int strIndex[] = {0, -1};
 int maxIndex = data.length()-1;

 for(int i=0; i<=maxIndex && found<=index; i++){
 if(data.charAt(i)==separator || i==maxIndex){
    found++;
    strIndex[0] = strIndex[1]+1;
    strIndex[1] = (i == maxIndex) ? i+1 : i;
 }
 }

 return found>index ? data.substring(strIndex[0], strIndex[1]) : "";
 }
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.