I'm using Modbus TCP to communicate with an IO board.
I have to create a channel order to read a holding register and then I need to create a second channel in order to write the same holding register.
So I need to map a variable for each channel in my application, one for reading the register and one to write the register something that is really inconvenient.
The same problem is there for coils as well.
Is there any other way to have one variable for both reading and writing the register?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
it is possible to declare a globale variable in a GVL and insert this in the I/O Mapping of the Modbus Slave to one! input and as much outputs as you want (take care of the qualified access and add the hole namespace: Appl...GVL...). I use this methode to write and test programs, without having configured the bus system. If everything is fine, i add the specified bus, like Modbus, CanOpen, EtherCat, etc. and do then the mapping to the earlier declared global variables:
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm understanding you right, you have mapped the same variable to a input and write to it in the ST-code? That makes no sense for me and will produce flickering bits! So it's correct to get the warning!
I suggest you, to read the inputs, process the variables and write it to the outputs mapped to different variables. Everything else looks for me like terrible code..
BR David
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Maybe I didn't understand properly what you did the in screenshot you have attached.
I thought that you mapped the CoilInOut0 variable to both read and write Modbus coil channels which is exactly what I did and then used this global variable in ST code.
How do you use CoilInOut0 in your code?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I was thinking, you have a input variable (f.eg. a switch) which you read in ST and an output that should show the same state as the input variable (f.eg. a lamp etc.). Then you can use this methode from me.
I will never write in ST to a variable, which is mapped to an input at the same time. Because, which state shell the variable take, state of the input or state what you are write in ST to it?
Reading the input in ST and mapping it at the same time to an output is no problem.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm talking about a relay output (Modbus coil read/write) which status I need to read but also to write.
The same thing applies to holding registers that can be both read or written.
They have different read/write Modbus commands.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Ok, that was my fault in the sample. What I was thinking about was, as shown below, to read a discrete and write to a coil. That produces no warning and will be functioning, but I don't like it. If I would have to read the state of a coil or a discrete, I won't map the same variable to the write coil, because for me, the read state an input (see %IX0.0) and the state to be written is an output (%QX0.0). That's my opinion.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm using Modbus TCP to communicate with an IO board.
I have to create a channel order to read a holding register and then I need to create a second channel in order to write the same holding register.
So I need to map a variable for each channel in my application, one for reading the register and one to write the register something that is really inconvenient.
The same problem is there for coils as well.
Is there any other way to have one variable for both reading and writing the register?
Originally created by: D. Kugler
it is possible to declare a globale variable in a GVL and insert this in the I/O Mapping of the Modbus Slave to one! input and as much outputs as you want (take care of the qualified access and add the hole namespace: Appl...GVL...). I use this methode to write and test programs, without having configured the bus system. If everything is fine, i add the specified bus, like Modbus, CanOpen, EtherCat, etc. and do then the mapping to the earlier declared global variables:
I had already tried to map the variables as you suggest and wrote the following test code:
IF Start THEN
GVL.CoilInOut := TRUE;
ELSE
GVL.CoilInOut := FALSE;
END_IF
It's working but I get a warning saying:
Application.GVL.CoilInOut is not a valid assignment.
I get this warning because I'm trying to write on read only variable in my application.
Of course it's just a warning and the program runs properly.
Do you use Cyclic or Rising Edge Trigger?
Originally created by: D. Kugler
I'm understanding you right, you have mapped the same variable to a input and write to it in the ST-code? That makes no sense for me and will produce flickering bits! So it's correct to get the warning!
I suggest you, to read the inputs, process the variables and write it to the outputs mapped to different variables. Everything else looks for me like terrible code..
BR David
Maybe I didn't understand properly what you did the in screenshot you have attached.
I thought that you mapped the CoilInOut0 variable to both read and write Modbus coil channels which is exactly what I did and then used this global variable in ST code.
How do you use CoilInOut0 in your code?
Originally created by: D. Kugler
I was thinking, you have a input variable (f.eg. a switch) which you read in ST and an output that should show the same state as the input variable (f.eg. a lamp etc.). Then you can use this methode from me.
I will never write in ST to a variable, which is mapped to an input at the same time. Because, which state shell the variable take, state of the input or state what you are write in ST to it?
Reading the input in ST and mapping it at the same time to an output is no problem.
I'm talking about a relay output (Modbus coil read/write) which status I need to read but also to write.
The same thing applies to holding registers that can be both read or written.
They have different read/write Modbus commands.
Originally created by: D. Kugler
Ok, that was my fault in the sample. What I was thinking about was, as shown below, to read a discrete and write to a coil. That produces no warning and will be functioning, but I don't like it. If I would have to read the state of a coil or a discrete, I won't map the same variable to the write coil, because for me, the read state an input (see %IX0.0) and the state to be written is an output (%QX0.0). That's my opinion.