teichhei hat geschrieben:
If you mean like fiddeling a dint into a byte array or so I do that with pointers.
Sent from my SM-G935F using Tapatalk
no not that, i mean when you are directly addressing the input/output/memory area.
i Siemens you can for example do:
FOR idx:= 0 to 4 DO
variable := variable + MW[idx];
LOOP;
That doesnt seem possible in codesys since you can only direcly adress input/output/memory with %MW0 or %MW10 for example, but you can't use brackets to indirecly adress
I would like to be able to do exactly the same:
FOR idx:= 0 to 4 DO
variable := variable + %MW[idx];
LOOP;
But thats not possible it seems and i can't find any information about indirect addressing if i google it..
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I don t know if it is an school habit, but it helps me in the problem of how to work from OOP point of view with inouts.
If you have an FB wich modelizes an pneumatic cillinder you need, normally, two Dinputs and two DOutputs. From my point of view this inouts have to be internals to the FB_CILLINDER.
For me every DInput is an FB wich has three configurable variables: channel, mask and inverted (that I configure using an csv for every di). Dinput has an boolean output with the value of the physical digital input:
Out:=(xb[channel] and mask) <>0.
It allows me to solve how pass from an sigleton (di) to Oop. And allows me to change without recompile the connection from an logical input to an logical output. Allows me to reconfigure diferent machines with only one code (versioning, rapid prototyping....).
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Josep M. Rams hat geschrieben:
Hi
You can do:
IW_in:pointer to word
IB_in:pointer to byte
After
IW_in:=adr(%iw0)
IB_in:=adr(%iw0)
After
A:=ib_in[4] Reads %iw4
B:=in_w[5] Reads %IB5
Thank you, i had no idea you could use index on pointer without the pointer being an array. It works perfect though.
I know this is a really old school way of doing things but i have some S7 code and i want the codebase to be as similar as possible in codesys
Not all CoDeSys controllers support direct addressing. For the one that do you would locate your variables as follows:
myBool AT%MX0.0:BOOL;//BooleanTypemyInputAT%IX0.0:BOOL;myOut  AT%QX0.0:BOOL;myByte AT%MB0  :BYTE;//ByteTypemySINT AT%MB0  :SINT;myUSINTAT%MB0  :USINT;myByteAraryAT%MB0:ARRAY[0..10]OFBYTE;myWORD AT%MW0  :WORD;//16bittypesmyINT  AT%MW0  :INT;myUINT AT%MW0  :UINT;myWordAraryAT%MW0:ARRAY[0..10]OFWORD;myDWORDAT%MD0  :DWORD;//32bitTypesmyDINT AT%MD0  :DINT;myUDINTAT%MD0  :UDINT;myReal AT%MD0  :REAL;myDwordArrayAT%MD0:ARRAY[0..10]OFDWORD;mySTRINGAT%MB0:STRING; //STRINGÂ
Also attached is a useful memory map. It is excel file because calculates the memory map
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2017-06-07
Originally created by: scott_cunningham
I understand the need to link a software BOOL to a physical real output. But for this I use the hardware IO mapping table of EtherCAT or other fieldbus device. Often, I have to shift around modules and when I do, the memory address changes and I do not want to care about this!
I use FBs with FB_INITs with REFERENCE TO for linking speaking software variables to physical outputs. This example I simply have a BOOL "ActOutput" which I map to an EtherCAT digital output. This forces the link at instantiation without any memory location hard coded. If I insert a module or move the module - CoDeSys handles the memory locations for me.
Original system has Digital Output 0 at %QX0.0. Second screen shot is after inserting a module, which shifts Digital Output 0 to %QX6.0 (for which I can completely ignore - it just works).
Here is an example of my Digital Output with REFERENCE TO:
PROGRAMPLC_PRGVAR  ActOutput:BOOL;//defineatmemorylocation,orusehardwareIOmapping  DigOut1  :DigitalOutput(refOutput:=ActOutput);//referencingisrequiredbyfb_init  Temp1   :BOOL;  Temp2   :BOOL;END_VARDigOut1.TurnOn();Temp1:=DigOut1.State;DigOut1.InvertedLogic:=TRUE;Temp2:=DigOut1.State;END_PROGRAMFUNCTION_BLOCKDigitalOutputVAR  InternalState:BOOL:=FALSE;  ActOutState  :REFERENCETOBOOL;//initnotnecessary-FB_INITforcesreferencing  Inverted   :BOOL:=FALSE;END_VARMETHODFB_INIT:BOOLVAR_INPUT  bInitRetains:BOOL;//ifTRUE,theretainvariablesareinitialized(warmstart/coldstart)  bInCopyCode:BOOL; //ifTRUE,theinstanceafterwardsgetsmovedintothecopycode(onlinechange)  refOutput  :REFERENCETOBOOL;END_VAR//linklocalvartoreallifeBOOLTHIS^.ActOutStateREF=refOutput;END_METHODMETHODTurnOnVAR_INPUTEND_VARTHIS^.InternalState:=TRUE;UpdateState();END_METHODMETHODTurnOffVAR_INPUTEND_VARTHIS^.InternalState:=FALSE;UpdateState();END_METHODMETHODToggleVAR_INPUTEND_VARTHIS^.InternalState:=NOT(THIS^.InternalState);UpdateState();END_METHODMETHODPRIVATEUpdateStateVAR_INPUTEND_VARIFTHIS^.InvertedTHEN  THIS^.ActOutState:=NOT(THIS^.InternalState);ELSE  THIS^.ActOutState:=THIS^.InternalState;END_IFEND_METHODPROPERTYInvertedLogic:BOOLGETInvertedLogic:=THIS^.Inverted;SETTHIS^.Inverted:=InvertedLogic;UpdateState();END_PROPERTYPROPERTYState:BOOLGETState:=THIS^.ActOutState;SETTHIS^.InternalState:=State;UpdateState();END_PROPERTYEND_FUNCTION_BLOCK
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Is it possible to indirectly address memory,input and outputs the way you can do i Siemens Step7?
In step7 you can do MW[x] or IW[x] for example. In codesys it seems that you can only do it absolute, %MW0 %IW0 and not %MW[x].
Is there any way to accomplish this in Codesys?
If you mean like fiddeling a dint into a byte array or so I do that with pointers.
Sent from my SM-G935F using Tapatalk
no not that, i mean when you are directly addressing the input/output/memory area.
i Siemens you can for example do:
FOR idx:= 0 to 4 DO
variable := variable + MW[idx];
LOOP;
That doesnt seem possible in codesys since you can only direcly adress input/output/memory with %MW0 or %MW10 for example, but you can't use brackets to indirecly adress
I would like to be able to do exactly the same:
FOR idx:= 0 to 4 DO
variable := variable + %MW[idx];
LOOP;
But thats not possible it seems and i can't find any information about indirect addressing if i google it..
Have you tried putting your data into an array?
Then you can enter your data into the array:
arr[0] := ...
arr[1] := ...
After that you can just do the for-loop like you did before.
Related
Talk.ru: 1
I see what you mean. Would be interesting to know.
But couldn't you still do something like
paWord := adr(%mw0)
for idx...
variable := paWord^[idx]
In that way you should still get the content of the first, 2nd... word within the loop
Sent from my SM-G935F using Tapatalk
Hi
You can do:
IW_in:pointer to word
IB_in:pointer to byte
After
IW_in:=adr(%iw0)
IB_in:=adr(%iw0)
After
A:=ib_in[4] Reads %iw4
B:=in_w[5] Reads %IB5
Related
Talk.ru: 5
Originally created by: scott_cunningham
What situations require reading direct memory locations? I've never needed this and I am curious. Or is this old-school PLC techniques/habits?
very old school habit
Hi.
I don t know if it is an school habit, but it helps me in the problem of how to work from OOP point of view with inouts.
If you have an FB wich modelizes an pneumatic cillinder you need, normally, two Dinputs and two DOutputs. From my point of view this inouts have to be internals to the FB_CILLINDER.
For me every DInput is an FB wich has three configurable variables: channel, mask and inverted (that I configure using an csv for every di). Dinput has an boolean output with the value of the physical digital input:
Out:=(xb[channel] and mask) <>0.
It allows me to solve how pass from an sigleton (di) to Oop. And allows me to change without recompile the connection from an logical input to an logical output. Allows me to reconfigure diferent machines with only one code (versioning, rapid prototyping....).
Thank you, i had no idea you could use index on pointer without the pointer being an array. It works perfect though.
I know this is a really old school way of doing things but i have some S7 code and i want the codebase to be as similar as possible in codesys
Related
Talk.ru: 5
Not all CoDeSys controllers support direct addressing. For the one that do you would locate your variables as follows:
Also attached is a useful memory map. It is excel file because calculates the memory map
SoM Modbus Table V3 .xls.txt [674 KiB]
Originally created by: scott_cunningham
I understand the need to link a software BOOL to a physical real output. But for this I use the hardware IO mapping table of EtherCAT or other fieldbus device. Often, I have to shift around modules and when I do, the memory address changes and I do not want to care about this!
I use FBs with FB_INITs with REFERENCE TO for linking speaking software variables to physical outputs. This example I simply have a BOOL "ActOutput" which I map to an EtherCAT digital output. This forces the link at instantiation without any memory location hard coded. If I insert a module or move the module - CoDeSys handles the memory locations for me.
Original system has Digital Output 0 at %QX0.0. Second screen shot is after inserting a module, which shifts Digital Output 0 to %QX6.0 (for which I can completely ignore - it just works).
Here is an example of my Digital Output with REFERENCE TO: