顶针盘与电压电流串口常连接

main
admin 2 months ago
parent 7554c180e2
commit b3dbcfc5b7

@ -1059,24 +1059,28 @@ void COtherMonitorDevMgr::OnO2ConcentrationCommRecv()
//读取机台的电流电压值 //读取机台的电流电压值
void COtherMonitorDevMgr::ReadDeviceCurrentAndVoltage() void COtherMonitorDevMgr::ReadDeviceCurrentAndVoltage()
{ {
ComComm Comm; if (!DevComm.IsOpen())
if(!Comm.Open(m_DeviceCurrentAndVoltageCommPort,COMM_BAUD_RATE_9600)) {
if (!DevComm.Open(m_DeviceCurrentAndVoltageCommPort, COMM_BAUD_RATE_9600))
{ {
return; return;
} }
ReadDeviceCurrentAndVoltageExt(_MonitorValType_DevCurrent1, Comm); }
ReadDeviceCurrentAndVoltageExt(_MonitorValType_DevCurrent2, Comm); ReadDeviceCurrentAndVoltageExt(_MonitorValType_DevCurrent1);
ReadDeviceCurrentAndVoltageExt(_MonitorValType_DevCurrent3, Comm); ReadDeviceCurrentAndVoltageExt(_MonitorValType_DevCurrent2);
ReadDeviceCurrentAndVoltageExt(_MonitorValType_DevVoltage1, Comm); ReadDeviceCurrentAndVoltageExt(_MonitorValType_DevCurrent3);
ReadDeviceCurrentAndVoltageExt(_MonitorValType_DevVoltage1);
#if 0 #if 0
ReadDeviceCurrentAndVoltageExt(_MonitorValType_DevSmoke,CommMgr); ReadDeviceCurrentAndVoltageExt(_MonitorValType_DevSmoke);
#endif #endif
Comm.Close();
} }
void COtherMonitorDevMgr::ReadDeviceCurrentAndVoltageExt(eMonitorValType MonitorValType,ComComm &Comm) void COtherMonitorDevMgr::ReadDeviceCurrentAndVoltageExt(eMonitorValType MonitorValType)
{
if (!DevComm.IsOpen())
{ {
return;
}
Sleep(100); Sleep(100);
unsigned char Buf[COM_BUF_LEN]; unsigned char Buf[COM_BUF_LEN];
memset(Buf, 0, COM_BUF_LEN); memset(Buf, 0, COM_BUF_LEN);
//ADDR //ADDR
@ -1122,10 +1126,10 @@ void COtherMonitorDevMgr::ReadDeviceCurrentAndVoltageExt(eMonitorValType Monitor
Buf[i++] = CRCH; Buf[i++] = CRCH;
Buf[i++] = CRCL; Buf[i++] = CRCL;
//发送 //发送
Comm.Write(Buf,i); DevComm.Write(Buf, i);
Sleep(100); Sleep(100);
memset(Buf, 0, COM_BUF_LEN); memset(Buf, 0, COM_BUF_LEN);
Comm.Read(Buf,COM_BUF_LEN); DevComm.Read(Buf, COM_BUF_LEN);
//从串口数据中提取读数 //从串口数据中提取读数
double ReadVal = -1; double ReadVal = -1;
int high = Byte2Int(Buf[3]); int high = Byte2Int(Buf[3]);

@ -102,10 +102,11 @@ public:
void FluoroscopyO2ConcentrationCommRecv(); void FluoroscopyO2ConcentrationCommRecv();
void PLCReadFFUVal(); void PLCReadFFUVal();
private: private:
void ReadDeviceCurrentAndVoltageExt(eMonitorValType MonitorValType,ComComm &Comm); void ReadDeviceCurrentAndVoltageExt(eMonitorValType MonitorValType);
void DealAlarm(eAlarmType CurAlarmType, bool bThrow, CString ErrInfo); void DealAlarm(eAlarmType CurAlarmType, bool bThrow, CString ErrInfo);
private: private:
CCommPortMgr m_O2ConcentrationComm;//氧气浓度串口管理 CCommPortMgr m_O2ConcentrationComm;//氧气浓度串口管理
ComComm DevComm;//设备电压电流串口
int m_O2ConcentrationCommPort;//氧气浓度串口端口 int m_O2ConcentrationCommPort;//氧气浓度串口端口
int m_nO2DevType;//氧浓度设备类型 0 TORAY 1 鸿瑞稻科 2 荧光学 int m_nO2DevType;//氧浓度设备类型 0 TORAY 1 鸿瑞稻科 2 荧光学
bool m_bCheckO2Concentration;//是否检测氧气浓度 bool m_bCheckO2Concentration;//是否检测氧气浓度

@ -71,11 +71,14 @@ int CSmartStraightLineSerDriverCtl::QueryPostion(int nTimeSecOut)
return -1; return -1;
} }
int nRet = -1; int nRet = -1;
if (!m_comCtl.IsOpen())
{
bool bRet = m_comCtl.Open(m_nCom, m_nBaud); bool bRet = m_comCtl.Open(m_nCom, m_nBaud);
if (!bRet) if (!bRet)
{ {
return nRet; return nRet;
} }
}
if (m_comCtl.IsOpen()) if (m_comCtl.IsOpen())
{ {
m_comCtl.Purge(); m_comCtl.Purge();
@ -150,7 +153,7 @@ int CSmartStraightLineSerDriverCtl::QueryPostion(int nTimeSecOut)
} }
} while (m_bInit); } while (m_bInit);
} }
m_comCtl.Close(); //m_comCtl.Close();
return nRet; return nRet;
} }
@ -227,13 +230,16 @@ int CSmartStraightLineSerDriverCtl::SetPostion(int nPostion,int nTimeSecOut)
string strOUT; string strOUT;
//测试发现偶尔出现USB 转COM 掉线问题,以及此设备报文必须发送后等待应答了才能发送下一个 //测试发现偶尔出现USB 转COM 掉线问题,以及此设备报文必须发送后等待应答了才能发送下一个
//所以保险每次都重新打开串口 //所以保险每次都重新打开串口
m_comCtl.Close(); //m_comCtl.Close();
if (!m_comCtl.IsOpen())
{
bool bRet = m_comCtl.Open(m_nCom, m_nBaud); bool bRet = m_comCtl.Open(m_nCom, m_nBaud);
if (!bRet) if (!bRet)
{ {
m_pLog->LogDebug("串口打开失败:%ld", GetLastError()); m_pLog->LogDebug("串口打开失败:%ld", GetLastError());
return nRet; return nRet;
} }
}
do do
{ {
@ -304,7 +310,7 @@ int CSmartStraightLineSerDriverCtl::SetPostion(int nPostion,int nTimeSecOut)
break; break;
} }
} while (m_bInit); } while (m_bInit);
m_comCtl.Close(); //m_comCtl.Close();
return nRet; return nRet;
} }

Loading…
Cancel
Save