| | |
| | | // mc channel |
| | | McChannelListener m_mcChannellistener; |
| | | m_mcChannellistener.funOnConnected = [&](IMcChannel* pChannel, int nErrorCode) -> void { |
| | | MYTRACE1("<PLC-%s>连接结果<code= %d>", m_strName.c_str(), nErrorCode); |
| | | LOGI("<PLC-%s>连接结果<code= %d>", m_strName.c_str(), nErrorCode); |
| | | if (nErrorCode == 0) { |
| | | setState(PLCSTATE::CONNECTED); |
| | | } |
| | |
| | | CString strText; |
| | | dataToHexString(pData, nDataSize, strText); |
| | | if (nDecodeRet != 0) { |
| | | MYTRACE1("<PLC-%s>funOnRead[%s], nDecodeRet=%d", m_strName.c_str(), (LPTSTR)(LPCTSTR)strText, nDecodeRet); |
| | | LOGE("<PLC-%s>funOnRead[%s], nDecodeRet=%d", m_strName.c_str(), (LPTSTR)(LPCTSTR)strText, nDecodeRet); |
| | | } |
| | | m_nUnHeartBeat = 0; |
| | | }; |
| | |
| | | && m_pChannel != NULL) { |
| | | m_pChannel->setChannelListener(&m_mcChannellistener); |
| | | m_pChannel->setActionInterval(m_nActionInterval); |
| | | MYTRACE1("<PLC-%s>正在连接PLC.", m_strName.c_str()); |
| | | LOGI("<PLC-%s>正在连接PLC.", m_strName.c_str()); |
| | | setState(PLCSTATE::CONNECTING); |
| | | m_pChannel->connect(); |
| | | } |
| | |
| | | s.AppendFormat(" %x", (BYTE)pData[i]); |
| | | } |
| | | s.Append("]"); |
| | | MYTRACE1("<CPLC-%d-%d>Received plc data.%s", m_nIndex, monitor.id, (LPTSTR)(LPCTSTR)s); |
| | | LOGD("<CPLC-%d-%d>Received plc data.%s", m_nIndex, monitor.id, (LPTSTR)(LPCTSTR)s); |
| | | } |
| | | } |
| | | else { |
| | | MYTRACE1("<CPLC-%d-%d>PLC批读取数据位超时.flag=%d", m_nIndex, monitor.id, flag); |
| | | LOGE("<CPLC-%d-%d>PLC批读取数据位超时.flag=%d", m_nIndex, monitor.id, flag); |
| | | } |
| | | |
| | | if (nDataSize == monitor.readLen && flag == 0) { |
| | |
| | | |
| | | bool CPLC::isConnected() |
| | | { |
| | | return m_pChannel->isConnected(); |
| | | return m_pChannel != nullptr && m_pChannel->isConnected(); |
| | | } |
| | | |
| | | int CPLC::readWord(MC::SOFT_COMPONENT softComponent, unsigned int addr, |
| | |
| | | int value, ONWRITE funOnWrite) |
| | | { |
| | | return m_pChannel->writeWord(softComponent, addr, value, funOnWrite); |
| | | } |
| | | |
| | | int CPLC::writeDWord(MC::SOFT_COMPONENT softComponent, unsigned int addr, |
| | | int value, ONWRITE funOnWrite) |
| | | { |
| | | return m_pChannel->writeDWord(softComponent, addr, value, funOnWrite); |
| | | } |
| | | |
| | | int CPLC::writeData(MC::SOFT_COMPONENT softComponent, unsigned int addr, |
| | |
| | | static int iii = 0; |
| | | iii++; |
| | | if (iii % 5 == 3) { |
| | | if (!m_pChannel->isConnected()) |
| | | if (m_pChannel != nullptr && !m_pChannel->isConnected()) |
| | | m_pChannel->connect(); |
| | | } |
| | | } |