| | |
| | | #include "Servo.h" |
| | | #include "afxdialogex.h" |
| | | #include "PageRecipe.h" |
| | | #include "MsgDlg.h" |
| | | #include "RecipeDeviceBindDlg.h" |
| | | |
| | | |
| | | // CPageRecipe 对话框 |
| | | |
| | |
| | | FillDataToListCtrl(vecData); |
| | | } |
| | | else { |
| | | // enable port |
| | | CMsgDlg msgDlg("请等待", "正在获取配方..."); |
| | | pEq->masterRecipeListRequest(0, [&, pEq](int status) -> void { |
| | | if (status == SS_FAILED || status == SS_TIMEOUT) { |
| | | CString strMsg; |
| | | strMsg.Format(status == SS_FAILED ? _T("获取配方失败!") : _T("获取配方超时!")); |
| | | msgDlg.DelayClose(3000); |
| | | msgDlg.SetIcon(MSG_BOX_ERROR); |
| | | msgDlg.SetTitle(_T("操作失败")); |
| | | msgDlg.SetMessage((LPTSTR)(LPCTSTR)strMsg); |
| | | msgDlg.SetMarquee(FALSE, 0); |
| | | msgDlg.SetCompleteCode(-1); |
| | | } |
| | | else if (status == SS_COMPLETE) { |
| | | CString strMsg; |
| | | strMsg.Format(_T("获取配方完成!")); |
| | | msgDlg.DelayClose(3000); |
| | | msgDlg.SetIcon(MSG_BOX_SUCCEED); |
| | | msgDlg.SetTitle(_T("操作成功")); |
| | | msgDlg.SetMessage((LPTSTR)(LPCTSTR)strMsg); |
| | | msgDlg.SetMarquee(FALSE, 0); |
| | | msgDlg.SetCompleteCode(0); |
| | | SERVO::CRecipeList* pRecipeList = pEq->getRecipeList(0); |
| | | FillRecipeListToListCtrl(pRecipeList); |
| | | } |
| | | }); |
| | | // 获取配方列表 |
| | | CMsgDlg msgDlg("请等待", "正在获取配方列表..."); |
| | | msgDlg.SetData((DWORD_PTR)this); |
| | | msgDlg.SetDataEx((DWORD_PTR)pEq); |
| | | msgDlg.BeginThread(SyncThreadFunction); |
| | | msgDlg.DoModal(); |
| | | } |
| | | } |
| | |
| | | FillRecipeListToListCtrl(pRecipeList); |
| | | } |
| | | } |
| | | |
| | | UINT CPageRecipe::SyncThreadFunction(LPVOID lpvData) |
| | | { |
| | | CMsgDlg* pMsgDlg = (CMsgDlg*)lpvData; |
| | | CPageRecipe* pPageRecipe = (CPageRecipe*)pMsgDlg->GetData(); |
| | | return pPageRecipe->SyncThreadFunctionInner(pMsgDlg); |
| | | } |
| | | |
| | | UINT CPageRecipe::SyncThreadFunctionInner(CMsgDlg* pMsgDlg) |
| | | { |
| | | SERVO::CEquipment* pEq = (SERVO::CEquipment*)pMsgDlg->GetDataEx(); |
| | | HANDLE hEvent = ::CreateEvent(NULL, TRUE, FALSE, NULL); |
| | | int nStep = 0; |
| | | pEq->masterRecipeListRequest(0, [&, pEq, pMsgDlg, hEvent](int status) -> void { |
| | | Sleep(300); |
| | | if (status == SS_FAILED || status == SS_TIMEOUT) { |
| | | CString strMsg; |
| | | strMsg.Format(status == SS_FAILED ? _T("获取配方列表失败!") : _T("获取配方列表超时!")); |
| | | pMsgDlg->SetIcon(MSG_BOX_ERROR); |
| | | pMsgDlg->SetTitle(_T("操作失败")); |
| | | pMsgDlg->SetMessage((LPTSTR)(LPCTSTR)strMsg); |
| | | SetEvent(hEvent); |
| | | } |
| | | else if (status == SS_LIST_COMPLETE) { |
| | | CString strMsg; |
| | | strMsg.Format(_T("获取配方列表完成!")); |
| | | pMsgDlg->SetTitle(_T("操作成功")); |
| | | pMsgDlg->SetMessage((LPTSTR)(LPCTSTR)strMsg); |
| | | SERVO::CRecipeList* pRecipeList = pEq->getRecipeList(0); |
| | | if (pRecipeList != nullptr && !pRecipeList->getIds().empty()) { |
| | | nStep = 1; |
| | | } |
| | | SetEvent(hEvent); |
| | | } |
| | | }); |
| | | ::WaitForSingleObject(hEvent, INFINITE); |
| | | if (nStep != 1) { |
| | | pMsgDlg->SetIcon(MSG_BOX_SUCCEED); |
| | | pMsgDlg->SetMarquee(FALSE, 0); |
| | | pMsgDlg->SetCompleteCode(-1); |
| | | pMsgDlg->DelayClose(3000); |
| | | } |
| | | ResetEvent(hEvent); |
| | | |
| | | |
| | | // 参数列表 |
| | | if (nStep == 1) { |
| | | SERVO::CRecipeList* pRecipeList = pEq->getRecipeList(0); |
| | | ASSERT(pRecipeList); |
| | | auto& ids = pRecipeList->getIds(); |
| | | pMsgDlg->SetTitle(_T("正在获取参数")); |
| | | for (auto item : ids) { |
| | | CString strMsg; |
| | | strMsg.Format(_T("正在获取配方 %d 参数..."), item.second); |
| | | pMsgDlg->SetMessage((LPTSTR)(LPCTSTR)strMsg); |
| | | pEq->recipeParameterRequest(0, item.second, 0, [&, pEq, pMsgDlg](int status) -> void { |
| | | Sleep(500); |
| | | if (status == SS_FAILED || status == SS_TIMEOUT) { |
| | | CString strMsg; |
| | | strMsg.Format(status == SS_FAILED ? _T("获取配方 %d 参数失败!") : _T("获取配方 %d 参数超时!"), item.second); |
| | | pMsgDlg->SetMessage((LPTSTR)(LPCTSTR)strMsg); |
| | | |
| | | Sleep(300); |
| | | SetEvent(hEvent); |
| | | } |
| | | else if (status == SS_PARAMS_COMPLETE) { |
| | | CString strMsg; |
| | | strMsg.Format(_T("获取配方 %d 参数完成!"), item.second); |
| | | pMsgDlg->SetMessage((LPTSTR)(LPCTSTR)strMsg); |
| | | |
| | | Sleep(300); |
| | | SetEvent(hEvent); |
| | | } |
| | | }); |
| | | ::WaitForSingleObject(hEvent, INFINITE); |
| | | ResetEvent(hEvent); |
| | | } |
| | | |
| | | pMsgDlg->SetIcon(MSG_BOX_SUCCEED); |
| | | pMsgDlg->SetTitle(_T("操作完成")); |
| | | pMsgDlg->SetCompleteCode(0); |
| | | pMsgDlg->SetMarquee(FALSE, 0); |
| | | pMsgDlg->DelayClose(3000); |
| | | }; |
| | | |
| | | SERVO::CRecipeList* pRecipeList = pEq->getRecipeList(0); |
| | | FillRecipeListToListCtrl(pRecipeList); |
| | | CloseHandle(hEvent); |
| | | |
| | | |
| | | return 0; |
| | | } |