* @brief Configures and connects a Modbus RTU bus from CLI options. */
| 1001 | * @brief Configures and connects a Modbus RTU bus from CLI options. |
| 1002 | */ |
| 1003 | void CLI::setupModbusRtuConnection() |
| 1004 | { |
| 1005 | const QString portPath = m_parser.value(m_opts.modbusRtuOpt); |
| 1006 | IO::ConnectionManager::instance().setBusType(SerialStudio::BusType::ModBus); |
| 1007 | IO::ConnectionManager::instance().modbus()->setProtocolIndex(0); |
| 1008 | |
| 1009 | const QStringList ports = IO::ConnectionManager::instance().modbus()->serialPortList(); |
| 1010 | const int portIndex = ports.indexOf(portPath); |
| 1011 | if (portIndex < 0) { |
| 1012 | qWarning() << "ModBus serial port not found:" << portPath; |
| 1013 | qWarning() << "Available ports:" << ports.join(", "); |
| 1014 | return; |
| 1015 | } |
| 1016 | |
| 1017 | IO::ConnectionManager::instance().modbus()->setSerialPortIndex(portIndex); |
| 1018 | applyModbusSlave(m_parser, m_opts.modbusSlaveOpt); |
| 1019 | applyModbusPoll(m_parser, m_opts.modbusPollOpt); |
| 1020 | applyModbusBaud(m_parser, m_opts.modbusBaudOpt); |
| 1021 | |
| 1022 | if (m_parser.isSet(m_opts.modbusParityOpt)) |
| 1023 | applyModbusParity(m_parser.value(m_opts.modbusParityOpt).toLower()); |
| 1024 | |
| 1025 | if (m_parser.isSet(m_opts.modbusDataBitsOpt)) |
| 1026 | applyModbusDataBits(m_parser.value(m_opts.modbusDataBitsOpt)); |
| 1027 | |
| 1028 | if (m_parser.isSet(m_opts.modbusStopBitsOpt)) |
| 1029 | applyModbusStopBits(m_parser.value(m_opts.modbusStopBitsOpt)); |
| 1030 | |
| 1031 | applyModbusRegisters(m_parser, m_opts.modbusRegisterOpt); |
| 1032 | IO::ConnectionManager::instance().connectDevice(); |
| 1033 | } |
| 1034 | |
| 1035 | /** |
| 1036 | * @brief Configures and connects a Modbus TCP bus from CLI options. |
nothing calls this directly
no test coverage detected