I have set in the ModbusTCP mapping IO a variable of struct data type, and when I try to log in I receive "Types of channel and mapped variable Application.MaskCW do not match".
Attached a print screen of the problem.
How can I map a variable of struct data type to the device?
the structure is built like:
TYPEMaskCW:STRUCT
  x1:bit;
  x2:bit;
  x3:bit;END_STRUCTEND_TYPE
The declaration in a GVL list is:
MaskCW:MaskCW;
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I cant help you directly with your problem because to me I would do it like this and I tried it out with DPDP coupler and it worked.
But for you to temporarly be able to continue your work you can do this:
Define a new variable in the configuration where you want to link it.
Then use pointers
VARÂ Â temporaryPointer:POINTERTOMaskCW;Â Â yourNewTempVariableInConfig:DWORD;Thisvariableistheonefromyourconfig,notdefinedlikeinthiscodesnippet!END_VARtemporaryPointer:=ADR(yourNewVariableInConfig);maskCWVariable:=temporaryPointer^;
Maybe you know this way already but I just want to give you a workaround if not.
I assume you don't have a variable Name MaskCW as well as a Type name MaskCW, because this would not work / compile normaly because the compiler would not be able to distinguish between MaskCW variable and the MaskCW Type.
My 2 cents:
Dont name your struct "MaskCW", its not clear what it means. Write what ever CW means, the name will not get "to big", this is an argument back when the displays were very small, nowadays it doesnt count anymore. I know some of this rules are in the PLCOpen guidlines, but even then a lot of stuff in there make absolutely no sense like Hungarian Notation.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
jonathanD hat geschrieben:
Hello,
I have set in the ModbusTCP mapping IO a variable of struct data type, and when I try to log in I receive "Types of channel and mapped variable Application.MaskCW do not match".
Attached a print screen of the problem.
How can I map a variable of struct data type to the device?
the structure is built like:
TYPEMaskCW:STRUCTÂ Â x1:bit;Â Â x2:bit;Â Â x3:bit;END_STRUCTEND_TYPE
The declaration in a GVL list is:
MaskCW:MaskCW;
What do you mean you have mapped a struct type in the Modbus mapping? I would think that whatever you have needs to be broken down into either bits or packed in words, that's how I do it. Like using for example Application.PLC_PRG.MaskCW.x1 as an existing variable in the modbus mapping as bits. I don't believe you can simply map a struct because how is that going to be handled over multiple words?
And I guess you mean bool not bit?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Zitat:
What do you mean you have mapped a struct type in the Modbus mapping? I would think that whatever you have needs to be broken down into either bits or packed in words, that's how I do it. Like using for example Application.PLC_PRG.MaskCW.x1 as an existing variable in the modbus mapping as bits. I don't believe you can simply map a struct because how is that going to be handled over multiple words?
And I guess you mean bool not bit?
Maybe I haven't explained myself correctly. I want to map a variable where I could refer to each of the bits separately, so I could name the bits in the code to something more readable.
For example:
Let's assume MaskCW is a WORD variable, and I want to control bit number 5 to operate a motor. I want to name this bit 'startMotor' without declaring each variable like 'Application.PLC_PRG.MaskCW.startMotor' in the mapping of the device.
I want to refer it in the code like a structure, or any other way that will be easy to read like: MaskCW.startMotor := true;
How can I do it?
Thank you for your time and effort!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I created a Union with two vars, one of the struct type and the other with word type.
In the GVL I declared a var of the Union type.
In the mapping of the Modbus device I mapped the var from the GVL list and the var of WORD data type from the Union.
Example:
myUnion:
x1 : myStructure;
x2 : WORD;
GVL:
myVar : myUnion;
Mapping:
Application.myVar.x2
Then in the code i can refer to what is listed in myStructure.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello,
I have set in the ModbusTCP mapping IO a variable of struct data type, and when I try to log in I receive "Types of channel and mapped variable Application.MaskCW do not match".
Attached a print screen of the problem.
How can I map a variable of struct data type to the device?
the structure is built like:
The declaration in a GVL list is:
I cant help you directly with your problem because to me I would do it like this and I tried it out with DPDP coupler and it worked.
But for you to temporarly be able to continue your work you can do this:
Define a new variable in the configuration where you want to link it.
Then use pointers
Maybe you know this way already but I just want to give you a workaround if not.
I assume you don't have a variable Name MaskCW as well as a Type name MaskCW, because this would not work / compile normaly because the compiler would not be able to distinguish between MaskCW variable and the MaskCW Type.
My 2 cents:
Dont name your struct "MaskCW", its not clear what it means. Write what ever CW means, the name will not get "to big", this is an argument back when the displays were very small, nowadays it doesnt count anymore. I know some of this rules are in the PLCOpen guidlines, but even then a lot of stuff in there make absolutely no sense like Hungarian Notation.
The declaration in a GVL list is:
What do you mean you have mapped a struct type in the Modbus mapping? I would think that whatever you have needs to be broken down into either bits or packed in words, that's how I do it. Like using for example Application.PLC_PRG.MaskCW.x1 as an existing variable in the modbus mapping as bits. I don't believe you can simply map a struct because how is that going to be handled over multiple words?
And I guess you mean bool not bit?
Maybe I haven't explained myself correctly. I want to map a variable where I could refer to each of the bits separately, so I could name the bits in the code to something more readable.
For example:
Let's assume MaskCW is a WORD variable, and I want to control bit number 5 to operate a motor. I want to name this bit 'startMotor' without declaring each variable like 'Application.PLC_PRG.MaskCW.startMotor' in the mapping of the device.
I want to refer it in the code like a structure, or any other way that will be easy to read like: MaskCW.startMotor := true;
How can I do it?
Thank you for your time and effort!
I found a way to solve it.
I created a Union with two vars, one of the struct type and the other with word type.
In the GVL I declared a var of the Union type.
In the mapping of the Modbus device I mapped the var from the GVL list and the var of WORD data type from the Union.
Example:
myUnion:
x1 : myStructure;
x2 : WORD;
GVL:
myVar : myUnion;
Mapping:
Application.myVar.x2
Then in the code i can refer to what is listed in myStructure.