402 lines
11 KiB
C++
402 lines
11 KiB
C++
#include "MachineCtrl.h"
|
|
#include "../config/ConfigManager.h"
|
|
#include "../Toast.h"
|
|
#include "../Logger.h"
|
|
#include "SignalService.h"
|
|
|
|
MachineCtrl::MachineCtrl()
|
|
{
|
|
m_Invoker = new PLCInvoker();
|
|
}
|
|
|
|
|
|
MachineCtrl::~MachineCtrl()
|
|
{
|
|
if (m_Invoker)delete m_Invoker;
|
|
}
|
|
|
|
void MachineCtrl::Init(PLCReveiver* receiver, SysParamWrapper* sysParamWrapper, SignalStateWrapper* alarmStateWrapper, PLCAxis* axis)
|
|
{
|
|
m_SysParamWrapper = sysParamWrapper;
|
|
m_SignalStateWrapper = alarmStateWrapper;
|
|
m_Axis = axis;
|
|
m_IOCfgWrapper = ConfigManager::GetInstance()->GetIoCfgWrapper();
|
|
m_RunCfg = ConfigManager::GetInstance()->GetRunCfg();
|
|
m_ExtCfg = ConfigManager::GetInstance()->GetExtCfg();
|
|
m_MachineCfg = ConfigManager::GetInstance()->GetMachineCfg();
|
|
m_CoverParamCommand = new CoverParamCommand(receiver, m_SysParamWrapper->m_LayerThick, m_SysParamWrapper->m_SupplyCount, m_SignalStateWrapper->m_IsCoverDebug, m_SignalStateWrapper->m_IsFirstCover);
|
|
}
|
|
|
|
void MachineCtrl::StartLaser(bool iswait)
|
|
{
|
|
HANDLE starthread = AtlCreateThread(StartLaserProc, this);
|
|
if (iswait) {
|
|
WaitForSingleObject(starthread, INFINITE);
|
|
}
|
|
CloseHandle(starthread);
|
|
}
|
|
|
|
DWORD WINAPI MachineCtrl::StartLaserProc(MachineCtrl* _this)
|
|
{
|
|
if (_this) {
|
|
_this->StartLaserRun();
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
void MachineCtrl::StartLaserRun() {
|
|
g_Toast->AddToast(new ToastBean(g_LngManager->Log_StartingLaser->ShowText(), 2000, ImVec4(1, 0.4, 0, 1)));
|
|
vector<ScannerControlCfg*>* laserCfg = ConfigManager::GetInstance()->GetMatchScannerControlCfg();
|
|
|
|
if (m_IOCfgWrapper->m_LaserPowerActive) {
|
|
if (!m_IOCfgWrapper->m_Laser->IsActive()) {
|
|
bool hasEn = false;
|
|
for (size_t laserIndex = 0; laserIndex < laserCfg->size(); ++laserIndex) {
|
|
IOCfg* enablecfg = (*laserCfg)[laserIndex]->m_LaserEnable;
|
|
if (enablecfg && enablecfg->IsActive()) {
|
|
enablecfg->SetActive(false);
|
|
hasEn = true;
|
|
}
|
|
}
|
|
if (hasEn)Sleep(2000);
|
|
bool hasSt = false;
|
|
for (size_t laserIndex = 0; laserIndex < laserCfg->size(); ++laserIndex) {
|
|
IOCfg* startCfg = (*laserCfg)[laserIndex]->m_LaserStart;
|
|
if (startCfg && startCfg->IsActive()) {
|
|
startCfg->SetActive(false);
|
|
hasSt = true;
|
|
}
|
|
}
|
|
if (hasSt)Sleep(2000);
|
|
m_IOCfgWrapper->m_Laser->SetActive(true);
|
|
Sleep(m_ExtCfg->m_AftLaserPowerWaitSecond * 1000);
|
|
}
|
|
|
|
if (!m_IOCfgWrapper->m_LaserPowerActive->IsActive()) {
|
|
m_IOCfgWrapper->m_LaserPowerActive->SetActive(true);
|
|
Sleep(20000);
|
|
}
|
|
|
|
bool hasSt = false;
|
|
for (size_t laserIndex = 0; laserIndex < laserCfg->size(); ++laserIndex) {
|
|
if ((*laserCfg)[laserIndex]->m_IsEnable) {
|
|
IOCfg* startCfg = (*laserCfg)[laserIndex]->m_LaserStart;
|
|
if (startCfg && !startCfg->IsActive()) {
|
|
startCfg->SetActive(true);
|
|
hasSt = true;
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
if (hasSt)Sleep(m_ExtCfg->m_AftLaserStartWaitSecond * 1000);
|
|
bool hasEn = false;
|
|
for (size_t laserIndex = 0; laserIndex < laserCfg->size(); ++laserIndex) {
|
|
if ((*laserCfg)[laserIndex]->m_IsEnable) {
|
|
IOCfg* enablecfg = (*laserCfg)[laserIndex]->m_LaserEnable;
|
|
if (enablecfg && !enablecfg->IsActive()) {
|
|
enablecfg->SetActive(true);
|
|
hasEn = true;
|
|
}
|
|
}
|
|
}
|
|
if (hasEn)Sleep(m_ExtCfg->m_AftLaserEnableWaitSecond * 1000);
|
|
}
|
|
else {
|
|
if (!m_IOCfgWrapper->m_Laser->IsActive()) {
|
|
bool hasEn = false;
|
|
for (size_t laserIndex = 0; laserIndex < laserCfg->size(); ++laserIndex) {
|
|
IOCfg* enablecfg = (*laserCfg)[laserIndex]->m_LaserEnable;
|
|
if (enablecfg && enablecfg->IsActive()) {
|
|
enablecfg->SetActive(false);
|
|
hasEn = true;
|
|
}
|
|
}
|
|
if (hasEn)Sleep(5000);
|
|
bool hasSt = false;
|
|
for (size_t laserIndex = 0; laserIndex < laserCfg->size(); ++laserIndex) {
|
|
IOCfg* startCfg = (*laserCfg)[laserIndex]->m_LaserStart;
|
|
if (startCfg && startCfg->IsActive()) {
|
|
startCfg->SetActive(false);
|
|
hasSt = true;
|
|
}
|
|
}
|
|
if (hasSt)Sleep(5000);
|
|
m_IOCfgWrapper->m_Laser->SetActive(true);
|
|
Sleep(m_ExtCfg->m_AftLaserPowerWaitSecond * 1000);
|
|
}
|
|
|
|
bool hasSt = false;
|
|
for (size_t laserIndex = 0; laserIndex < laserCfg->size(); ++laserIndex) {
|
|
if ((*laserCfg)[laserIndex]->m_IsEnable) {
|
|
IOCfg* startCfg = (*laserCfg)[laserIndex]->m_LaserStart;
|
|
if (startCfg && !startCfg->IsActive()) {
|
|
startCfg->SetActive(true);
|
|
hasSt = true;
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
if (hasSt)Sleep(m_ExtCfg->m_AftLaserStartWaitSecond * 1000);
|
|
bool hasEn = false;
|
|
for (size_t laserIndex = 0; laserIndex < laserCfg->size(); ++laserIndex) {
|
|
if ((*laserCfg)[laserIndex]->m_IsEnable) {
|
|
IOCfg* enablecfg = (*laserCfg)[laserIndex]->m_LaserEnable;
|
|
if (enablecfg && !enablecfg->IsActive()) {
|
|
enablecfg->SetActive(true);
|
|
hasEn = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (hasEn)Sleep(m_ExtCfg->m_AftLaserEnableWaitSecond * 1000);
|
|
|
|
|
|
}
|
|
|
|
g_Toast->AddToast(new ToastBean(_(u8"激光器已经启动").c_str(), 2000, ImVec4(0, 1, 0, 1)));
|
|
g_log->TraceInfo(_(u8"激光器已经启动").c_str());
|
|
}
|
|
|
|
void MachineCtrl::StopLaser(bool iswait)
|
|
{
|
|
HANDLE stopthread = AtlCreateThread(StopLaserProc, this);
|
|
if (iswait) {
|
|
WaitForSingleObject(stopthread, INFINITE);
|
|
}
|
|
CloseHandle(stopthread);
|
|
}
|
|
|
|
DWORD WINAPI MachineCtrl::StopLaserProc(MachineCtrl* _this)
|
|
{
|
|
if (_this) {
|
|
_this->StopLaserRun();
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
void MachineCtrl::StopLaserRun()
|
|
{
|
|
g_Toast->AddToast(new ToastBean(g_LngManager->Log_StopingLaser->ShowText(), 2000));
|
|
vector<ScannerControlCfg*>* laserCfg = ConfigManager::GetInstance()->GetMatchScannerControlCfg();
|
|
bool hasEn = false;
|
|
for (size_t laserIndex = 0; laserIndex < laserCfg->size(); ++laserIndex) {
|
|
IOCfg* enablecfg = (*laserCfg)[laserIndex]->m_LaserEnable;
|
|
if (enablecfg && enablecfg->IsActive()) {
|
|
enablecfg->SetActive(false);
|
|
hasEn = true;
|
|
}
|
|
}
|
|
if (hasEn)Sleep(5000);
|
|
bool hasSt = false;
|
|
|
|
for (size_t laserIndex = 0; laserIndex < laserCfg->size(); ++laserIndex) {
|
|
IOCfg* startcfg = (*laserCfg)[laserIndex]->m_LaserStart;
|
|
if (startcfg && startcfg->IsActive()) {
|
|
startcfg->SetActive(false);
|
|
hasSt = true;
|
|
}
|
|
}
|
|
if (hasSt)Sleep(5000);
|
|
|
|
g_Toast->AddToast(new ToastBean(g_LngManager->Log_StopedLaser->ShowText(), 2000));
|
|
g_log->TraceInfo(g_LngManager->Log_StopedLaser->ShowText());
|
|
|
|
}
|
|
|
|
bool MachineCtrl::IsLaserActive()
|
|
{
|
|
bool active = false;
|
|
vector<ScannerControlCfg*>* laserCfg = ConfigManager::GetInstance()->GetMatchScannerControlCfg();
|
|
for (size_t laserIndex = 0; laserIndex < laserCfg->size(); ++laserIndex) {
|
|
IOCfg* enablecfg = (*laserCfg)[laserIndex]->m_LaserEnable;
|
|
IOCfg* startcfg = (*laserCfg)[laserIndex]->m_LaserStart;
|
|
if (enablecfg && enablecfg->IsActive()) {
|
|
active = true;
|
|
break;
|
|
}
|
|
if (startcfg && startcfg->IsActive()) {
|
|
active = true;
|
|
break;
|
|
}
|
|
}
|
|
return active;
|
|
}
|
|
|
|
bool MachineCtrl::IsLaserOn()
|
|
{
|
|
if (!m_IOCfgWrapper->m_Laser->IsActive()) {
|
|
return false;
|
|
}
|
|
vector<ScannerControlCfg*>* laserCfgs = ConfigManager::GetInstance()->GetMatchScannerControlCfg();
|
|
for (size_t i = 0; i < laserCfgs->size(); i++) {
|
|
ScannerControlCfg* laserCfg = (*laserCfgs)[i];
|
|
if (laserCfg->m_IsEnable) {
|
|
if (!laserCfg->m_LaserEnable->IsActive() || !laserCfg->m_LaserStart->IsActive()) {
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
void MachineCtrl::StopLaserByCfg(ScannerControlCfg* cfg)
|
|
{
|
|
m_StopLaserCfg = cfg;
|
|
HANDLE stopthread = AtlCreateThread(StopLaserByCfgProc, this);
|
|
CloseHandle(stopthread);
|
|
}
|
|
|
|
DWORD WINAPI MachineCtrl::StopLaserByCfgProc(MachineCtrl* _this)
|
|
{
|
|
if (_this) {
|
|
_this->StopLaserByCfgRun();
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
void MachineCtrl::StopLaserByCfgRun()
|
|
{
|
|
if (!m_StopLaserCfg)return;
|
|
char buffer[256];
|
|
sprintf_s(buffer, sizeof(buffer), g_LngManager->UI_StopingLaserInfo->ShowText(), m_StopLaserCfg->m_CardName->GetValueStr().c_str());
|
|
g_Toast->AddToast(new ToastBean(buffer, 2000));
|
|
if (m_StopLaserCfg->m_LaserEnable->IsActive()) {
|
|
m_StopLaserCfg->m_LaserEnable->SetActive(false);
|
|
Sleep(8000);
|
|
}
|
|
if (m_StopLaserCfg->m_LaserStart->IsActive()) {
|
|
m_StopLaserCfg->m_LaserStart->SetActive(false);
|
|
}
|
|
sprintf_s(buffer, sizeof(buffer), g_LngManager->UI_StopedLaserInfo->ShowText(), m_StopLaserCfg->m_CardName->GetValueStr().c_str());
|
|
g_Toast->AddToast(new ToastBean(buffer, 2000));
|
|
}
|
|
|
|
void MachineCtrl::MachineStartup()
|
|
{
|
|
HANDLE thread = AtlCreateThread(StartUpProc, this);
|
|
CloseHandle(thread);
|
|
}
|
|
|
|
DWORD WINAPI MachineCtrl::StartUpProc(MachineCtrl* _this)
|
|
{
|
|
if (_this) {
|
|
_this->StartUpRun();
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
void MachineCtrl::StartUpRun()
|
|
{
|
|
Sleep(3000);
|
|
m_IOCfgWrapper->m_LightOn->SetActive(true);
|
|
//m_IOCfgWrapper->m_ServoMotor->SetActive(true);
|
|
Sleep(200);
|
|
|
|
m_IOCfgWrapper->m_Laser->SetActive(true);
|
|
// m_SignalStateWrapper->m_SheildPrintPosSensor->SetValue(true);
|
|
// m_SignalStateWrapper->m_SheildCylinderSensor->SetValue(true);
|
|
// m_SignalStateWrapper->m_SheildLeftRightLocSensor->SetValue(true);
|
|
}
|
|
|
|
void MachineCtrl::MachineStop()
|
|
{
|
|
HANDLE thread = AtlCreateThread(ShutdownProc, this);
|
|
WaitForSingleObject(thread, INFINITE);
|
|
}
|
|
|
|
DWORD WINAPI MachineCtrl::ShutdownProc(MachineCtrl* _this)
|
|
{
|
|
if (_this) {
|
|
_this->ShutdownRun();
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
void MachineCtrl::ShutdownRun()
|
|
{
|
|
m_IOCfgWrapper->m_LightOn->SetActive(false);
|
|
|
|
Sleep(200);
|
|
}
|
|
|
|
void MachineCtrl::ExecuteCover(float layerThick, short powderCount, bool isCoverDebug, bool isFirst)
|
|
{
|
|
//g_log->TraceInfo("LayerThick:%f", layerThick);
|
|
m_CoverParamCommand->SetValue(layerThick, powderCount, isCoverDebug, isFirst);
|
|
m_Invoker->SetCommand(m_CoverParamCommand);
|
|
m_Invoker->Call();
|
|
m_SignalStateWrapper->m_CoverTriger->SetValue(true);
|
|
}
|
|
|
|
void MachineCtrl::ExecuteDataSizeY(float miny, float maxy) {
|
|
m_SysParamWrapper->m_DataSizeMaxY->SetValue(maxy);
|
|
m_SysParamWrapper->m_DataSizeMinY->SetValue(miny);
|
|
}
|
|
|
|
void MachineCtrl::MoldMoveUp(float fvalue, bool iswait)
|
|
{
|
|
AxisConfig* moldCfg = m_Axis->m_Mold->GetConfig();
|
|
moldCfg->m_RefDistance->SetValue(fvalue);
|
|
Sleep(50);
|
|
m_Axis->m_Mold->MovPoint(AxisConfig::ActiveDirect::UP);
|
|
//g_log->TraceInfo(u8"升降往上运动:%.1f", fvalue);
|
|
if (iswait)
|
|
{
|
|
Sleep(200);
|
|
int count = 0;
|
|
AxisStateValue asv;
|
|
m_Axis->m_Mold->GetState()->GetValue(asv);
|
|
while (asv.ServoBusy)
|
|
{
|
|
Sleep(100);
|
|
m_Axis->m_Mold->GetState()->GetValue(asv);
|
|
}
|
|
}
|
|
}
|
|
|
|
void MachineCtrl::MoldMoveDown(float fvalue, bool iswait)
|
|
{
|
|
AxisConfig* moldCfg = m_Axis->m_Mold->GetConfig();
|
|
moldCfg->m_RefDistance->SetValue(fvalue);
|
|
Sleep(50);
|
|
m_Axis->m_Mold->MovPoint(AxisConfig::ActiveDirect::DOWN);
|
|
//g_log->TraceInfo(u8"升降往下运动:%.1f", fvalue);
|
|
if (iswait)
|
|
{
|
|
Sleep(200);
|
|
int count = 0;
|
|
AxisStateValue asv;
|
|
m_Axis->m_Mold->GetState()->GetValue(asv);
|
|
while (asv.ServoBusy)
|
|
{
|
|
Sleep(100);
|
|
m_Axis->m_Mold->GetState()->GetValue(asv);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
int MachineCtrl::GetTimeWhenExit() {
|
|
int rel = 0;
|
|
vector<ScannerControlCfg*>* laserCfgs = ConfigManager::GetInstance()->GetMatchScannerControlCfg();
|
|
for (size_t i = 0; i < laserCfgs->size(); i++) {
|
|
ScannerControlCfg* laserCfg = (*laserCfgs)[i];
|
|
if (laserCfg->m_LaserEnable && laserCfg->m_LaserEnable->IsActive()) {
|
|
rel += 8000;
|
|
break;
|
|
}
|
|
}
|
|
for (size_t i = 0; i < laserCfgs->size(); i++) {
|
|
ScannerControlCfg* laserCfg = (*laserCfgs)[i];
|
|
if (laserCfg->m_LaserStart && laserCfg->m_LaserStart->IsActive()) {
|
|
rel += 5000;
|
|
break;
|
|
}
|
|
}
|
|
return rel;
|
|
}
|
|
|