|
public byte[] CSMessageEncode(params int[] MessageList)
{
StringBuilder stringBuilder = new StringBuilder();
foreach (int MessageNum in MessageList)
{
stringBuilder.Append(Convert.ToString(MessageNum,16));
stringBuilder.Append("%");
}
string str = stringBuilder.ToString();
string[] chars = str.Split(new char[] { '%' }, StringSplitOptions.RemoveEmptyEntries);
byte[] writebuffer = new byte[chars.Length];
for(int counter=0;counter<chars.Length;counter++)
{
writebuffer[counter] = Convert.ToByte(chars[counter], 16);
}
return writebuffer;
//byte[] writebuffer = Encoding.UTF8.GetBytes(stringBuilder.ToString());
}
public void CSSendMessage
(byte[] msg, CheckCallBack checkcallback , ReceiveCallBack callback ,MessageSpyCallBack msgspy)
{
tcpNetworkStream = tcpClient.GetStream();
if (tcpNetworkStream.CanWrite)
{
tcpNetworkStream.Write(msg, 0, msg.Length);
checkcallback(true);
msgspy(msg);
}
else
{
checkcallback(false);
}
callback();
}
以上两个函数是数据的编码和发送函数,以51单片机作为下位机进行测试,但是经过测试发现只有发送0x01-0x09时下位机可以正常接收到,发送更大的值比如0x51这样的值接收不到,希望请教一下各位高手这是为什么{:soso_e134:} 另外用串口助手发现收不到数据 波特率9600和115200全部试过 但是usb转串口线有点发热不清楚是不是线的问题
|
|