Modbus Write Specific Function Code 42

Does one of you know if there is a node that support specific function code. for example i will use code 42.

Already try to create flow and inject command to convert like below. The result after buffer maker is succesfull to convert in hex command format to write into modbus. but after modbus flex write, I have error messages "FC Not Valid"

Is it something wrong about this flow or node? Is it possible to program this?

Is there a pallete can support specific code?

Hi @Steve-Mcl

Could you help advise about this specific function code can do modbus request ?

Is there something wrong about this flow or node?

Let me know if any how to do will be possible.

Function Code FC42 is not listed in the ModBus Specification
Are you certain it is FC42?
Is this some custom code added by the device manufacturer?

Also, Modbus typically works with 16bit Integers (so sending a Buffer would probably yield wrong result anyhow). That is easily fixed by adding a "Buffer Parser" after "Buffer Maker" to turn the bytes into an array of UInt16 (be)

@Steve-Mcl Yes, FC42 is manufacturer specific function code.

already add buffer parser but have error messages below


Then how to revise the flow ? Let you know my flow below

[{"id":"c45a118bb46dc88a","type":"tab","label":"Flow 1","disabled":false,"info":"","env":[]},{"id":"31bb89b6798f4b3f","type":"buffer-maker","z":"c45a118bb46dc88a","name":"","specification":"spec","specificationType":"ui","items":[{"name":"item2","type":"hex","length":-1,"dataType":"msg","data":"payload"}],"swap1":"","swap2":"","swap3":"","swap1Type":"swap","swap2Type":"swap","swap3Type":"swap","msgProperty":"payload","msgPropertyType":"str","x":450,"y":220,"wires":[["9e6e9e0d9058ea6d","b2240e1878e86494"]]},{"id":"9e6e9e0d9058ea6d","type":"debug","z":"c45a118bb46dc88a","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":590,"y":140,"wires":[]},{"id":"b2223f5ae18472c0","type":"inject","z":"c45a118bb46dc88a","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0142b778","payloadType":"str","x":260,"y":220,"wires":[["31bb89b6798f4b3f"]]},{"id":"9015a7e65baff3da","type":"debug","z":"c45a118bb46dc88a","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":850,"y":140,"wires":[]},{"id":"b2240e1878e86494","type":"buffer-parser","z":"c45a118bb46dc88a","name":"","data":"payload","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"uint16be","name":"id","offset":0,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"uint16be","name":"fc","offset":1,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"uint16be","name":"high","offset":2,"length":1,"offsetbit":0,"scale":"1","mask":""},{"type":"uint16be","name":"low","offset":3,"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":650,"y":220,"wires":[["9015a7e65baff3da"]]}]

The underlying modbus node package does not support custom FCs.

Your choices are...

  • raise a "Feature Request" on the github repo + cross your finger :crossed_fingers:
  • fork, add "custom FC feature", publish a PR (pull request), wait for developer to merge an release.
  • fork, add "custom FC feature", publish an alternative node in NPM.
  • DIY it - here is the basis for a DIY solution

As for your error...

You have asked Buffer Parser to use 6 bytes (but only supply it with 4 bytes)

The proper solution to convert a buffer of bytes into an array of integers is to use the length -1 (it is documented in the built in help)


@Steve-Mcl The choices DIY options is great for me.

After tryin the basis DIY solution, I want to makesure have true response after my write request.

How do parse the correct reply if location value in the buffer is disordered and dynamic changing?

e.g the buffer is below

0: 0x09
1: 0x67
2: 0xD4
3: 0x01
4: 0x05
5: 0x32
6: 0x4A
7: 0x5B
8: 0x55
9: 0x13

the correct respon values is in the bold italic font

It should not be "disordered" - it may be byteswapped (you can swap using the buffer parser options).

However, what you are asking is not exactly clear.

If you provide ...

  • some demo data (use the "COPY VALUE" [button] on the debug output to get actual values)
  • a specification of the data (data type, data size, byte offset/position)
  • the expected value

I will show you how.

@Steve-Mcl e.g I have buffer [40] raw below:

I want to parse only for 4 bytes (hex value) in this position:

2: 0x1
23: 0x34
38: 0xae
39: 0x92

but the position 4 bytes (hex value) is not static. it's dynamic changed every request. how to parse this buffer?

@Steve-Mcl how to parse this buffer if the 4 bytes is not static position.

Could you advise how to config parse node? Is there a way auto scan position in the buffer?

I doubt the data moves. That would be illogical. If it does move it is because the spec if rubbish or dynamic or the request is not returning what you think (e.g. an error code or something).

As I said before...

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