From 4ed7fc8447d202e21ef9907e2aac63ef6fcbf301 Mon Sep 17 00:00:00 2001 From: zxd <zxdvslxy@gmail.com> Date: 星期二, 17 十月 2023 12:33:23 +0800 Subject: [PATCH] 提交图码转换部分修改: 1.基本图形转换 2.ANS\ORS\PSHS\POPS命令的处理 3.重构了转换方法,命名为CMTerm1View::ScanLDSCells2();同时将翻译单独提出为方法CMTerm1View::Translate2Prog() 4.快捷键的添加绑定 5.其他相关方法修改,Insert,Delete,FocusChg…… 6.其他关联修改 --- MTerm2/MTerm2Doc.cpp | 152 ++++++++++++++++++++++++++++++++++++++------------ 1 files changed, 115 insertions(+), 37 deletions(-) diff --git a/MTerm2/MTerm2Doc.cpp b/MTerm2/MTerm2Doc.cpp index 067073d..2622a2a 100644 --- a/MTerm2/MTerm2Doc.cpp +++ b/MTerm2/MTerm2Doc.cpp @@ -26,9 +26,12 @@ #include "MTerm2CommDevView.h" #include <propkey.h> -#include "CDialogCommSet1.h" -#include "CDialogStatusShow.h" - +#include "DialogCommSet1.h" +#include "DialogStatusShow.h" +#include "DialogSysRegSet.h" +#include "DialogFactCfg.h" +#include "DialogDateTime.h" +#include "DialogEventLog.h" #include "HvSerialPort.h" #include <functional> @@ -37,7 +40,7 @@ #endif // CMTerm2Doc -CMTerm2Doc::stTypeDef CMTerm2Doc::CoilTypeDef[] = +CMTerm2Doc::stTypeNameDef CMTerm2Doc::CoilTypeNameDef[] = { {KLCoilTypeX,"X"}, {KLCoilTypeY,"Y"}, @@ -49,9 +52,9 @@ {KLCoilTypeC,"C"}, {KLCoilTypeT,"T"}, }; -int CMTerm2Doc::nCoilTypeDefCount = sizeof(CMTerm2Doc::CoilTypeDef) / sizeof(stTypeDef); +int CMTerm2Doc::nCoilTypeDefCount = sizeof(CMTerm2Doc::CoilTypeNameDef) / sizeof(stTypeNameDef); -CMTerm2Doc::stTypeDef CMTerm2Doc::DataTypeDef[] = +CMTerm2Doc::stTypeNameDef CMTerm2Doc::DataTypeNameDef[] = { {KLDataTypeDEC,"K"}, {KLDataTypeHEX,"H"}, @@ -67,7 +70,7 @@ {KLDataTypeSV,"SV"}, {KLDataTypeLD,"LD"}, }; -int CMTerm2Doc::nDataTypeDefCount = sizeof(CMTerm2Doc::DataTypeDef) / sizeof(stTypeDef); +int CMTerm2Doc::nDataTypeDefCount = sizeof(CMTerm2Doc::DataTypeNameDef) / sizeof(stTypeNameDef); CMTerm2Doc::stOpDef CMTerm2Doc::OpDef[] = { @@ -154,6 +157,9 @@ ON_COMMAND(ID_SIMULATE, &CMTerm2Doc::OnSimulate) ON_UPDATE_COMMAND_UI(ID_SIMULATE, &CMTerm2Doc::OnUpdateSimulate) ON_COMMAND(ID_MENU_STATUS_SHOW, &CMTerm2Doc::OnMenuStatusShow) + ON_COMMAND(ID_MENU_FACT_CFG, &CMTerm2Doc::OnMenuFactCfg) + ON_COMMAND(ID_MENU_DATETIME_SET, &CMTerm2Doc::OnMenuDatetimeSet) + ON_COMMAND(ID_MENU_EVENT_LOG, &CMTerm2Doc::OnMenuEventLog) END_MESSAGE_MAP() @@ -163,9 +169,21 @@ { // TODO: 鍦ㄦ娣诲姞涓�娆℃�ф瀯閫犱唬鐮� - MyKLink1.SetSendCallBackFunc(std::bind(&CMTerm2Doc::SendPacket, this, std::placeholders::_1, std::placeholders::_2)); - MyKLink1.SetRecvCallBackFunc(std::bind(&CMTerm2Doc::RecvPacket, this, std::placeholders::_1, std::placeholders::_2)); - StartTime = myHvSerialPort1.GetTimemS(); + KLink::stCallBackFuncs callbackfuncs; + callbackfuncs.OpenFunc = std::bind(&HvSerialPort::Open, &myHvSerialPort1); + callbackfuncs.CloseFunc = std::bind(&HvSerialPort::Close, &myHvSerialPort1); + callbackfuncs.ClearBufFunc = std::bind(&HvSerialPort::ClearBuf, &myHvSerialPort1); +// callbackfuncs.SendPkgFunc = std::bind(&CMTerm2Doc::SendPacket, this, std::placeholders::_1, std::placeholders::_2); +// callbackfuncs.RecvPkgFunc = std::bind(&CMTerm2Doc::RecvPacket, this, std::placeholders::_1, std::placeholders::_2); + + callbackfuncs.SendPkgFunc = std::bind(&HvSerialPort::Send, &myHvSerialPort1, std::placeholders::_1, std::placeholders::_2); + callbackfuncs.RecvPkgFunc = std::bind(&HvSerialPort::Recv, &myHvSerialPort1, std::placeholders::_1, std::placeholders::_2); + + MyKLink1.SetCallBackFuncs(&callbackfuncs); + +// MyKLink1.SetSendCallBackFunc(std::bind(&CMTerm2Doc::SendPacket, this, std::placeholders::_1, std::placeholders::_2)); +// MyKLink1.SetRecvCallBackFunc(std::bind(&CMTerm2Doc::RecvPacket, this, std::placeholders::_1, std::placeholders::_2)); +// StartTime = myHvSerialPort1.GetTimemS(); } CMTerm2Doc::~CMTerm2Doc() @@ -178,7 +196,8 @@ } int CMTerm2Doc::RecvPacket(void * pBuf, int Len) { - int j = myHvSerialPort1.Recv((char *)pBuf, Len); + int j = 0; + j = myHvSerialPort1.Recv((char *)pBuf, Len); if (j <= 0) { CString s1; @@ -467,10 +486,10 @@ Typetxt.MakeUpper(); for (int i = 0; i < nCoilTypeDefCount; i++) { - if (Typetxt.Find( CoilTypeDef[i].TypeTxt)==0) { - *nCoilType = CoilTypeDef[i].nType; - *nCoilAddr = atoi(Typetxt.Mid(CoilTypeDef[i].TypeTxt.GetLength())); - return CoilTypeDef[i].nType; + if (Typetxt.Find( CoilTypeNameDef[i].TypeTxt)==0) { + *nCoilType = CoilTypeNameDef[i].nType; + *nCoilAddr = atoi(Typetxt.Mid(CoilTypeNameDef[i].TypeTxt.GetLength())); + return CoilTypeNameDef[i].nType; } } return false;; @@ -480,8 +499,8 @@ { for (int i = 0; i < nCoilTypeDefCount; i++) { - if (CoilTypeDef[i].nType == nType){ - typeTxt = CoilTypeDef[i].TypeTxt; + if (CoilTypeNameDef[i].nType == nType){ + typeTxt = CoilTypeNameDef[i].TypeTxt; return true; } } @@ -493,9 +512,9 @@ Typetxt.MakeUpper(); for (int i = 0; i < nDataTypeDefCount; i++) { - if (Typetxt.Find(DataTypeDef[i].TypeTxt) == 0) { - *nDataType = DataTypeDef[i].nType; - *nDataAddr = atoi(Typetxt.Mid(DataTypeDef[i].TypeTxt.GetLength())); + if (Typetxt.Find(DataTypeNameDef[i].TypeTxt) == 0) { + *nDataType = DataTypeNameDef[i].nType; + *nDataAddr = atoi(Typetxt.Mid(DataTypeNameDef[i].TypeTxt.GetLength())); return true; } } @@ -507,8 +526,8 @@ { for (int i = 0; i < nDataTypeDefCount; i++) { - if (DataTypeDef[i].nType == nType) { - typeTxt = DataTypeDef[i].TypeTxt; + if (DataTypeNameDef[i].nType == nType) { + typeTxt = DataTypeNameDef[i].TypeTxt; return true; } } @@ -560,7 +579,7 @@ int CMTerm2Doc::SetAnno(unsigned short nType, unsigned short nAddr, CString sCoilName, CString sAnno) { // TODO: 鍦ㄦ澶勬坊鍔犲疄鐜颁唬鐮�. -// 浜屽垎娉� 鏌ユ壘銆� +// 浜屽垎娉�? 鏌ユ壘銆� // map. for (int i = 0; i < nCoilAnnoCount; i++) { if (mCoilAnnos[i].nType == nType && mCoilAnnos[i].nAddr == nAddr) { @@ -1360,6 +1379,23 @@ void CMTerm2Doc::OnPlcSysregSet() { // TODO: 鍦ㄦ娣诲姞鍛戒护澶勭悊绋嬪簭浠g爜 + CDialogSysRegSet dialog1; + INT_PTR r = dialog1.DoModal(); + if (r == IDOK) + { + + } +} + +void CMTerm2Doc::OnMenuFactCfg() +{ + // TODO: 鍦ㄦ娣诲姞鍛戒护澶勭悊绋嬪簭浠g爜 + CDialogFactCfg dialog1; + INT_PTR r = dialog1.DoModal(); + if (r == IDOK) + { + + } } @@ -1645,7 +1681,7 @@ return nDataAddr; } - MyKLink1.ReadDataWord(1, 2, nDataType, nDataAddr, value);// (unsigned char *)&KMem.DT[nDataAddr]); + MyKLink1.ReadDataWord(1, nDataType, nDataAddr, 2, value);// (unsigned char *)&KMem.DT[nDataAddr]); svalue = value[0]; return svalue; } @@ -1730,7 +1766,7 @@ unsigned short svalue[10]; svalue[0]=nDataValue; int res = 0; - res = MyKLink1.WriteDataWord(1, 2, nDataType, nDataAddr, svalue); + res = MyKLink1.WriteDataWord(1, nDataType, nDataAddr, 2, svalue); return res; } @@ -1826,11 +1862,12 @@ int CMTerm2Doc::DoPLCMonitor() { // TODO: 鍦ㄦ澶勬坊鍔犲疄鐜颁唬鐮�. + CString s1; if (m_bSimulate) { int nDataType = MyKLink1.KLDataTypeWX; int nDataAddr = 0; int nDataCount = 4; - int res; +// int res; for (int i = 0; i < nDataCount; i++) { KMem.WX[i] = myKMachine1.KMem.WX[i]; } @@ -1880,33 +1917,52 @@ int nDataAddr = 0; int nDataCount = 4; int res; - res = MyKLink1.ReadDataWord(1, nDataCount, nDataType, nDataAddr, KMem.WX);// (unsigned char *)&KMem.DT[nDataAddr]); + res = MyKLink1.ReadDataWord(1, nDataType, nDataAddr, nDataCount, KMem.WX);// (unsigned char *)&KMem.DT[nDataAddr]); + if (res != MyKLink1.KL_OK) { + s1.Format(_T("R:= %d %s \r\n"), res, MyKLink1.m_resultStr); + SysLog(s1); + } nDataType = MyKLink1.KLDataTypeWY; nDataAddr = 0; nDataCount = 4; - res = MyKLink1.ReadDataWord(1, nDataCount, nDataType, nDataAddr, KMem.WY);// (unsigned char *)&KMem.DT[nDataAddr]); - + res = MyKLink1.ReadDataWord(1, nDataType, nDataAddr, nDataCount, KMem.WY);// (unsigned char *)&KMem.DT[nDataAddr]); + if (res != MyKLink1.KL_OK) { + s1.Format(_T("R:= %d %s \r\n"), res, MyKLink1.m_resultStr); + SysLog(s1); + } nDataType = MyKLink1.KLDataTypeWR; nDataAddr = 0; nDataCount = 10; - res = MyKLink1.ReadDataWord(1, nDataCount, nDataType, nDataAddr, KMem.WR);// (unsigned char *)&KMem.DT[nDataAddr]); - + res = MyKLink1.ReadDataWord(1, nDataType, nDataAddr, nDataCount, KMem.WR);// (unsigned char *)&KMem.DT[nDataAddr]); + if (res != MyKLink1.KL_OK) { + s1.Format(_T("R:= %d %s \r\n"), res, MyKLink1.m_resultStr); + SysLog(s1); + } nDataType = MyKLink1.KLDataTypeDT; nDataAddr = 0; nDataCount = 80; - res = MyKLink1.ReadDataWord(1, nDataCount, nDataType, nDataAddr, KMem.DT);// (unsigned char *)&KMem.DT[nDataAddr]); - + res = MyKLink1.ReadDataWord(1, nDataType, nDataAddr, nDataCount, KMem.DT);// (unsigned char *)&KMem.DT[nDataAddr]); + if (res != MyKLink1.KL_OK) { + s1.Format(_T("R:= %d %s \r\n"), res, MyKLink1.m_resultStr); + SysLog(s1); + } nDataType = MyKLink1.KLDataTypeSV; nDataAddr = 0; nDataCount = 40; - res = MyKLink1.ReadDataWord(1, nDataCount, nDataType, nDataAddr, KMem.SV);// (unsigned char *)&KMem.DT[nDataAddr]); - + res = MyKLink1.ReadDataWord(1, nDataType, nDataAddr, nDataCount, KMem.SV);// (unsigned char *)&KMem.DT[nDataAddr]); + if (res != MyKLink1.KL_OK) { + s1.Format(_T("R:= %d %s \r\n"), res, MyKLink1.m_resultStr); + SysLog(s1); + } nDataType = MyKLink1.KLDataTypeEV; nDataAddr = 0; nDataCount = 40; - res = MyKLink1.ReadDataWord(1, nDataCount, nDataType, nDataAddr, KMem.EV);// (unsigned char *)&KMem.DT[nDataAddr]); - + res = MyKLink1.ReadDataWord(1, nDataType, nDataAddr, nDataCount, KMem.EV);// (unsigned char *)&KMem.DT[nDataAddr]); + if (res != MyKLink1.KL_OK) { + s1.Format(_T("R:= %d %s \r\n"), res, MyKLink1.m_resultStr); + SysLog(s1); + } } return 0; @@ -1936,3 +1992,25 @@ } } + +void CMTerm2Doc::OnMenuDatetimeSet() +{ + // TODO: 鍦ㄦ娣诲姞鍛戒护澶勭悊绋嬪簭浠g爜 + CDialogDateTime dialog1; + INT_PTR r = dialog1.DoModal(); + if (r == IDOK) + { + + } +} + +void CMTerm2Doc::OnMenuEventLog() +{ + // TODO: 鍦ㄦ娣诲姞鍛戒护澶勭悊绋嬪簭浠g爜 + CDialogEventLog dialog1; + INT_PTR r = dialog1.DoModal(); + if (r == IDOK) + { + + } +} -- Gitblit v1.9.1