MFC單文件之串列埠資料傳送和接收的校驗

2021-07-30 12:46:55 字數 1312 閱讀 1291

1、傳送和接收訊號陣列結構:

0xaa55(cmd)(data1, data2,……,data32)(check1)(check2);

2、cmd、data、check範圍:01-ff

3、所有資料加起來的和得到的高位為(check1),低位為(check2),然後收到資料方再累加一次與(check1)(check2)進行比較,可以有效防止資料出錯,出錯概率為1/256*1/256。

怎麼把累加得到的三位元組或者四位元組的16進製制數拆成兩半分別放置呢,用乙個&就可以完美實現了。

data37 =(data36 & 0xff00) >> 8, data38 = (data36 & 0xff);
cbytearray receivedata;

int receivedatalen;

receivedatalen = str2hex(buffer, receivedata);

int data36 = receivedata[0] + receivedata[1] + receivedata[2] + receivedata[3] + receivedata[4] + receivedata[5] + receivedata[6] + receivedata[7] + receivedata[8] + receivedata[9]

+ receivedata[10] + receivedata[11] + receivedata[12] + receivedata[13] + receivedata[14] + receivedata[15] + receivedata[16] + receivedata[17] + receivedata[18] + receivedata[19]

+ receivedata[20] + receivedata[21] + receivedata[22] + receivedata[23] + receivedata[24] + receivedata[25] + receivedata[26] + receivedata[27] + receivedata[28] + receivedata[29]

+ receivedata[30] + receivedata[31] + receivedata[32] + receivedata[33] + receivedata[34],

data37 = (data36 & 0xff00) >> 8, data38 = (data36 & 0xff);

if ((receivedata[35] == data37) && (receivedata[36] == data38))

}

MFC單文件之串列埠通訊實現16進製制資料的傳送和接收

void cdlg ci onbnclickedstart void cdlg ci onbnclickedloaddata3a m mscomm ci.put commport flag 選擇com m mscomm ci.put inbuffersize 1024 接收緩衝區 m mscomm ...

Python串列埠資料打包傳送STM32接收資料解析

嘗試使用python中的struct.pack函式打包資料通過串列埠傳送,由stm32接收解析。1 struct.pack struct.pack用於將python的值根據格式符,轉換為字串 因為python中沒有位元組 byte 型別,可以把這裡的字串理解為位元組流,或位元組陣列 其函式原型為 s...

Http傳送單條資料和傳送多條資料

此處使用的是springboot 單條資料 服務端 public string getsentimentanalysisresultpost1 requestbody string text return 客戶端 public static string postrequest string url...