私は、シリアルポート上のグリッパーと通信するためのC++プログラムを作成しています。符号なしの文字連結
"unsigned char [8]"タイプのバッファを送信する必要がありますが、この8バイトのうち4つはキーボードから入力され、2はCRCで計算されます。
したがって、8バイトのunsigned charの1つのバッファでいくつかの部分を連結するにはどうすればよいですか?例えば
:DLEN
、CMD
、data
とCRC
の労働組合がある{0x05,0x01,0x00,0x01,0x20,0x41,0xFF,0x41}
:
unsigned char buffer[8];
----
unsigned char DLEN[1]={0x05};
----
unsigned char CMD[1]={0x01};
----
unsigned char data[4]={0x00,0x01,0x20,0x41};
----
unsigned char CRC[2]={0xFF,0x41};
----
は、どのように私はこのバッファを得ることができますか?
か 'バッファ[0] = DLEN [0];バッファ[1] = CMD [0]。 std :: copy(begin(data)、end(data)、buffer + sizeof DLEN + size of CMD)。 std :: copy(begin(CRC)、end(CRC)、buffer + size of DLEN + size of data + sizeof data); '(別々の行に分割されます) – bames53