Serial Modbus server using Node-Red Modbus Flex Server (User MMI)

Im trying to intergrate a Coolmay TK6070FH HMI Touch Screen via RS485 into Node red to display system status

I have not been able to find much info and the stuff i found had no resolutions.

This is my Flow todate

I have connected a serial port into the Modbus Flex Server and for the reply the same port on the output side

my first issues looks to be the serial port is not getting the data via the USB serial port.
Note I have checked the port USB_P5 works by using it to read a Modbus relay module, This works with out issue.

I have included my Flow below for reference.

The Modbus Flex write is used to write data into the Flex server, (this Node is work in progress)

[{"id":"e6b3a6c0.6ec858","type":"tab","label":"ModBusServer","disabled":false,"info":""},{"id":"766a48eb.713ac8","type":"function","z":"e6b3a6c0.6ec858","name":"","func":"//var fc=16;\nvar sa;\nvar buf;\n//var addresses=2;\nvar value=msg.payload;\n//var value=1234.5;\nbuf=Buffer.alloc(4);\nbuf.writeFloatBE(value);\nsa=100;\n\n\nvar values=[(buf[0]*256+buf[1]),(buf[2]*256)+buf[3]]\nmsg.slave_ip=\"127.0.0.1\";\nmsg.payload={value:values, 'fc':16, 'unitid':1, 'address':sa, 'quantity':2};\nreturn msg;","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":520,"y":400,"wires":[["a2e07899.bc8c28"]]},{"id":"a2e07899.bc8c28","type":"modbus-flex-write","z":"e6b3a6c0.6ec858","name":"","showStatusActivities":true,"showErrors":true,"showWarnings":true,"server":"4aa7c6e1.e939b8","emptyMsgOnFail":false,"keepMsgProperties":false,"delayOnStart":false,"startDelayTime":"","x":760,"y":380,"wires":[["1e06e24d.26f85e"],["3b1941e5.89c3be"]]},{"id":"1e06e24d.26f85e","type":"debug","z":"e6b3a6c0.6ec858","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":990,"y":340,"wires":[]},{"id":"65118185.540b5","type":"modbus-flex-server","z":"e6b3a6c0.6ec858","name":"","logEnabled":true,"serverAddress":"0.0.0.0","serverPort":"11502","responseDelay":100,"unitId":1,"delayUnit":"ms","coilsBufferSize":20000,"registersBufferSize":20000,"minAddress":0,"splitAddress":10000,"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":true,"x":780,"y":120,"wires":[["4d13b7e3.ba72f8","1e9d6102fd1beceb"],["4d13b7e3.ba72f8"],["4d13b7e3.ba72f8"],["4d13b7e3.ba72f8"],["4d13b7e3.ba72f8"]]},{"id":"3b1941e5.89c3be","type":"modbus-response","z":"e6b3a6c0.6ec858","name":"Modbus ","registerShowMax":"4","x":1010,"y":420,"wires":[]},{"id":"4d13b7e3.ba72f8","type":"debug","z":"e6b3a6c0.6ec858","name":"Modbus Server Output","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1150,"y":100,"wires":[]},{"id":"5e68cd64.9b62c4","type":"inject","z":"e6b3a6c0.6ec858","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"num","x":110,"y":320,"wires":[["65118185.540b5","7442be40.16fa7"]]},{"id":"7442be40.16fa7","type":"function","z":"e6b3a6c0.6ec858","name":"","func":"\nmsg.payload={value:[27.1 , 23] , 'fc':6, 'unitid':1, 'address':2, 'quantity':8};\nreturn msg;","outputs":1,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":520,"y":320,"wires":[["a2e07899.bc8c28"]]},{"id":"5f57feeddc5b4380","type":"inject","z":"e6b3a6c0.6ec858","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":120,"y":400,"wires":[["766a48eb.713ac8"]]},{"id":"8b0e90a8c673e5ec","type":"serial request","z":"e6b3a6c0.6ec858","d":true,"name":"","serial":"96ff0162771d8f80","x":420,"y":100,"wires":[["65118185.540b5","e410d0a7fd8a541f","a5a4e68720a7f323"]]},{"id":"e410d0a7fd8a541f","type":"debug","z":"e6b3a6c0.6ec858","name":"USB_P5Data","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":750,"y":40,"wires":[]},{"id":"5970b2a64b6c6148","type":"serial in","z":"e6b3a6c0.6ec858","d":true,"name":"","serial":"96ff0162771d8f80","x":460,"y":40,"wires":[["e410d0a7fd8a541f"]]},{"id":"a5a4e68720a7f323","type":"modbus-server","z":"e6b3a6c0.6ec858","name":"","logEnabled":false,"hostname":"0.0.0.0","serverPort":10502,"responseDelay":100,"delayUnit":"ms","coilsBufferSize":10000,"holdingBufferSize":10000,"inputBufferSize":10000,"discreteBufferSize":10000,"showErrors":false,"x":780,"y":220,"wires":[["4d13b7e3.ba72f8"],["4d13b7e3.ba72f8"],["4d13b7e3.ba72f8"],["4d13b7e3.ba72f8"],["4d13b7e3.ba72f8"]]},{"id":"2854956b554dbca8","type":"serial in","z":"e6b3a6c0.6ec858","name":"","serial":"96ff0162771d8f80","x":380,"y":160,"wires":[["e410d0a7fd8a541f","65118185.540b5"]]},{"id":"1e9d6102fd1beceb","type":"serial out","z":"e6b3a6c0.6ec858","name":"","serial":"96ff0162771d8f80","x":1220,"y":180,"wires":[]},{"id":"4aa7c6e1.e939b8","type":"modbus-client","name":"","clienttype":"tcp","bufferCommands":true,"stateLogEnabled":false,"queueLogEnabled":false,"failureLogEnabled":false,"tcpHost":"192.168.1.7","tcpPort":"11502","tcpType":"DEFAULT","serialPort":"/dev/ttyUSB","serialType":"RTU-BUFFERD","serialBaudrate":"9600","serialDatabits":"8","serialStopbits":"1","serialParity":"none","serialConnectionDelay":"100","serialAsciiResponseStartDelimiter":"","unit_id":"7","commandDelay":"1","clientTimeout":"1000","reconnectOnTimeout":true,"reconnectTimeout":"2000","parallelUnitIdsAllowed":true},{"id":"96ff0162771d8f80","type":"serial-port","name":"","serialport":"/dev/ttyUSB_P5","serialbaud":"9600","databits":"8","parity":"none","stopbits":"1","waitfor":"","dtr":"none","rts":"none","cts":"none","dsr":"none","newline":"\\n","bin":"bin","out":"char","addchar":"","responsetimeout":"2000"}]

OK Solution Found

Used "@krakul/node-red-modbus-rtu-slave" its for USB Connections , found this out by going to the github link, the Info doesnt mention USB serial Comms.

Also discovered Modbus RTU implies serial communication

Worked without issues, will provide Flow once completed

1 Like

Hi so having some issues with this Node.
looks like each time i switch OFF/ON the MMI the Mode stops responding.
When the MMI turns back on it drive the Transmit on for about 3 seconds and after this no more comms,
I think its my USB serial port which is locking up as it has just received a break, has anyone encountered this issue and what was the fix ?

Today 24th June 2024 i tryed a different USB to 485 converter with the same fault.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.