Skip to content

Commit

Permalink
Merge pull request #140 from Jalle19/modbus-timeout
Browse files Browse the repository at this point in the history
Make Modbus timeout configurable
  • Loading branch information
Jalle19 authored Feb 20, 2025
2 parents 92bab2a + bebfe63 commit 7cd81db
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions eda-modbus-bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ const argv = yargs(process.argv.slice(2))
default: 1,
alias: 's',
},
'modbusTimeout': {
description: 'The timeout for Modbus operations (in seconds)',
type: 'number',
default: 5,
alias: 't',
},
'http': {
description: 'Whether to enable the HTTP server or not',
type: 'boolean',
Expand Down Expand Up @@ -100,11 +106,13 @@ void (async () => {
logger.error(`Malformed Modbus device ${argv.device} specified, exiting`)
process.exit(1)
}
logger.info(`Opening Modbus connection to ${argv.device}, slave ID ${argv.modbusSlave}`)
logger.info(
`Opening Modbus connection to ${argv.device}, slave ID ${argv.modbusSlave}, ${argv.modbusTimeout} second timeout`
)
const modbusDevice = parseDevice(argv.device)
const modbusClient = new ModbusRTU()
modbusClient.setID(argv.modbusSlave)
modbusClient.setTimeout(5000) // 5 seconds
modbusClient.setTimeout(argv.modbusTimeout * 1000)

// Use buffered RTU or TCP depending on device type
if (modbusDevice.type === ModbusDeviceType.RTU) {
Expand Down

0 comments on commit 7cd81db

Please sign in to comment.