682 lines
23 KiB
C++
682 lines
23 KiB
C++
|
#include "IPGLaserClient.h"
|
|||
|
#include "YLRCommand.h"
|
|||
|
#include <bitset>
|
|||
|
//#include "../LanguageManager.h"
|
|||
|
#include "../PLC/SignalService.h"
|
|||
|
#include "../config/ConfigManager.h"
|
|||
|
#include "../external/imgui/imgui_custom.h"
|
|||
|
//#include "../Toast.h"
|
|||
|
|
|||
|
IPGLaserClient::IPGLaserClient(CommunicationCfg* pconfig, AlarmCfg* laserAlarm, int freq):TcpClient(pconfig,freq)
|
|||
|
, m_LaserAlarm(laserAlarm)
|
|||
|
{
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
IPGLaserClient::~IPGLaserClient()
|
|||
|
{
|
|||
|
Shutdown();
|
|||
|
}
|
|||
|
|
|||
|
void IPGLaserClient::InitCommand()
|
|||
|
{
|
|||
|
//读取激光二极管电流设置
|
|||
|
Command* rcsCommand = new YLRReadCommand("RCS");
|
|||
|
rcsCommand->m_Fun = &IPGLaserClient::PorcReadCurrentSetpoint;
|
|||
|
rcsCommand->m_Ref = this;
|
|||
|
rcsCommand->isNeedDel = false;
|
|||
|
|
|||
|
//读取内部实际温度
|
|||
|
Command* rctCommand = new YLRReadCommand("RCT");
|
|||
|
rctCommand->m_Fun = &IPGLaserClient::PorcReadLaserTemp;
|
|||
|
rctCommand->m_Ref = this;
|
|||
|
rctCommand->isNeedDel = false;
|
|||
|
|
|||
|
//输出功率
|
|||
|
Command* ropCommand = new YLRReadCommand("ROP");
|
|||
|
ropCommand->m_Fun = &IPGLaserClient::PorcReadOutputPower;
|
|||
|
ropCommand->m_Ref = this;
|
|||
|
ropCommand->isNeedDel = false;
|
|||
|
|
|||
|
//读取模块错误代码
|
|||
|
Command* rmecCommand = new YLRReadCommand("RMEC");
|
|||
|
rmecCommand->m_Fun = &IPGLaserClient::PorcModuleErrorCode;
|
|||
|
rmecCommand->m_Ref = this;
|
|||
|
rmecCommand->isNeedDel = false;
|
|||
|
|
|||
|
//读取设备状态
|
|||
|
Command* staCommand = new YLRReadCommand("STA");
|
|||
|
staCommand->m_Fun = &IPGLaserClient::PorcDeviceStatus;
|
|||
|
staCommand->m_Ref = this;
|
|||
|
staCommand->isNeedDel = false;
|
|||
|
|
|||
|
m_CycleCommands.push_back(rcsCommand);
|
|||
|
m_CycleCommands.push_back(rctCommand);
|
|||
|
m_CycleCommands.push_back(ropCommand);
|
|||
|
m_CycleCommands.push_back(rmecCommand);
|
|||
|
m_CycleCommands.push_back(staCommand);
|
|||
|
}
|
|||
|
|
|||
|
void IPGLaserClient::ResetAlarm()
|
|||
|
{
|
|||
|
if (!m_Client.IsOpen())return;
|
|||
|
Command* reerCommand = new YLREchoCommand("RERR");
|
|||
|
EnterCriticalSection(&m_RtcCS);
|
|||
|
m_RTCommands.push(reerCommand);
|
|||
|
LeaveCriticalSection(&m_RtcCS);
|
|||
|
}
|
|||
|
|
|||
|
void IPGLaserClient::PorcReadCurrentSetpoint(void* pobject, Command* pcommand)
|
|||
|
{
|
|||
|
if (pobject == NULL)return;
|
|||
|
IPGLaserClient* client = (IPGLaserClient*)pobject;
|
|||
|
YLRReadCommand* ylrCommand = (YLRReadCommand*)pcommand;
|
|||
|
string strvalue = ylrCommand->GetValue();
|
|||
|
if (strvalue.empty())return;
|
|||
|
float fvalue = 0.0f;
|
|||
|
bool rel = true;
|
|||
|
try {
|
|||
|
fvalue = stof(strvalue);
|
|||
|
}
|
|||
|
catch (std::invalid_argument&) {
|
|||
|
rel = false;
|
|||
|
}
|
|||
|
catch (std::out_of_range&)
|
|||
|
{
|
|||
|
rel = false;
|
|||
|
}
|
|||
|
catch (...) {
|
|||
|
rel = false;
|
|||
|
}
|
|||
|
if (!rel)return;
|
|||
|
EnterCriticalSection(&client->m_ValueCS);
|
|||
|
client->m_State.currentSetpoint = fvalue;
|
|||
|
LeaveCriticalSection(&client->m_ValueCS);
|
|||
|
}
|
|||
|
|
|||
|
void IPGLaserClient::PorcReadLaserTemp(void* pobject, Command* pcommand)
|
|||
|
{
|
|||
|
if (pobject == NULL)return;
|
|||
|
IPGLaserClient* client = (IPGLaserClient*)pobject;
|
|||
|
YLRReadCommand* ylrCommand = (YLRReadCommand*)pcommand;
|
|||
|
string strvalue = ylrCommand->GetValue();
|
|||
|
if (strvalue.empty())return;
|
|||
|
float fvalue = 0.0f;
|
|||
|
bool rel = true;
|
|||
|
try {
|
|||
|
fvalue = stof(strvalue);
|
|||
|
}
|
|||
|
catch (std::invalid_argument&) {
|
|||
|
rel = false;
|
|||
|
}
|
|||
|
catch (std::out_of_range&)
|
|||
|
{
|
|||
|
rel = false;
|
|||
|
}
|
|||
|
catch (...) {
|
|||
|
rel = false;
|
|||
|
}
|
|||
|
if (!rel)return;
|
|||
|
EnterCriticalSection(&client->m_ValueCS);
|
|||
|
client->m_State.laserTemperature = fvalue;
|
|||
|
LeaveCriticalSection(&client->m_ValueCS);
|
|||
|
}
|
|||
|
|
|||
|
void IPGLaserClient::PorcModuleErrorCode(void* pobject, Command* pcommand)
|
|||
|
{
|
|||
|
if (pobject == NULL)return;
|
|||
|
IPGLaserClient* client = (IPGLaserClient*)pobject;
|
|||
|
YLRReadCommand* ylrCommand = (YLRReadCommand*)pcommand;
|
|||
|
string strvalue = ylrCommand->GetValue();
|
|||
|
if (strvalue.empty())return;
|
|||
|
int ivalue = 0;
|
|||
|
bool rel = true;
|
|||
|
try {
|
|||
|
ivalue = stoi(strvalue);
|
|||
|
}
|
|||
|
catch (std::invalid_argument&) {
|
|||
|
rel = false;
|
|||
|
}
|
|||
|
catch (std::out_of_range&)
|
|||
|
{
|
|||
|
rel = false;
|
|||
|
}
|
|||
|
catch (...) {
|
|||
|
rel = false;
|
|||
|
}
|
|||
|
if (!rel)return;
|
|||
|
EnterCriticalSection(&client->m_ValueCS);
|
|||
|
client->m_State.moduleErrorCode = ivalue;
|
|||
|
LeaveCriticalSection(&client->m_ValueCS);
|
|||
|
}
|
|||
|
|
|||
|
void IPGLaserClient::PorcDeviceStatus(void* pobject, Command* pcommand)
|
|||
|
{
|
|||
|
if (pobject == NULL)return;
|
|||
|
IPGLaserClient* client = (IPGLaserClient*)pobject;
|
|||
|
YLRReadCommand* ylrCommand = (YLRReadCommand*)pcommand;
|
|||
|
string strvalue = ylrCommand->GetValue();
|
|||
|
if (strvalue.empty())return;
|
|||
|
int ivalue = 0;
|
|||
|
bool rel = true;
|
|||
|
try {
|
|||
|
ivalue = stoi(strvalue);
|
|||
|
}
|
|||
|
catch (std::invalid_argument&) {
|
|||
|
rel = false;
|
|||
|
}
|
|||
|
catch (std::out_of_range&)
|
|||
|
{
|
|||
|
rel = false;
|
|||
|
}
|
|||
|
catch (...) {
|
|||
|
rel = false;
|
|||
|
}
|
|||
|
if (!rel)return;
|
|||
|
std::bitset<32> bitValut(ivalue);
|
|||
|
EnterCriticalSection(&client->m_ValueCS);
|
|||
|
client->m_State.isOverheat = bitValut[1];
|
|||
|
client->m_State.isEmissionOn = bitValut[2];
|
|||
|
client->m_State.isHighBackReflectionLevel = bitValut[3];
|
|||
|
client->m_State.isExtCtrlEnable = bitValut[4];
|
|||
|
client->m_State.isModuleDisconnected = bitValut[6];
|
|||
|
client->m_State.isModuleAlarm = bitValut[7];
|
|||
|
client->m_State.isAimingBeamON = bitValut[8];
|
|||
|
//client->m_State.isPulseTooShort = bitValut[9];
|
|||
|
//client->m_State.isPulseMode = bitValut[10];
|
|||
|
client->m_State.isPowerSupplyOff = bitValut[11];
|
|||
|
client->m_State.isModulationEnabled = bitValut[12];
|
|||
|
client->m_State.isEmission = bitValut[15];
|
|||
|
//client->m_State.isGateModeEnabled = bitValut[16];
|
|||
|
//client->m_State.isHighPulseEnergy = bitValut[17];
|
|||
|
client->m_State.isExtEmissionCtrlEnabled = bitValut[18];
|
|||
|
client->m_State.isPowerSupplyFailure = bitValut[19];
|
|||
|
//client->m_State.isLockFrontPanel = bitValut[20];
|
|||
|
//client->m_State.isKeyswitchInREMPosition = bitValut[21];
|
|||
|
//client->m_State.isWaveformPulseModeEnabled = bitValut[22];
|
|||
|
//client->m_State.isHighDutyCycle = bitValut[23];
|
|||
|
client->m_State.isLowTemperature = bitValut[24];
|
|||
|
client->m_State.isPowerSupplyVotageAlarm = bitValut[25];
|
|||
|
client->m_State.isLeakageCurrentTooHigh = bitValut[26];
|
|||
|
client->m_State.isExtRedLightCtrlEnabled = bitValut[27];
|
|||
|
client->m_State.isCritialError = bitValut[29];
|
|||
|
client->m_State.isOpticalInterlockActive = bitValut[30];
|
|||
|
//client->m_State.isAveragePowerTooHigh = bitValut[31];
|
|||
|
bool hasAlarm = false;
|
|||
|
SignalService& ss = SignalService::GetInstance();
|
|||
|
if (client->m_State.isOverheat) {
|
|||
|
ss.SetAlarm(client->m_LaserAlarm, true);
|
|||
|
client->m_LaserAlarm->m_AlarmInfo = _(u8"温度过高:").c_str();
|
|||
|
hasAlarm = true;
|
|||
|
}
|
|||
|
if (client->m_State.isLowTemperature) {
|
|||
|
ss.SetAlarm(client->m_LaserAlarm, true);
|
|||
|
client->m_LaserAlarm->m_AlarmInfo = _(u8"温度过低:").c_str();
|
|||
|
hasAlarm = true;
|
|||
|
}
|
|||
|
if (client->m_State.isHighBackReflectionLevel) {
|
|||
|
ss.SetAlarm(client->m_LaserAlarm, true);
|
|||
|
client->m_LaserAlarm->m_AlarmInfo = _(u8"高反报警:").c_str();
|
|||
|
hasAlarm = true;
|
|||
|
}
|
|||
|
if (client->m_State.isModuleDisconnected) {
|
|||
|
ss.SetAlarm(client->m_LaserAlarm, true);
|
|||
|
client->m_LaserAlarm->m_AlarmInfo = _(u8"激光模块失连:").c_str();
|
|||
|
hasAlarm = true;
|
|||
|
}
|
|||
|
if (client->m_State.isModuleAlarm) {
|
|||
|
ss.SetAlarm(client->m_LaserAlarm, true);
|
|||
|
client->m_LaserAlarm->m_AlarmInfo = _(u8"激光模块报警:").c_str();
|
|||
|
hasAlarm = true;
|
|||
|
}
|
|||
|
if (client->m_State.isPowerSupplyOff) {
|
|||
|
ss.SetAlarm(client->m_LaserAlarm, true);
|
|||
|
client->m_LaserAlarm->m_AlarmInfo = _(u8"模块主电源关闭:").c_str();
|
|||
|
hasAlarm = true;
|
|||
|
}
|
|||
|
if (client->m_State.isPowerSupplyFailure) {
|
|||
|
ss.SetAlarm(client->m_LaserAlarm, true);
|
|||
|
client->m_LaserAlarm->m_AlarmInfo = _(u8"模块主电源故障:").c_str();
|
|||
|
hasAlarm = true;
|
|||
|
}
|
|||
|
if (client->m_State.isPowerSupplyVotageAlarm) {
|
|||
|
ss.SetAlarm(client->m_LaserAlarm, true);
|
|||
|
client->m_LaserAlarm->m_AlarmInfo = _(u8"模块主电源电压:").c_str();
|
|||
|
hasAlarm = true;
|
|||
|
}
|
|||
|
if (client->m_State.isCritialError) {
|
|||
|
ss.SetAlarm(client->m_LaserAlarm, true);
|
|||
|
client->m_LaserAlarm->m_AlarmInfo = _(u8"关键错误:").c_str();
|
|||
|
hasAlarm = true;
|
|||
|
}
|
|||
|
if (client->m_State.isOpticalInterlockActive) {
|
|||
|
ss.SetAlarm(client->m_LaserAlarm, true);
|
|||
|
client->m_LaserAlarm->m_AlarmInfo = _(u8"安全互锁开路:").c_str();
|
|||
|
hasAlarm = true;
|
|||
|
}
|
|||
|
|
|||
|
if (!hasAlarm) {
|
|||
|
ss.SetAlarm(client->m_LaserAlarm, false);
|
|||
|
}
|
|||
|
LeaveCriticalSection(&client->m_ValueCS);
|
|||
|
}
|
|||
|
|
|||
|
void IPGLaserClient::PorcReadOutputPower(void* pobject, Command* pcommand)
|
|||
|
{
|
|||
|
if (pobject == NULL)return;
|
|||
|
IPGLaserClient* client = (IPGLaserClient*)pobject;
|
|||
|
YLRReadCommand* ylrCommand = (YLRReadCommand*)pcommand;
|
|||
|
string strvalue = ylrCommand->GetValue();
|
|||
|
if (strvalue.empty())return;
|
|||
|
int ivalue = 0;
|
|||
|
bool rel = true;
|
|||
|
EnterCriticalSection(&client->m_ValueCS);
|
|||
|
client->m_State.outputPower = strvalue;
|
|||
|
LeaveCriticalSection(&client->m_ValueCS);
|
|||
|
}
|
|||
|
|
|||
|
void IPGLaserClient::GetState(IPGLaserState& state)
|
|||
|
{
|
|||
|
EnterCriticalSection(&m_ValueCS);
|
|||
|
state.currentSetpoint =m_State.currentSetpoint;
|
|||
|
state.laserTemperature = m_State.laserTemperature;
|
|||
|
state.moduleErrorCode = m_State.moduleErrorCode;
|
|||
|
state.outputPower = m_State.outputPower;
|
|||
|
state.isOverheat = m_State.isOverheat;
|
|||
|
state.isEmissionOn = m_State.isEmissionOn;
|
|||
|
state.isHighBackReflectionLevel = m_State.isHighBackReflectionLevel;
|
|||
|
state.isExtCtrlEnable = m_State.isExtCtrlEnable;
|
|||
|
state.isModuleDisconnected = m_State.isModuleDisconnected;
|
|||
|
state.isModuleAlarm = m_State.isModuleAlarm;
|
|||
|
state.isAimingBeamON = m_State.isAimingBeamON;
|
|||
|
//state.isPulseTooShort = m_State.isPulseTooShort;
|
|||
|
// state.isPulseMode = m_State.isPulseMode;
|
|||
|
state.isPowerSupplyOff = m_State.isPowerSupplyOff;
|
|||
|
state.isModulationEnabled = m_State.isModulationEnabled;
|
|||
|
state.isEmission = m_State.isEmission;
|
|||
|
//state.isGateModeEnabled = m_State.isGateModeEnabled;
|
|||
|
//state.isHighPulseEnergy = m_State.isHighPulseEnergy;
|
|||
|
state.isExtEmissionCtrlEnabled = m_State.isExtEmissionCtrlEnabled;
|
|||
|
state.isPowerSupplyFailure = m_State.isPowerSupplyFailure;
|
|||
|
// state.isLockFrontPanel = m_State.isLockFrontPanel;
|
|||
|
// state.isKeyswitchInREMPosition = m_State.isKeyswitchInREMPosition;
|
|||
|
// state.isWaveformPulseModeEnabled = m_State.isWaveformPulseModeEnabled;
|
|||
|
// state.isHighDutyCycle = m_State.isHighDutyCycle;
|
|||
|
state.isLowTemperature = m_State.isLowTemperature;
|
|||
|
state.isPowerSupplyVotageAlarm = m_State.isPowerSupplyVotageAlarm;
|
|||
|
state.isLeakageCurrentTooHigh = m_State.isLeakageCurrentTooHigh;
|
|||
|
state.isExtRedLightCtrlEnabled = m_State.isExtRedLightCtrlEnabled;
|
|||
|
state.isCritialError = m_State.isCritialError;
|
|||
|
state.isOpticalInterlockActive = m_State.isOpticalInterlockActive;
|
|||
|
// state.isAveragePowerTooHigh = m_State.isAveragePowerTooHigh;
|
|||
|
LeaveCriticalSection(&m_ValueCS);
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
IPGLaserClientV1::IPGLaserClientV1(CommunicationCfg* pconfig, AlarmCfg* laserAlarm) :TcpClient(pconfig)
|
|||
|
, m_LaserAlarm(laserAlarm)
|
|||
|
{
|
|||
|
m_AlarmCfgWrapper = ConfigManager::GetInstance()->GetAlarmCfg();
|
|||
|
}
|
|||
|
|
|||
|
IPGLaserClientV1::~IPGLaserClientV1()
|
|||
|
{
|
|||
|
Shutdown();
|
|||
|
}
|
|||
|
|
|||
|
void IPGLaserClientV1::InitCommand()
|
|||
|
{
|
|||
|
//读取激光二极管电流设置
|
|||
|
Command* rcsCommand = new YLRReadCommand("RCS");
|
|||
|
rcsCommand->m_Fun = &IPGLaserClientV1::PorcReadCurrentSetpoint;
|
|||
|
rcsCommand->m_Ref = this;
|
|||
|
rcsCommand->isNeedDel = false;
|
|||
|
|
|||
|
//读取内部实际温度
|
|||
|
Command* rctCommand = new YLRReadCommand("RCT");
|
|||
|
rctCommand->m_Fun = &IPGLaserClientV1::PorcReadLaserTemp;
|
|||
|
rctCommand->m_Ref = this;
|
|||
|
rctCommand->isNeedDel = false;
|
|||
|
|
|||
|
//输出功率
|
|||
|
Command* ropCommand = new YLRReadCommand("ROP");
|
|||
|
ropCommand->m_Fun = &IPGLaserClientV1::PorcReadOutputPower;
|
|||
|
ropCommand->m_Ref = this;
|
|||
|
ropCommand->isNeedDel = false;
|
|||
|
|
|||
|
//读取模块错误代码
|
|||
|
Command* rmecCommand = new YLRReadCommand("RMEC");
|
|||
|
rmecCommand->m_Fun = &IPGLaserClientV1::PorcModuleErrorCode;
|
|||
|
rmecCommand->m_Ref = this;
|
|||
|
rmecCommand->isNeedDel = false;
|
|||
|
|
|||
|
//读取设备状态
|
|||
|
Command* staCommand = new YLRReadCommand("STA");
|
|||
|
staCommand->m_Fun = &IPGLaserClientV1::PorcDeviceStatus;
|
|||
|
staCommand->m_Ref = this;
|
|||
|
staCommand->isNeedDel = false;
|
|||
|
|
|||
|
m_CycleCommands.push_back(rcsCommand);
|
|||
|
m_CycleCommands.push_back(rctCommand);
|
|||
|
m_CycleCommands.push_back(ropCommand);
|
|||
|
m_CycleCommands.push_back(rmecCommand);
|
|||
|
m_CycleCommands.push_back(staCommand);
|
|||
|
}
|
|||
|
|
|||
|
void IPGLaserClientV1::ResetAlarm()
|
|||
|
{
|
|||
|
if (!m_Client.IsOpen())return;
|
|||
|
Command* reerCommand = new YLREchoCommand("RERR");
|
|||
|
EnterCriticalSection(&m_RtcCS);
|
|||
|
m_RTCommands.push(reerCommand);
|
|||
|
LeaveCriticalSection(&m_RtcCS);
|
|||
|
}
|
|||
|
|
|||
|
void IPGLaserClientV1::PorcReadCurrentSetpoint(void* pobject, Command* pcommand)
|
|||
|
{
|
|||
|
if (pobject == NULL)return;
|
|||
|
IPGLaserClientV1* client = (IPGLaserClientV1*)pobject;
|
|||
|
YLRReadCommand* ylrCommand = (YLRReadCommand*)pcommand;
|
|||
|
string strvalue = ylrCommand->GetValue();
|
|||
|
if (strvalue.empty())return;
|
|||
|
float fvalue = 0.0f;
|
|||
|
bool rel = true;
|
|||
|
try {
|
|||
|
fvalue = stof(strvalue);
|
|||
|
}
|
|||
|
catch (std::invalid_argument&) {
|
|||
|
rel = false;
|
|||
|
}
|
|||
|
catch (std::out_of_range&)
|
|||
|
{
|
|||
|
rel = false;
|
|||
|
}
|
|||
|
catch (...) {
|
|||
|
rel = false;
|
|||
|
}
|
|||
|
if (!rel)return;
|
|||
|
EnterCriticalSection(&client->m_ValueCS);
|
|||
|
client->m_State.currentSetpoint = fvalue;
|
|||
|
LeaveCriticalSection(&client->m_ValueCS);
|
|||
|
}
|
|||
|
|
|||
|
void IPGLaserClientV1::PorcReadLaserTemp(void* pobject, Command* pcommand)
|
|||
|
{
|
|||
|
if (pobject == NULL)return;
|
|||
|
IPGLaserClientV1* client = (IPGLaserClientV1*)pobject;
|
|||
|
YLRReadCommand* ylrCommand = (YLRReadCommand*)pcommand;
|
|||
|
string strvalue = ylrCommand->GetValue();
|
|||
|
if (strvalue.empty())return;
|
|||
|
float fvalue = 0.0f;
|
|||
|
bool rel = true;
|
|||
|
try {
|
|||
|
fvalue = stof(strvalue);
|
|||
|
}
|
|||
|
catch (std::invalid_argument&) {
|
|||
|
rel = false;
|
|||
|
}
|
|||
|
catch (std::out_of_range&)
|
|||
|
{
|
|||
|
rel = false;
|
|||
|
}
|
|||
|
catch (...) {
|
|||
|
rel = false;
|
|||
|
}
|
|||
|
if (!rel)return;
|
|||
|
EnterCriticalSection(&client->m_ValueCS);;
|
|||
|
client->m_State.laserTemperature = fvalue;
|
|||
|
LeaveCriticalSection(&client->m_ValueCS);
|
|||
|
}
|
|||
|
|
|||
|
void IPGLaserClientV1::PorcModuleErrorCode(void* pobject, Command* pcommand)
|
|||
|
{
|
|||
|
if (pobject == NULL)return;
|
|||
|
IPGLaserClientV1* client = (IPGLaserClientV1*)pobject;
|
|||
|
YLRReadCommand* ylrCommand = (YLRReadCommand*)pcommand;
|
|||
|
string strvalue = ylrCommand->GetValue();
|
|||
|
if (strvalue.empty())return;
|
|||
|
int ivalue = 0;
|
|||
|
bool rel = true;
|
|||
|
try {
|
|||
|
ivalue = stoi(strvalue);
|
|||
|
}
|
|||
|
catch (std::invalid_argument&) {
|
|||
|
rel = false;
|
|||
|
}
|
|||
|
catch (std::out_of_range&)
|
|||
|
{
|
|||
|
rel = false;
|
|||
|
}
|
|||
|
catch (...) {
|
|||
|
rel = false;
|
|||
|
}
|
|||
|
if (!rel)return;
|
|||
|
EnterCriticalSection(&client->m_ValueCS);
|
|||
|
client->m_State.moduleErrorCode = ivalue;
|
|||
|
LeaveCriticalSection(&client->m_ValueCS);
|
|||
|
}
|
|||
|
|
|||
|
void IPGLaserClientV1::PorcDeviceStatus(void* pobject, Command* pcommand)
|
|||
|
{
|
|||
|
if (pobject == NULL)return;
|
|||
|
IPGLaserClientV1* client = (IPGLaserClientV1*)pobject;
|
|||
|
YLRReadCommand* ylrCommand = (YLRReadCommand*)pcommand;
|
|||
|
string strvalue = ylrCommand->GetValue();
|
|||
|
if (strvalue.empty())return;
|
|||
|
int ivalue = 0;
|
|||
|
bool rel = true;
|
|||
|
try {
|
|||
|
ivalue = stoi(strvalue);
|
|||
|
}
|
|||
|
catch (std::invalid_argument&) {
|
|||
|
rel = false;
|
|||
|
}
|
|||
|
catch (std::out_of_range&)
|
|||
|
{
|
|||
|
rel = false;
|
|||
|
}
|
|||
|
catch (...) {
|
|||
|
rel = false;
|
|||
|
}
|
|||
|
if (!rel)return;
|
|||
|
std::bitset<32> bitValut(ivalue);
|
|||
|
|
|||
|
|
|||
|
EnterCriticalSection(&client->m_ValueCS);
|
|||
|
client->m_State.isCommandBufferOverload = bitValut[0];
|
|||
|
client->m_State.isOverheat = bitValut[1];
|
|||
|
client->m_State.isEmissionOn = bitValut[2];
|
|||
|
client->m_State.isHighBackReflectionLevel = bitValut[3];
|
|||
|
client->m_State.isAnalogPowerControlEnable = bitValut[4];
|
|||
|
client->m_State.isAimingBeamON = bitValut[8];
|
|||
|
client->m_State.isPowerSupplyOff = bitValut[11];
|
|||
|
client->m_State.isModulationEnabled = bitValut[12];
|
|||
|
client->m_State.isEmission = bitValut[15];
|
|||
|
client->m_State.isGateModeEnable = bitValut[16];
|
|||
|
client->m_State.isHardwareEmissionCtrlEnabled = bitValut[18];
|
|||
|
client->m_State.isPowerSupplyFailure = bitValut[19];
|
|||
|
client->m_State.isLowTemperature = bitValut[24];
|
|||
|
client->m_State.isPowerSupplyAlarm = bitValut[25];
|
|||
|
client->m_State.isHardwareAimingBeanControlEnable = bitValut[27];
|
|||
|
client->m_State.isCritialError = bitValut[29];
|
|||
|
client->m_State.isFiberInterlockActive = bitValut[30];
|
|||
|
bool hasAlarm = false;
|
|||
|
SignalService& ss = SignalService::GetInstance();
|
|||
|
if (client->m_State.isOverheat) {
|
|||
|
ss.SetAlarm(client->m_LaserAlarm, true);
|
|||
|
client->m_LaserAlarm->m_AlarmInfo = _(u8"温度过高").c_str();
|
|||
|
hasAlarm = true;
|
|||
|
}
|
|||
|
if (client->m_State.isLowTemperature) {
|
|||
|
ss.SetAlarm(client->m_LaserAlarm, true);
|
|||
|
client->m_LaserAlarm->m_AlarmInfo = _(u8"温度过低").c_str();
|
|||
|
hasAlarm = true;
|
|||
|
}
|
|||
|
if (client->m_State.isHighBackReflectionLevel) {
|
|||
|
ss.SetAlarm(client->m_LaserAlarm, true);
|
|||
|
client->m_LaserAlarm->m_AlarmInfo = _(u8"高反报警").c_str();
|
|||
|
hasAlarm = true;
|
|||
|
}
|
|||
|
|
|||
|
if (client->m_State.isPowerSupplyOff) {
|
|||
|
ss.SetAlarm(client->m_LaserAlarm, true);
|
|||
|
client->m_LaserAlarm->m_AlarmInfo = _(u8"模块主电源关闭").c_str();
|
|||
|
hasAlarm = true;
|
|||
|
}
|
|||
|
if (client->m_State.isPowerSupplyFailure) {
|
|||
|
ss.SetAlarm(client->m_LaserAlarm, true);
|
|||
|
client->m_LaserAlarm->m_AlarmInfo = _(u8"模块主电源故障").c_str();
|
|||
|
hasAlarm = true;
|
|||
|
}
|
|||
|
if (client->m_State.isPowerSupplyAlarm) {
|
|||
|
ss.SetAlarm(client->m_LaserAlarm, true);
|
|||
|
client->m_LaserAlarm->m_AlarmInfo = _(u8"供电报警").c_str();
|
|||
|
hasAlarm = true;
|
|||
|
}
|
|||
|
if (client->m_State.isCritialError) {
|
|||
|
ss.SetAlarm(client->m_LaserAlarm, true);
|
|||
|
client->m_LaserAlarm->m_AlarmInfo = _(u8"关键错误").c_str();
|
|||
|
hasAlarm = true;
|
|||
|
}
|
|||
|
if (client->m_State.isFiberInterlockActive) {
|
|||
|
ss.SetAlarm(client->m_LaserAlarm, true);
|
|||
|
client->m_LaserAlarm->m_AlarmInfo = _(u8"光路内部锁定").c_str();
|
|||
|
hasAlarm = true;
|
|||
|
}
|
|||
|
|
|||
|
if (!hasAlarm) {
|
|||
|
ss.SetAlarm(client->m_LaserAlarm, false);
|
|||
|
}
|
|||
|
|
|||
|
LeaveCriticalSection(&client->m_ValueCS);
|
|||
|
}
|
|||
|
|
|||
|
void IPGLaserClientV1::PorcReadOutputPower(void* pobject, Command* pcommand)
|
|||
|
{
|
|||
|
if (pobject == NULL)return;
|
|||
|
IPGLaserClientV1* client = (IPGLaserClientV1*)pobject;
|
|||
|
YLRReadCommand* ylrCommand = (YLRReadCommand*)pcommand;
|
|||
|
string strvalue = ylrCommand->GetValue();
|
|||
|
if (strvalue.empty())return;
|
|||
|
int ivalue = 0;
|
|||
|
bool rel = true;
|
|||
|
EnterCriticalSection(&client->m_ValueCS);
|
|||
|
client->m_State.outputPower = strvalue;
|
|||
|
LeaveCriticalSection(&client->m_ValueCS);
|
|||
|
}
|
|||
|
|
|||
|
void IPGLaserClientV1::GetState(IPGLaserStateV1& state)
|
|||
|
{
|
|||
|
EnterCriticalSection(&m_ValueCS);
|
|||
|
state.currentSetpoint = m_State.currentSetpoint;
|
|||
|
state.laserTemperature = m_State.laserTemperature;
|
|||
|
state.moduleErrorCode = m_State.moduleErrorCode;
|
|||
|
state.outputPower = m_State.outputPower;
|
|||
|
state.isCommandBufferOverload = m_State.isCommandBufferOverload;
|
|||
|
state.isOverheat = m_State.isOverheat;
|
|||
|
state.isEmissionOn = m_State.isEmissionOn;
|
|||
|
state.isHighBackReflectionLevel = m_State.isHighBackReflectionLevel;
|
|||
|
state.isAnalogPowerControlEnable = m_State.isAnalogPowerControlEnable;
|
|||
|
state.isAimingBeamON = m_State.isAimingBeamON;
|
|||
|
//state.isPulseTooShort = m_State.isPulseTooShort;
|
|||
|
// state.isPulseMode = m_State.isPulseMode;
|
|||
|
state.isPowerSupplyOff = m_State.isPowerSupplyOff;
|
|||
|
state.isModulationEnabled = m_State.isModulationEnabled;
|
|||
|
state.isEmission = m_State.isEmission;
|
|||
|
state.isGateModeEnable = m_State.isGateModeEnable;
|
|||
|
state.isHardwareEmissionCtrlEnabled = m_State.isHardwareEmissionCtrlEnabled;
|
|||
|
state.isPowerSupplyFailure = m_State.isPowerSupplyFailure;
|
|||
|
state.isLowTemperature = m_State.isLowTemperature;
|
|||
|
state.isPowerSupplyAlarm = m_State.isPowerSupplyAlarm;
|
|||
|
state.isHardwareAimingBeanControlEnable = m_State.isHardwareAimingBeanControlEnable;
|
|||
|
state.isCritialError = m_State.isCritialError;
|
|||
|
state.isFiberInterlockActive = m_State.isFiberInterlockActive;
|
|||
|
|
|||
|
// state.isAveragePowerTooHigh = m_State.isAveragePowerTooHigh;
|
|||
|
LeaveCriticalSection(&m_ValueCS);
|
|||
|
}
|
|||
|
|
|||
|
void IPGLaserClientV1::DrawClientState()
|
|||
|
{
|
|||
|
IPGLaserStateV1 state;
|
|||
|
GetState(state);
|
|||
|
if (ImGui::BeginTabItem(GetConfig()->m_ClientCode.c_str())) {
|
|||
|
ImGui::BeginGroup();
|
|||
|
ImGui::Text(_(u8"激光端口连接:").c_str()); ImGui::SameLine();
|
|||
|
if (IsServerConnected()) {
|
|||
|
ImGui::TextColored(ImVec4(0.0, 1.0, 0.0, 1.0), _(u8"正常").c_str());
|
|||
|
}
|
|||
|
else {
|
|||
|
ImGui::TextColored(ImVec4(1.0, 0.0, 0.0, 1.0), _(u8"断开").c_str());
|
|||
|
}
|
|||
|
ImGui::Text(_(u8"激光通讯连接:").c_str()); ImGui::SameLine();
|
|||
|
if (IsComConnected()) {
|
|||
|
ImGui::TextColored(ImVec4(0.0, 1.0, 0.0, 1.0), _(u8"正常").c_str());
|
|||
|
}
|
|||
|
else ImGui::TextColored(ImVec4(1.0, 0.0, 0.0, 1.0), _(u8"断开").c_str());
|
|||
|
|
|||
|
ImGui::Text(_(u8"输出功率:").c_str()); ImGui::SameLine(); ImGui::Text("%s", state.outputPower.c_str());
|
|||
|
ImGui::Text(_(u8"激光二极管电流:").c_str()); ImGui::SameLine(); ImGui::Text("%.1f", state.currentSetpoint);
|
|||
|
ImGui::Text(_(u8"内部实际温度:").c_str()); ImGui::SameLine(); ImGui::Text("%.1f", state.laserTemperature);
|
|||
|
ImGui::Text(_(u8"激光使能:").c_str()); ImGui::SameLine(); ImGui::Text("%s", state.isEmissionOn ? _(u8"是").c_str() : _(u8"否").c_str());
|
|||
|
ImGui::Text(_(u8"激光发射:").c_str()); ImGui::SameLine(); ImGui::Text("%s", state.isEmission ? _(u8"发射").c_str() : _(u8"停止").c_str());
|
|||
|
ImGui::Text(_(u8"引导红光:").c_str()); ImGui::SameLine(); ImGui::Text("%s", state.isAimingBeamON ? _(u8"开启").c_str() : _(u8"关闭").c_str());
|
|||
|
ImGui::Text(_(u8"外部功率控制:").c_str()); ImGui::SameLine(); ImGui::Text("%s", state.isAnalogPowerControlEnable ? _(u8"开启").c_str() : _(u8"关闭").c_str());
|
|||
|
ImGui::Text(_(u8"外部使能控制:").c_str()); ImGui::SameLine(); ImGui::Text("%s", state.isHardwareEmissionCtrlEnabled ? _(u8"开启").c_str() : _(u8"关闭").c_str());
|
|||
|
ImGui::Text(_(u8"外部红光控制:").c_str()); ImGui::SameLine(); ImGui::Text("%s", state.isHardwareAimingBeanControlEnable ? _(u8"开启").c_str() : _(u8"关闭").c_str());
|
|||
|
ImGui::Text(_(u8"调制模式:").c_str()); ImGui::SameLine(); ImGui::Text("%s", state.isModulationEnabled ? _(u8"开启").c_str() : _(u8"关闭").c_str());
|
|||
|
ImGui::Text(_(u8"门模式").c_str()); ImGui::SameLine(); ImGui::Text("%s", state.isGateModeEnable ? _(u8"开启").c_str() : _(u8"关闭").c_str());
|
|||
|
ImGui::EndGroup();
|
|||
|
|
|||
|
ImGui::SameLine(0, 20);
|
|||
|
ImGui::SeparatorEx(ImGuiSeparatorFlags_Vertical);
|
|||
|
ImGui::SameLine();
|
|||
|
|
|||
|
ImGui::BeginGroup();
|
|||
|
ImGui::Text(_(u8"模块错误代码:").c_str()); ImGui::SameLine();
|
|||
|
if (state.moduleErrorCode != 0) ImGui::TextColored(Toast::COLOR_RED, "%d", state.moduleErrorCode);
|
|||
|
else ImGui::TextColored(Toast::COLOR_GREEN, "%d", state.moduleErrorCode);
|
|||
|
|
|||
|
ImGui::Text(_(u8"温度过高:").c_str()); ImGui::SameLine();
|
|||
|
if (state.isOverheat) ImGui::TextColored(Toast::COLOR_RED, _(u8"报警").c_str());
|
|||
|
else ImGui::TextColored(Toast::COLOR_GREEN, _(u8"正常").c_str());
|
|||
|
|
|||
|
ImGui::Text(_(u8"温度过低:").c_str()); ImGui::SameLine();
|
|||
|
if (state.isLowTemperature) ImGui::TextColored(Toast::COLOR_RED, _(u8"报警").c_str());
|
|||
|
else ImGui::TextColored(Toast::COLOR_GREEN, _(u8"正常").c_str());
|
|||
|
|
|||
|
ImGui::Text(_(u8"高反报警:").c_str()); ImGui::SameLine();
|
|||
|
if (state.isHighBackReflectionLevel) ImGui::TextColored(Toast::COLOR_RED, _(u8"报警").c_str());
|
|||
|
else ImGui::TextColored(Toast::COLOR_GREEN, _(u8"正常").c_str());
|
|||
|
|
|||
|
ImGui::Text(_(u8"模块主电源关闭:").c_str()); ImGui::SameLine();
|
|||
|
if (state.isPowerSupplyOff) ImGui::TextColored(Toast::COLOR_RED, _(u8"报警").c_str());
|
|||
|
else ImGui::TextColored(Toast::COLOR_GREEN, _(u8"正常").c_str());
|
|||
|
|
|||
|
ImGui::Text(_(u8"模块主电源故障:").c_str()); ImGui::SameLine();
|
|||
|
if (state.isPowerSupplyFailure) ImGui::TextColored(Toast::COLOR_RED, _(u8"报警").c_str());
|
|||
|
else ImGui::TextColored(Toast::COLOR_GREEN, _(u8"正常").c_str());
|
|||
|
|
|||
|
ImGui::Text(_(u8"供电报警:").c_str()); ImGui::SameLine();
|
|||
|
if (state.isPowerSupplyAlarm) ImGui::TextColored(Toast::COLOR_RED, _(u8"报警").c_str());
|
|||
|
else ImGui::TextColored(Toast::COLOR_GREEN, _(u8"正常").c_str());
|
|||
|
|
|||
|
ImGui::Text(_(u8"关键错误:").c_str()); ImGui::SameLine();
|
|||
|
if (state.isCritialError) ImGui::TextColored(Toast::COLOR_RED, _(u8"报警").c_str());
|
|||
|
else ImGui::TextColored(Toast::COLOR_GREEN, _(u8"正常").c_str());
|
|||
|
|
|||
|
ImGui::Text(_(u8"光路内部锁定:").c_str()); ImGui::SameLine();
|
|||
|
if (state.isFiberInterlockActive) ImGui::TextColored(Toast::COLOR_RED, _(u8"报警").c_str());
|
|||
|
else ImGui::TextColored(Toast::COLOR_GREEN, _(u8"正常").c_str());
|
|||
|
|
|||
|
if (ImGui::Button(_(u8"复位报警信息").c_str(), ImVec2(150, 0))) {
|
|||
|
ResetAlarm();
|
|||
|
g_Toast->AddToast(new ToastBean(_(u8"请求复位报警信息").c_str(), 3000));
|
|||
|
}
|
|||
|
|
|||
|
ImGui::EndGroup();
|
|||
|
ImGui::SameLine(0, 20);
|
|||
|
ImGui::Spacing();
|
|||
|
ImGui::EndTabItem();
|
|||
|
}
|
|||
|
}
|