| | |
| | | #include "MTerm2CommDevView.h"
|
| | | #include <propkey.h>
|
| | |
|
| | | #include "CDialogCommSet1.h"
|
| | | #include "DialogCommSet1.h"
|
| | | #include "DialogStatusShow.h"
|
| | | #include "DialogSysRegSet.h"
|
| | | #include "DialogFactCfg.h"
|
| | |
|
| | | #include "HvSerialPort.h"
|
| | | #include <functional>
|
| | |
|
| | |
| | | #endif
|
| | |
|
| | | // CMTerm2Doc
|
| | | CMTerm2Doc::stTypeDef CMTerm2Doc::CoilTypeDef[] =
|
| | | CMTerm2Doc::stTypeNameDef CMTerm2Doc::CoilTypeNameDef[] =
|
| | | {
|
| | | {KLCoilTypeX,"X"},
|
| | | {KLCoilTypeY,"Y"},
|
| | |
| | | {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"},
|
| | |
| | | {KLDataTypeSV,"SV"},
|
| | | {KLDataTypeLD,"LD"},
|
| | | };
|
| | | int CMTerm2Doc::nDataTypeDefCount = sizeof(CMTerm2Doc::DataTypeDef) / sizeof(stTypeDef);
|
| | | int CMTerm2Doc::nDataTypeDefCount = sizeof(CMTerm2Doc::DataTypeNameDef) / sizeof(stTypeNameDef);
|
| | |
|
| | | CMTerm2Doc::stOpDef CMTerm2Doc::OpDef[] =
|
| | | {
|
| | |
| | | {OP_MUL,"MUL",3,KLParamWord,"X"},
|
| | | {OP_DIV,"DIV",3,KLParamWord,"/"},
|
| | |
|
| | |
|
| | |
|
| | |
|
| | | };
|
| | | int CMTerm2Doc::nOpDefCount = sizeof(CMTerm2Doc::OpDef) / sizeof(stOpDef);
|
| | |
|
| | |
| | | ON_COMMAND(ID_MENU_SHOW_CONSOLE, &CMTerm2Doc::OnMenuShowConsole)
|
| | |
|
| | | ON_COMMAND(ID_MENU_COMM_TEST, &CMTerm2Doc::OnMenuCommTest)
|
| | | |
| | | |
| | | 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)
|
| | | END_MESSAGE_MAP()
|
| | |
|
| | |
|
| | |
| | |
|
| | | 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();
|
| | | StartTime = myHvSerialPort1.GetTimemS();
|
| | | }
|
| | |
|
| | | CMTerm2Doc::~CMTerm2Doc()
|
| | |
| | | }
|
| | | 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;
|
| | |
| | | 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;;
|
| | |
| | | {
|
| | | 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;
|
| | | }
|
| | | }
|
| | |
| | | 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;
|
| | | }
|
| | | }
|
| | |
| | | {
|
| | | 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;
|
| | | }
|
| | | }
|
| | |
| | | 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) {
|
| | |
| | | void CMTerm2Doc::OnPlcSysregSet()
|
| | | {
|
| | | // TODO: 在此添加命令处理程序代码
|
| | | CDialogSysRegSet dialog1;
|
| | | INT_PTR r = dialog1.DoModal();
|
| | | if (r == IDOK)
|
| | | {
|
| | |
|
| | | }
|
| | | }
|
| | |
|
| | | void CMTerm2Doc::OnMenuFactCfg()
|
| | | {
|
| | | // TODO: 在此添加命令处理程序代码
|
| | | CDialogFactCfg dialog1;
|
| | | INT_PTR r = dialog1.DoModal();
|
| | | if (r == IDOK)
|
| | | {
|
| | |
|
| | | }
|
| | | }
|
| | |
|
| | |
|
| | |
| | | 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;
|
| | | }
|
| | |
| | | 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;
|
| | | }
|
| | |
|
| | |
| | | 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];
|
| | | }
|
| | |
| | | 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]);
|
| | |
|
| | | 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]);
|
| | |
|
| | | 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]);
|
| | |
|
| | | 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]);
|
| | |
|
| | | 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]);
|
| | |
|
| | | 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]);
|
| | |
|
| | | }
|
| | |
|
| | |
| | |
|
| | | void CMTerm2Doc::OnTimer(UINT_PTR nIDEvent)
|
| | | {
|
| | | CString s1;
|
| | | // s1.Format(_T("Doc::OntTimer"));
|
| | | // SysLog(s1);
|
| | | if (m_bSimulate && m_bPlcRunning)
|
| | | {
|
| | | //ProcessPLCProg(Progs, m_nProgSteps);
|
| | | myKMachine1.ProcPLC();
|
| | |
|
| | | // update PLC Stat
|
| | | }
|
| | | }
|
| | |
|
| | | void CMTerm2Doc::OnMenuStatusShow()
|
| | | {
|
| | | // TODO: 在此添加命令处理程序代码
|
| | | CDialogStatusShow dialog1;
|
| | | INT_PTR r = dialog1.DoModal();
|
| | | if (r == IDOK)
|
| | | {
|
| | |
|
| | | }
|
| | | }
|
| | |
|
| | |
|