operationtooldlg1.cpp
来自「采用文档类方法实现的一种串口通讯协议。可以借鉴参考」· C++ 代码 · 共 2,277 行 · 第 1/4 页
CPP
2,277 行
for (xyz = 0; xyz < I_nPacLen; xyz++)
{
strLast.Format("%c", I_pbyDataS[xyz]);
strUnitInf += strLast ;
}
break;
case 0x23: //0x2123
strUnitInf += "The Firmware Version is:\t";
for (xyz = 0; xyz < I_nPacLen; xyz++)
{
strLast.Format("%c",I_pbyDataS[xyz]);
strUnitInf += strLast ;
}
break;
case 0x24:
strUnitInf += "The Product name is:\t";
for (xyz = 0; xyz < I_nPacLen; xyz++)
{
strLast.Format("%c", I_pbyDataS[xyz]);
strUnitInf += strLast ;
}
break;
case 0x25:
strUnitInf += "The System option byte is:\t";
strLast.Format("%02X", I_pbyDataS[0]);
strUnitInf += strLast ;
break;
case 0x26:
strUnitInf += "The instrument byStatus byte is:\t";
strLast.Format("%02X", I_pbyDataS[0]);
strUnitInf += strLast ;
break;
default:
break;
}
mf_DispMsg(strUnitInf);
mf_ChangeFormat();
}
void COperationToolDlg::mf_Deal213XProc(BYTE I_byCMDS, short I_nPacLen, BYTE *I_pbyDataS)
{
ASSERT(I_pbyDataS != NULL);
CString strInf;
CString strLast;
BYTE abyName[10] = "";
int nInstallEnable = 0;
int xyz = 0;
int nCount = 0;
int nNumber = 0; //used in sensor Number
float fTmp;
strInf = "The Number of received data is:\t";
strLast.Format("%d\n\r", I_nPacLen);
strInf += strLast;
switch (I_byCMDS)
{
case 0x30: //0x2130
if (I_nPacLen <= 0) break;
m_nSensornumber = I_pbyDataS[0];
strLast.Format("%d\n\r", m_nSensornumber);
strInf += "Number of Sensor is:\t" + strLast;
for (xyz = 0; xyz < m_nSensornumber; xyz++)
{
nInstallEnable = (1 << xyz ) & 0xFF; //1---const Number,used to shift
if ((I_pbyDataS[m_nSensornumber + 1] & nInstallEnable) == nInstallEnable)
{
strLast.Format("%d", (xyz + 1)) ;
strInf += "Sensor " + strLast + ": Installed ";
m_SensorInf[xyz].Installed = TRUE; //coresponsed sensor is installed
//Enabled or not
if ((I_pbyDataS[m_nSensornumber+2] & nInstallEnable) == nInstallEnable)
{
m_SensorInf[xyz].Enabled = TRUE;
strInf += "and Enabled.";
}
else
{
m_SensorInf[xyz].Enabled = FALSE;
strInf += "but Not Enabled.";
}
strInf += "\n";
}
else
{
m_SensorInf[xyz].Installed = FALSE;
m_SensorInf[xyz].Enabled = FALSE;
strInf += "Sensor " + strLast + ": Not Installed and not enabled";
strInf += "\n";
} //end install
} //end for
break;
case 0x31: //0x2131
if (I_nPacLen <= 0) break;
if (m_nSensornumber <= 0)
{
strInf += "please run GET_SEN_SUMMARY item first!";
break;
}
strInf += "The Sensor Name is:" ;
strLast.Format("%s",I_pbyDataS);
strInf += strLast ;
//split the string and fill the structure Name
for (xyz=0; xyz<=I_nPacLen; xyz++)
{
if ((I_pbyDataS[xyz] != ',') && (xyz < I_nPacLen))
{
abyName[nCount] = I_pbyDataS[xyz];
nCount ++;
}
else
{
abyName[nCount] = 0;
strLast.Format("%s", abyName);
m_SensorInf[nNumber].Name = strLast;
nNumber ++;
nCount = 0;
}
}
break;
case 0x32: //0x2132 data format
if (I_nPacLen <= 0) break;
if (m_nSensornumber <= 0)
{
strInf += "please run GET_SEN_SUMMARY item first!";
break;
}
strInf += "Sensor data format is:\t\n\r" ;
for (xyz = 0; xyz < m_nSensornumber; xyz++)
{
strLast.Format("%d", (xyz+1));
strInf += "Sensor" + strLast + ":";
nInstallEnable = I_pbyDataS[2 * xyz];
switch(nInstallEnable & 0x03) //data length
{
case 0x00:
strInf += "1 byte";
m_SensorInf[xyz].DataLen = 1;
break;
case 0x01:
strInf += "2 bytes";
m_SensorInf[xyz].DataLen = 2;
break;
case 0x02:
strInf += "4 bytes";
m_SensorInf[xyz].DataLen = 4;
break;
case 0x03:
strInf += "8 bytes";
m_SensorInf[xyz].DataLen = 8;
break;
}
switch(nInstallEnable & 0x0C) //decimal point
{
case 0x00:
strInf += ", No point ";
m_SensorInf[xyz].Point = 0;
break;
case 0x04:
strInf += ", in last bit ";
m_SensorInf[xyz].Point = 1;
break;
case 0x08:
strInf += ", in last 2 bit";
m_SensorInf[xyz].Point = 2;
break;
case 0x0C:
strInf += ", in last 3 bit";
m_SensorInf[xyz].Point = 3;
break;
}
strInf += "; unit is: ";
nCount = I_pbyDataS[2 * xyz + 1];
strInf += MeasureUnit[nCount & 0x1F]; //get unit
strInf += "\n";
m_SensorInf[xyz].unit = MeasureUnit[nCount & 0x1F];
}
break;
case 0x33: //0x2133
if (m_nSensornumber <= 0)
{
strInf += "please run GET_SEN_SUMMARY and GET_SENSORNAME and GET_SEN_DATAFORMAT items first!";
break;
}
// if (I_nPacLen <= (5 * m_nSensornumber +4)) break;
for (xyz = 0; xyz < m_nSensornumber; xyz++)
{
strLast.Format("%d", (xyz+1));
strInf += "Sensor" + strLast + " CalibTime is:\t";
strLast.Format("20%02d-%02d-%02d %02d:%02d\n", I_pbyDataS[5*xyz],I_pbyDataS[5*xyz+1],I_pbyDataS[5*xyz+2],I_pbyDataS[5*xyz+3],I_pbyDataS[5*xyz+4]);
strInf += strLast;
}
break;
case 0x34: //0x2134
if (m_nSensornumber <= 0)
{
strInf += "please run GET_SEN_SUMMARY and GET_SENSORNAME and GET_SEN_DATAFORMAT items first!";
break;
}
// if (I_nPacLen <= (4 * m_nSensornumber + 4)) break;
strInf += " Sensor Span Value is:\n\r";
for (xyz = 0; xyz < m_nSensornumber; xyz++)
{
nCount = I_pbyDataS[4*xyz] << 24;
nCount += I_pbyDataS[4*xyz + 1] << 16;
nCount += I_pbyDataS[4*xyz + 2] << 8;
nCount += I_pbyDataS[4*xyz + 3];
strInf += m_SensorInf[xyz].Name + "(" + m_SensorInf[xyz].unit + ")\t = ";
switch(m_SensorInf[xyz].Point)
{
case 0:
fTmp = static_cast<float>(nCount);
strLast.Format("%.0f\n", fTmp);
break;
case 1:
fTmp = static_cast<float>(nCount/10.0);
strLast.Format("%.1f\n", fTmp);
break;
case 2:
fTmp = static_cast<float>(nCount/100.0);
strLast.Format("%.2f\n", fTmp);
break;
case 3:
fTmp = static_cast<float>(nCount/1000.0);
strLast.Format("%.3f\n", fTmp);
break;
default:
break;
}
strInf += strLast;
}
break;
case 0x35: //0x2135
if (m_nSensornumber <= 0)
{
strInf += "please run GET_SEN_SUMMARY and GET_SENSORNAME and GET_SEN_DATAFORMAT items first!";
break;
}
// if (I_nPacLen <= (4 * m_nSensornumber + 4)) break;
strInf += "Sensor Low Alarm Limits is:\n\r ";
for (xyz = 0; xyz < m_nSensornumber; xyz++)
{
nCount = I_pbyDataS[4 * xyz] << 24;
nCount += I_pbyDataS[4 * xyz + 1] << 16;
nCount += I_pbyDataS[4 * xyz + 2] << 8;
nCount += I_pbyDataS[4 * xyz + 3];
strInf += m_SensorInf[xyz].Name + "(" + m_SensorInf[xyz].unit + ")\t = ";
switch(m_SensorInf[xyz].Point)
{
case 0:
fTmp = static_cast<float>(nCount);
strLast.Format("%.0f\n", fTmp);
break;
case 1:
fTmp = static_cast<float>(nCount/10.0);
strLast.Format("%.1f\n", fTmp);
break;
case 2:
fTmp = static_cast<float>(nCount/100.0);
strLast.Format("%.2f\n", fTmp);
break;
case 3:
fTmp = static_cast<float>(nCount/1000.0);
strLast.Format("%.3f\n", fTmp);
break;
default:
break;
}
strInf += strLast;
}
break;
case 0x36: //0x2136
if (m_nSensornumber <= 0)
{
strInf += "please run GET_SEN_SUMMARY and GET_SENSORNAME and GET_SEN_DATAFORMAT items first!";
break;
}
// if (I_nPacLen <= (4 * m_nSensornumber + 4)) break;
strInf += "Sensor High Alarm Limits is:\n\r";
for (xyz = 0; xyz < m_nSensornumber; xyz++)
{
nCount = I_pbyDataS[4*xyz] << 24;
nCount += I_pbyDataS[4*xyz + 1] << 16;
nCount += I_pbyDataS[4*xyz + 2] << 8;
nCount += I_pbyDataS[4*xyz + 3];
strInf += m_SensorInf[xyz].Name + "(" + m_SensorInf[xyz].unit + ")\t = ";
switch(m_SensorInf[xyz].Point)
{
case 0:
fTmp = static_cast<float>(nCount);
strLast.Format("%.0f\n", fTmp);
break;
case 1:
fTmp = static_cast<float>(nCount/10.0);
strLast.Format("%.1f\n", fTmp);
break;
case 2:
fTmp = static_cast<float>(nCount/100.0);
strLast.Format("%.2f\n",fTmp);
break;
case 3:
fTmp = static_cast<float>(nCount/1000.0);
strLast.Format("%.3f\n", fTmp);
break;
default:
break;
}
strInf += strLast;
}
break;
case 0x37: //0x2137
if (m_nSensornumber <= 0)
{
strInf += "please run GET_SEN_SUMMARY and GET_SENSORNAME and GET_SEN_DATAFORMAT items first!";
break;
}
// if (I_nPacLen <= (4 * m_nSensornumber + 4)) break;
strInf += "Sensor STEL Alarm Limits is:\n\r";
for (xyz = 0; xyz < m_nSensornumber; xyz++)
{
if ((4 * xyz) < I_nPacLen)
{
nCount = I_pbyDataS[4*xyz] << 24;
nCount += I_pbyDataS[4*xyz+1] << 16;
nCount += I_pbyDataS[4*xyz+2] << 8;
nCount += I_pbyDataS[4*xyz+3];
if (nCount>0)
{
strInf += m_SensorInf[xyz].Name + "(" + m_SensorInf[xyz].unit + ")\t = ";
switch(m_SensorInf[xyz].Point)
{
case 0:
fTmp = static_cast<float>(nCount);
strLast.Format("%.0f\n", fTmp);
break;
case 1:
fTmp = static_cast<float>(nCount/10.0);
strLast.Format("%.1f\n", fTmp);
break;
case 2:
fTmp = static_cast<float>(nCount/100.0);
strLast.Format("%.2f\n", fTmp);
break;
case 3:
fTmp = static_cast<float>(nCount/1000.0);
strLast.Format("%.3f\n", fTmp);
break;
default:
break;
}
strInf += strLast;
}
}
}
break;
case 0x38: //0x2138
if (m_nSensornumber <= 0)
{
strInf += "please run GET_SEN_SUMMARY and GET_SENSORNAME and GET_SEN_DATAFORMAT items first!";
break;
}
// if (I_nPacLen <= (4 * m_nSensornumber + 4)) break;
strInf += "Sensor TWA Alarm Limits is:\n\r";
for (xyz = 0; xyz < m_nSensornumber; xyz++)
{
if (4 * xyz < I_nPacLen)
{
nCount = I_pbyDataS[4*xyz] << 24;
nCount += I_pbyDataS[4*xyz+1] << 16;
nCount += I_pbyDataS[4*xyz+2] << 8;
nCount += I_pbyDataS[4*xyz+3];
if (nCount > 0)
{
strInf += m_SensorInf[xyz].Name + "(" + m_SensorInf[xyz].unit + ")\t = ";
switch(m_SensorInf[xyz].Point)
{
case 0:
fTmp = static_cast<float>(nCount);
strLast.Format("%.0f\n", fTmp);
break;
case 1:
fTmp = static_cast<float>(nCount/10.0);
strLast.Format("%.1f\n", fTmp);
break;
case 2:
fTmp = static_cast<float>(nCount/100.0);
strLast.Format("%.2f\n", fTmp);
break;
case 3:
fTmp = static_cast<float>(nCount/1000.0);
strLast.Format("%.3f\n", fTmp);
break;
default:
break;
}
strInf += strLast;
}
}
}
break;
case 0x39: //0x2139
if (m_nSensornumber <= 0)
{
strInf += "please run GET_SEN_SUMMARY and GET_SENSORNAME and GET_SEN_DATAFORMAT items first!";
break;
}
// if (I_nPacLen <= (4 * m_nSensornumber + 4)) break;
strInf += "Sensor Over Range Limit is:\n\r";
for (xyz = 0; xyz < m_nSensornumber; xyz++)
{
if (4*xyz < I_nPacLen)
{
nCount = I_pbyDataS[4*xyz] << 24;
nCount += I_pbyDataS[4*xyz+1] << 16;
nCount += I_pbyDataS[4*xyz+2] << 8;
nCount += I_pbyDataS[4*xyz+3];
if (nCount>0)
{
strInf += m_SensorInf[xyz].Name + "(" + m_SensorInf[xyz].unit + ")\t= ";
switch(m_SensorInf[xyz].Point)
{
case 0:
fTmp = static_cast<float>(nCount);
strLast.Format("%.0f\n", fTmp);
break;
case 1:
fTmp = static_cast<float>(nCount/10.0);
strLast.Format("%.1f\n", fTmp);
break;
case 2:
fTmp = static_cast<float>(nCount/100.0);
strLast.Format("%.2f\n", fTmp);
break;
case 3:
fTmp = static_cast<float>(nCount/1000.0);
strLast.Format("%.3f\n", fTmp);
break;
default:
break;
}
strInf += strLast;
}
}
}
break;
case 0x3A: //0x213A
if (m_nSensornumber <= 0)
{
strInf += "please run GET_SEN_SUMMARY and GET_SENSORNAME and GET_SEN_DATAFORMAT items first!";
break;
}
// if (I_nPacLen <= (4 * m_nSensornumber + 4)) break;
strInf += "Sensor Reading is:\n\r";
for (xyz = 0; xyz < m_nSensornumber; xyz++)
{
if (4*xyz < I_nPacLen)
{
nCount = I_pbyDataS[4*xyz] << 24;
nCount += I_pbyDataS[4*xyz+1] << 16;
nCount += I_pbyDataS[4*xyz+2] << 8;
nCount += I_pbyDataS[4*xyz+3];
strInf += m_SensorInf[xyz].Name + "(" + m_SensorInf[xyz].unit + ")\t= ";
switch(m_SensorInf[xyz].Point)
{
case 0:
fTmp = static_cast<float>(nCount);
strLast.Format("%.0f\n", fTmp);
break;
case 1:
fTmp = static_cast<float>(nCount/10.0);
strLast.Format("%.1f\n", fTmp);
break;
case 2:
fTmp = static_cast<float>(nCount/100.0);
strLast.Format("%.2f\n", fTmp);
break;
case 3:
fTmp = static_cast<float>(nCount/1000.0);
strLast.Format("%.3f\n",fTmp);
break;
default:
break;
}
strInf += strLast;
}
}
break;
case 0x3B: //0x213B
if (m_nSensornumber <= 0)
{
strInf += "please run GET_SEN_SUMMARY and GET_SENSORNAME and GET_SEN_DATAFORMAT items first!";
break;
}
strInf += "Sensor byStatus is:\n\r ";
for (xyz = 0; xyz < m_nSensornumber; xyz++)
{
strInf += m_SensorInf[xyz].Name + "(" + m_SensorInf[xyz].unit + "):\t";
if ((I_pbyDataS[xyz] & 0x01) == 0x01)
strInf += " Over range";
if ((I_pbyDataS[xyz] & 0x02) == 0x02)
strInf += " max";
if ((I_pbyDataS[xyz] & 0x04) == 0x04)
strInf += " sensor fail";
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?