Skip to content
2 changes: 1 addition & 1 deletion src/main/modules/compiler/compiler-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1215,7 +1215,7 @@ class CompilerModule {
await writeFile(configFilePath, modbusMasterConfig, 'utf-8')
handleOutputData('Generated conf/modbus_master.json', 'info')
} else {
handleOutputData('No Modbus TCP remote devices configured, skipping modbus_master.json generation', 'info')
handleOutputData('No Modbus remote devices configured, skipping modbus_master.json generation', 'info')
}
}

Expand Down
15 changes: 4 additions & 11 deletions src/utils/modbus/generate-modbus-master-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ interface ModbusMasterIOPoint {

// Base device config with common fields
interface ModbusMasterDeviceConfigBase {
type: 'SLAVE'
type: 'MASTER'
transport: 'tcp' | 'rtu'
timeout_ms: number
slave_id: number
Expand Down Expand Up @@ -100,20 +100,13 @@ const convertRemoteDeviceToModbusMaster = (device: PLCRemoteDevice): ModbusMaste
const transport = modbusTcpConfig.transport || 'tcp'

if (transport === 'rtu') {
// RTU configuration
if (!modbusTcpConfig.serialPort) {
// RTU requires a serial port
console.warn(`Modbus RTU device "${device.name}" is missing a serial port configuration and will be skipped.`)
return null
}

return {
name: device.name,
protocol: 'MODBUS',
config: {
type: 'SLAVE',
type: 'MASTER',
transport: 'rtu',
serial_port: modbusTcpConfig.serialPort,
serial_port: modbusTcpConfig.serialPort ?? '/dev/ttyUSB0',
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
baud_rate: modbusTcpConfig.baudRate ?? 9600,
parity: modbusTcpConfig.parity ?? 'N',
stop_bits: modbusTcpConfig.stopBits ?? 1,
Expand All @@ -129,7 +122,7 @@ const convertRemoteDeviceToModbusMaster = (device: PLCRemoteDevice): ModbusMaste
name: device.name,
protocol: 'MODBUS',
config: {
type: 'SLAVE',
type: 'MASTER',
transport: 'tcp',
host: modbusTcpConfig.host ?? '127.0.0.1',
port: modbusTcpConfig.port ?? 502,
Expand Down