MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / setPort

Method setPort

app/src/API/Handlers/ModbusHandler.cpp:348–370  ·  view source on GitHub ↗

* @brief Set TCP port */

Source from the content-addressed store, hash-verified

346 * @brief Set TCP port
347 */
348API::CommandResponse API::Handlers::ModbusHandler::setPort(const QString& id,
349 const QJsonObject& params)
350{
351 if (!params.contains(QStringLiteral("port"))) {
352 return CommandResponse::makeError(
353 id, ErrorCode::MissingParam, QStringLiteral("Missing required parameter: port"));
354 }
355
356 const int port = params.value(QStringLiteral("port")).toInt();
357
358 if (port < 1 || port > 65535) {
359 return CommandResponse::makeError(
360 id,
361 ErrorCode::InvalidParam,
362 QStringLiteral("Invalid port: %1. Valid range: 1-65535").arg(port));
363 }
364
365 IO::ConnectionManager::instance().modbus()->setPort(static_cast<quint16>(port));
366
367 QJsonObject result;
368 result[QStringLiteral("port")] = port;
369 return CommandResponse::makeSuccess(id, result);
370}
371
372/**
373 * @brief Set RTU serial port by index

Callers 2

applyPublisherEndpointFunction · 0.45
applySubscriberEndpointFunction · 0.45

Calls 3

modbusMethod · 0.80
containsMethod · 0.45
valueMethod · 0.45

Tested by

no test coverage detected