|
- void __fastcall TForm1::QueryProc() //查询协议 普通信息
- {
- AnsiString str;
- unsigned char Data[64];
- unsigned short *p;
- unsigned long *l;
- long acc_p;
- unsigned short tmp2;
- float tmp,ac_v,ac_a;
- SYSTEMTIME systime;
- setmem(Data,64,0);
- pkgBuf->GetData(Data);
- acc_p= 0xa1 + 0x1c + Form1->SlaveAddr->Text.ToInt();
- for(int i = 0; i < 33; i++)
- {
- acc_p += Data[i];
- }
- acc_p &= 0xff;//通过计算获得的校验和
- pkgBuf->GetParityData(&cmdParity);
- cmdParity &= 0xff;//直接获取的检验和
- Form1->Edit6->Text = cmdParity;
- Form1->Edit7->Text = acc_p;//此部分是我自己调试用的
- if(cmdParity == acc_p)
- {
- p= (unsigned short*)&Data[0]; //直流电压
- str = *p;
- str = str.Insert(".",str.Length());
- if(str.Pos(".") == 1)str = "0" + str;
- Form1->vlQuery->Cells[1][1] = str+"V";
- p= (unsigned short*)&Data[2]; //直流电流
- str = *p;
- str = str.Insert(".",str.Length());
- if(str.Pos(".") == 1)str = "0" + str;
- Form1->vlQuery->Cells[1][2] = str+"A";
- p= (unsigned short*)&Data[4];
- str = *p;
- str = str.Insert(".",str.Length());
- if(str.Pos(".") == 1)str = "0" + str;
- Form1->vlQuery->Cells[1][3] = str + "V";
- ac_v = (float)*p/10;
- ....
- ....
- }
- }
复制代码
发现cmdParity获取老为0 但是当我重新关闭再打开一次串口时却可以获取到校验和,接下来就不可以了 |
|