| | |
| | | std::string strProductID; |
| | | if (ReadProductID(strProductID)) { |
| | | CString msg; |
| | | msg.Format(_T("读取到产品ID:%s"), strProductID.c_str()); |
| | | msg.Format(_T("读取到产品ID:%s"), strProductID); |
| | | LOG_MSG(msg, LOG_TYPE_SUCCESS); |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | for (int i = 0; i < PLC_RESULT_ADDR_COUNT; ++i) { |
| | | // 放大100倍并四舍五入,转为PLC整数 |
| | | uint16_t nScaled = static_cast<uint16_t>(std::round(values[i] * 100.0)); |
| | | WordContainer vec = { nScaled }; |
| | | // 放大1000倍并四舍五入,转为PLC整数 |
| | | int32_t nScaled = static_cast<int32_t>(std::round(values[i] * 1000.0)); |
| | | DWordContainer vec = { static_cast<uint32_t>(nScaled) }; |
| | | |
| | | short nTargetAddr = PLC_RESULT_ADDR_START + i * 2; |
| | | int ret = m_pPlc->WriteWordDataEx(m_station, PLC_WORD_DEVICE_TYPE, nTargetAddr, vec); |
| | | int ret = m_pPlc->WriteDWordDataEx(m_station, PLC_WORD_DEVICE_TYPE, nTargetAddr, vec); |
| | | if (ret != 0) { |
| | | CString msg; |
| | | msg.Format(_T("写入OUT%d到地址%d失败,值=%.2f"), i + 1, nTargetAddr, values[i]); |
| | |
| | | } |
| | | |
| | | strProductID.clear(); |
| | | strProductID.reserve(PLC_PRODUCT_ID_WORDS * 2); |
| | | for (auto w : vec) { |
| | | char c1 = static_cast<char>(w & 0xFF); // 低字节 |
| | | char c2 = static_cast<char>((w >> 8) & 0xFF); // 高字节 |