觅风论坛
标题:
ESP8266与单片机通讯
[打印本页]
作者:
awdjzm
时间:
2022-7-24 01:59
标题:
ESP8266与单片机通讯
#include <SoftwareSerial.h>
SoftwareSerial Serialb;
void setup() {
Serial.begin(9600);
Serialb.begin(9600, SWSERIAL_8N1, 12, 13 );
}
void loop(){
String Bms_rx = Bms_tx("A5409808000000000000000085");
Serial.println(Bms_rx);
}
String Bms_tx(String data){
for (int i1=0,ii=0;i1 < 13; i1++) {
String data1 = "0x"+data.substring(ii,ii+2)+"\0";
char b[5]={};char a={};int iii=0;
for (int i2=0;i2 < data1.length(); i2++) {
b[iii++] = data1.charAt(i2);
a = strtol(b, 0, 16);
}
Serialb.write(a);
ii=ii+2;
}
delay(500);
String rx_data0,rx_data1;
while (Serialb.available()>0){
rx_data0 = String(Serialb.read(),HEX);
if(rx_data0.length() == 1 ){
rx_data1 += "0" + rx_data0;
}else{rx_data1 += rx_data0;}
delay(5);
}
if (rx_data1 != ""){
rx_data1.toUpperCase();
return rx_data1;
}
return "BmsTX_ERR";
}
欢迎光临 觅风论坛 (https://www.eyyba.com/)
Powered by Discuz! X3.4