From 89cd7441c184d37f90d4d5311b348e938119765f Mon Sep 17 00:00:00 2001 From: zxd <zxdvslxy@gmail.com> Date: 星期六, 21 十月 2023 12:28:04 +0800 Subject: [PATCH] 修改最后一个单元格不会被读取的问题 --- MTerm2/MTerm2Doc.cpp | 48 ++++++++++++++++++++++++++++++++++++++++-------- 1 files changed, 40 insertions(+), 8 deletions(-) diff --git a/MTerm2/MTerm2Doc.cpp b/MTerm2/MTerm2Doc.cpp index 95a36ee..2622a2a 100644 --- a/MTerm2/MTerm2Doc.cpp +++ b/MTerm2/MTerm2Doc.cpp @@ -169,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() @@ -1850,6 +1862,7 @@ int CMTerm2Doc::DoPLCMonitor() { // TODO: 鍦ㄦ澶勬坊鍔犲疄鐜颁唬鐮�. + CString s1; if (m_bSimulate) { int nDataType = MyKLink1.KLDataTypeWX; int nDataAddr = 0; @@ -1905,32 +1918,51 @@ int nDataCount = 4; int res; 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, 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, 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, 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, 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, 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; -- Gitblit v1.9.1