Modbus Server not working

Steve's method works :+1:

Updated the Test Flow to include a Modbus Write node instead

[{"id":"a58ce8e2.9210d8","type":"debug","z":"937cb040.d8e16","name":"coils Buffer","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":900,"y":100,"wires":[]},{"id":"c45f9a38fafeea33","type":"debug","z":"937cb040.d8e16","name":"holding Buffer","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":910,"y":60,"wires":[]},{"id":"3ebf4334ff738f57","type":"debug","z":"937cb040.d8e16","name":"discrete inputs Buffer","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":930,"y":180,"wires":[]},{"id":"c85cf54d3f04b905","type":"debug","z":"937cb040.d8e16","name":"input Buffer","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":900,"y":140,"wires":[]},{"id":"67da3b9c4e798a0b","type":"debug","z":"937cb040.d8e16","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":845,"y":240,"wires":[],"l":false},{"id":"2027c3dacc40fb15","type":"inject","z":"937cb040.d8e16","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"-123","payloadType":"num","x":130,"y":240,"wires":[["9cecfc46858d01f2"]]},{"id":"6ef8309b782c54cb","type":"debug","z":"937cb040.d8e16","name":"debug 35","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":285,"y":220,"wires":[],"l":false},{"id":"f594dc8cbd89b61e","type":"modbus-read","z":"937cb040.d8e16","name":"","topic":"","showStatusActivities":true,"logIOActivities":false,"showErrors":true,"showWarnings":true,"unitid":"1","dataType":"HoldingRegister","adr":"4","quantity":"2","rate":"3","rateUnit":"s","delayOnStart":false,"startDelayTime":"","server":"644cb5f29bb9a4f8","useIOFile":false,"ioFile":"","useIOForPayload":false,"emptyMsgOnFail":false,"x":210,"y":440,"wires":[["6f86aebe1f9f82e9"],[]]},{"id":"4295ae7bfd9a13a8","type":"debug","z":"937cb040.d8e16","name":"debug 63","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":600,"y":460,"wires":[]},{"id":"6f86aebe1f9f82e9","type":"buffer-parser","z":"937cb040.d8e16","name":"","data":"responseBuffer.buffer","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"int16be","name":"item1","offset":0,"length":1,"offsetbit":0,"scale":"1","mask":""}],"swap1":"","swap2":"","swap3":"","swap1Type":"swap","swap2Type":"swap","swap3Type":"swap","msgProperty":"payload","msgPropertyType":"str","resultType":"keyvalue","resultTypeType":"return","multipleResult":false,"fanOutMultipleResult":false,"setTopic":true,"outputs":1,"x":410,"y":460,"wires":[["4295ae7bfd9a13a8"]]},{"id":"9cecfc46858d01f2","type":"link call","z":"937cb040.d8e16","name":"","links":["06e8463bb48c80ad"],"linkType":"static","timeout":"30","x":255,"y":280,"wires":[["6ef8309b782c54cb","ed4b47b45d78c3cc"]],"l":false},{"id":"ed4b47b45d78c3cc","type":"function","z":"937cb040.d8e16","name":"","func":"\nmsg.payload = {\n    value: msg.payload,\n    'fc': 6,\n    'unitid': 1,\n    'address': 4,\n    'quantity': 1\n}\n\nreturn msg","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":355,"y":280,"wires":[["6985a227346dfea0"]],"l":false},{"id":"b83ead4a63c6fe76","type":"inject","z":"937cb040.d8e16","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"252","payloadType":"num","x":130,"y":320,"wires":[["9cecfc46858d01f2"]]},{"id":"6985a227346dfea0","type":"modbus-flex-write","z":"937cb040.d8e16","name":"","showStatusActivities":true,"showErrors":true,"showWarnings":true,"server":"644cb5f29bb9a4f8","emptyMsgOnFail":false,"keepMsgProperties":false,"delayOnStart":false,"startDelayTime":"","x":510,"y":280,"wires":[[],[]]},{"id":"f498667f45ddcea6","type":"modbus-flex-server","z":"937cb040.d8e16","name":"","logEnabled":false,"serverAddress":"0.0.0.0","serverPort":"10502","responseDelay":100,"unitId":1,"delayUnit":"ms","coilsBufferSize":"200","registersBufferSize":"200","minAddress":0,"splitAddress":"100","funcGetCoil":"function getFlexCoil(addr, unitID) {\n\tif (unitID === node.unitId && \n\t\taddr >= node.minAddress && \n\t\taddr <= node.splitAddress) { \n\n\t\treturn node.coils.readUInt8(addr * node.bufferFactor) \n\t}  \n}","funcGetDiscreteInput":"function getFlexDiscreteInput(addr, unitID) {\n\taddr += node.splitAddress\n\tif (unitID === node.unitId && \n\t\taddr >= node.splitAddress && \n\t\taddr <= node.splitAddress * 2) { \n\n\t\treturn node.coils.readUInt8(addr * node.bufferFactor) \n\t}  \n}","funcGetInputRegister":"function getFlexInputRegister(addr, unitID) { \n\tif (unitID === node.unitId && \n\t\taddr >= node.minAddress && \n\t\taddr <= node.splitAddress) { \n\n\t\treturn node.registers.readUInt16BE(addr * node.bufferFactor)  \n\t} \n}","funcGetHoldingRegister":"function getFlexHoldingRegsiter(addr, unitID) { \n\taddr += node.splitAddress\n\tif (unitID === node.unitId && \n\t\taddr >= node.splitAddress && \n\t\taddr <= node.splitAddress * 2) { \n\n\t\treturn node.registers.readUInt16BE(addr * node.bufferFactor)  \n\t} \n}","funcSetCoil":"function setFlexCoil(addr, value, unitID) { \n\tif (unitID === node.unitId && \n\t\taddr >= node.minAddress && \n\t\taddr <= node.splitAddress) { \n\n\t\tnode.coils.writeUInt8(value, addr * node.bufferFactor)  \n\t} \n}","funcSetRegister":"function setFlexRegister(addr, value, unitID) { \n\taddr += node.splitAddress\n\tif (unitID === node.unitId && \n\t\taddr >= node.splitAddress && \n\t\taddr <= node.splitAddress * 2) { \n\n\t\tnode.registers.writeUInt16BE(value, addr * node.bufferFactor)  \n\t} \n}","showErrors":false,"x":640,"y":120,"wires":[["c45f9a38fafeea33"],["a58ce8e2.9210d8"],["c85cf54d3f04b905"],["3ebf4334ff738f57"],["67da3b9c4e798a0b"]]},{"id":"2e869ad80ee4016b","type":"group","z":"937cb040.d8e16","name":"SUBROUTINE: Convert to a UINT value for ModBus","style":{"stroke":"#0070c0","fill":"#bfdbef","label":true,"color":"#000000"},"nodes":["06e8463bb48c80ad","ba82d013eccbe4fc","651d03f969ae5789","ac4640d4f6ddc59c"],"x":44,"y":619,"w":782,"h":82},{"id":"06e8463bb48c80ad","type":"link in","z":"937cb040.d8e16","g":"2e869ad80ee4016b","name":"Float to UINT","links":[],"x":85,"y":660,"wires":[["651d03f969ae5789"]]},{"id":"ba82d013eccbe4fc","type":"link out","z":"937cb040.d8e16","g":"2e869ad80ee4016b","name":"link out 41","mode":"return","links":[],"x":785,"y":660,"wires":[]},{"id":"651d03f969ae5789","type":"buffer-maker","z":"937cb040.d8e16","g":"2e869ad80ee4016b","name":"Convert 1 int to a buffer","specification":"spec","specificationType":"ui","items":[{"name":"item1","type":"int16be","length":1,"dataType":"msg","data":"payload"}],"swap1":"","swap2":"","swap3":"","swap1Type":"swap","swap2Type":"swap","swap3Type":"swap","msgProperty":"payload","msgPropertyType":"str","x":260,"y":660,"wires":[["ac4640d4f6ddc59c"]]},{"id":"ac4640d4f6ddc59c","type":"buffer-parser","z":"937cb040.d8e16","g":"2e869ad80ee4016b","name":"Buffer to UINT","data":"payload","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"uint16be","name":"item1","offset":0,"length":1,"offsetbit":0,"scale":"1","mask":""}],"swap1":"","swap2":"","swap3":"","swap1Type":"swap","swap2Type":"swap","swap3Type":"swap","msgProperty":"payload","msgPropertyType":"str","resultType":"value","resultTypeType":"return","multipleResult":false,"fanOutMultipleResult":true,"setTopic":false,"outputs":1,"x":570,"y":660,"wires":[["ba82d013eccbe4fc"]]},{"id":"644cb5f29bb9a4f8","type":"modbus-client","name":"","clienttype":"tcp","bufferCommands":true,"stateLogEnabled":false,"queueLogEnabled":false,"failureLogEnabled":true,"tcpHost":"127.0.0.1","tcpPort":"10502","tcpType":"DEFAULT","serialPort":"/dev/ttyUSB","serialType":"RTU-BUFFERD","serialBaudrate":"9600","serialDatabits":"8","serialStopbits":"1","serialParity":"none","serialConnectionDelay":"100","serialAsciiResponseStartDelimiter":"0x3A","unit_id":"1","commandDelay":"1","clientTimeout":"1000","reconnectOnTimeout":false,"reconnectTimeout":"2000","parallelUnitIdsAllowed":true,"showErrors":false,"showWarnings":true,"showLogs":true}]

The Subroutine part may not be needed if you are not planning to send negative values

1 Like