如何在 Arduino 上拆分 ECU 字符串数据?
How to split ECU string data on Arduino?
我有一个关于从串行端口拆分发动机控制系统字符串数据的问题。通讯协议说明如下
示例:
检索显示在 FADEC 的 LCD 屏幕上的数据。如果命令是 RSD
,那么输出将是:
**C7h 2Ch 52h 53h 44h 2Ch 0Dh**
C7h -> Sync
2Ch -> “,” Separator
52h -> “R”
53h -> “S”
44h -> “D”
2Ch -> “,” Separator
0Dh -> CR, last byte.
ECU 将 return 两个字符串。第一个是收到的命令的副本,然后是请求的数据。在上面的例子中,它将 return:
**C7h, RSD, 0Dh**
C7h -> Sync byte
2Ch -> “,” Separator
Payload in ASCII “TrimLow EGT 20CRpm 50.000Pw=124”
2Ch -> “,” Separator
0Dh -> CR, last byte.
我以字符串格式读取屏幕上的所有数据。当我向ECU发送RCV
时,它会根据上面的表格return RPM、温度、泵电压、电池电压和油门。
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
和数据表(第 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]);
}
}
如何在从 ECU 返回的数据包中分离 RPM、EGT °C、泵电压、电池电压和油门百分比?判别过程结束后,我会通过第二个串口发送给LabView。 RPM 值可以是 6 位数字(大约 120000 RPM),排气温度是 3 位数字(EGT 800 °C),这些数字可能会丢失,因为除节气门值外,所有数字均为零。你能分享一个样本吗?谢谢。
图片:
同样的答案是;
#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]) : "";
}
我有一个关于从串行端口拆分发动机控制系统字符串数据的问题。通讯协议说明如下
示例:
检索显示在 FADEC 的 LCD 屏幕上的数据。如果命令是 RSD
,那么输出将是:
**C7h 2Ch 52h 53h 44h 2Ch 0Dh**
C7h -> Sync
2Ch -> “,” Separator
52h -> “R”
53h -> “S”
44h -> “D”
2Ch -> “,” Separator
0Dh -> CR, last byte.
ECU 将 return 两个字符串。第一个是收到的命令的副本,然后是请求的数据。在上面的例子中,它将 return:
**C7h, RSD, 0Dh**
C7h -> Sync byte
2Ch -> “,” Separator
Payload in ASCII “TrimLow EGT 20CRpm 50.000Pw=124”
2Ch -> “,” Separator
0Dh -> CR, last byte.
我以字符串格式读取屏幕上的所有数据。当我向ECU发送RCV
时,它会根据上面的表格return RPM、温度、泵电压、电池电压和油门。
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
和数据表(第 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]);
}
}
如何在从 ECU 返回的数据包中分离 RPM、EGT °C、泵电压、电池电压和油门百分比?判别过程结束后,我会通过第二个串口发送给LabView。 RPM 值可以是 6 位数字(大约 120000 RPM),排气温度是 3 位数字(EGT 800 °C),这些数字可能会丢失,因为除节气门值外,所有数字均为零。你能分享一个样本吗?谢谢。
图片:
同样的答案是;
#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]) : "";
}