Sending Command in ModBus C example

Hi,

getting status 20245 means, that a process variable, that is used inside the data module, does not exist in the PLC.

You have to mention, that if you declare a process variable (by _LOCAL or _GLOBAL or inside *.var file), but don’t use it anywhere in the code, then for performance reasons this variable is not installed into the PLC (because it’s nowhere referenced).

So you have to:

  • declare the variable
  • call it somewhere in the code (normally in the _INIT) - this call is really only to convince the compiler that he has to “build and install a process variable object into the PLC”
  • depending on if it’s a local or a global variable, address it in the right naming way inside the data module.

For example let’s assume, your task where MBMopen() is called has the name “MBOpenTest”. Inside “MBOpenTest”, there’s a _LOCAL process variable called “myMbDummyVar” declared.
To use this variable for the data module, you have to

  • add a “dummy call” somewhere in the code
  • in case of a _LOCAL declaration, use the right syntax “Taskname:Variablename” inside the data object.

I don’t have suitable hardware to really run some code, but it should look somehow like this:

Best regards!

1 Like