請問師傅 ClientSocket 接收的問題
我用ClientSocket 來接收網路模組 CONVERTER
CONVERTER 是SERVER端 跟溫控器做通訊
這是我發送出去給 溫控器的命令
unsigned char buf[ 8 ];
buf[ 0 ] = 0x52;
buf[ 1 ] = 0x01;
buf[ 2 ] = 0x00;
buf[ 3 ] = 0x00;
buf[ 4 ] = 0x00;
buf[ 5 ] = 0x00;
buf[ 6 ] = buf[ 0 ]+buf[ 1 ]+buf[ 2 ]+buf[ 3 ]+buf[ 4 ]+buf[ 5 ];
ClientSocket1->Socket->SendBuf( buf, 7 );
這是我要接收溫控器送回的命令 讀取BUF
void __fastcall TForm1::ClientSocket1Read(TObject *Sender,
TCustomWinSocket *Socket)
{
char receiveBuf[50];
int receiveLen = Socket->ReceiveLength();
Socket->ReceiveBuf( receiveBuf, receiveLen );
AnsiString display_string;
for( int i = 0; i <receiveLen ; i ++ )
{
display_string +=IntToHex( receiveBuf[ i ], 2 )+" ";
Sleep(100);
}
Memo1->Lines->Add( display_string );
Edit4->Text=receiveLen;
}
正常收回的命令應該為 07 4D 01 00 00 03 E8 39
可是每次收回 都會變成 07 4D 01 00 00 FFFFFF03 FFFFFFE8 39
都會多FFFFF 請教各位師傅這是怎麼回事呢 還是有更好的辦法來收回命令?? 拜託各位師傅解答
[解决办法]
FFFFFF是因为默认32位,提取出了他的高位数据去掉就可以了。
[解决办法]
char receiveBuf[50];
改为
unsigned char receiveBuf[50];