com发送
comPort.Open();
//发送
dt = ParaToDataTableHelper.GetDataTable();
byte[] bytSendArray = new byte[100]; //发送数据缓冲区
SampRepInfor para = new SampRepInfor();
para.ID = 1;
para.Sex = 1;
para.Age = 18;
para.HCYResult = 9;
para.Name = "张敏";
bytSendArray = BytesToParaHelper.ParaToBytes(para);
//接收
byte[] bytReceiveArray = new byte[bytSendArray.Length];
int ReceiveNum = comPort.SendCommand(bytSendArray, ref bytReceiveArray, 200);
SampRepInfor samp = new SampRepInfor();
if (ReceiveNum!=0)
{
samp = BytesToParaHelper.BytesToPara(bytReceiveArray);
Table = ParaToDataTableHelper.ConvertToDataTable(samp, dt);
}
//发送
bytSendArray = new byte[100]; //发送数据缓冲区
para = new SampRepInfor();
para.ID = 2;
para.Sex = 0;
para.Age = 20;
para.HCYResult = 12;
para.Name = "小军";
bytSendArray = BytesToParaHelper.ParaToBytes(para);
//接收
bytReceiveArray = new byte[bytSendArray.Length];
ReceiveNum = comPort.SendCommand(bytSendArray, ref bytReceiveArray, 200);
if (ReceiveNum != 0)
{
samp = BytesToParaHelper.BytesToPara(bytReceiveArray);
Table = ParaToDataTableHelper.ConvertToDataTable(samp, dt);
}