Can anyone provide me with a dummies guide for using pointers. I need to look at parts of an RS232 receive buffer in my program, but i don't understand how pointers work or how to implement them.
Any help would be appreciated.
Thank You
Dave
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
What does the RS232 port have to do with pointers? A pointer holds an address to a memory location. Typically this is in the variable type DWORD which holds the address in memory. In the IEC 61131 they gave us the following:
ADR operator - Get the address to a variable
^ - de-reference a pointer.
VAR_IN_OUT - This is basically pass by reference instead of pass by value. You can look this up.
<identifier>: POINTER TO <datatype functionblock="">; </datatype></identifier>
I think you can do a google search and find un-godly amounts of information on pointers but in IEC 61131 the main pointers are as described above. Please see the CoDeSys help topic "Pointer".
If you don't know how they work or how to implement them then how do you know you need to use pointers?
A very brief example:
MyVar :int = 3; ( initialize the value of a variable of type int to 3 )
If I need the memory address of this variable then I can use the ADR operator
Pointer_To_MyVar = ADR(MyVar); ( So Pointer_To_MyVar holds a memory address not the value 3 )
If you want the value 3 returned you can dereference the pointer
What_Is_The_Value_MyVar := Pointer_To_MyVar^;
What_Is_The_Value_MyVar will be = 3 after this call.
If you want to change the the value of MyVar through the pointer Pointer_To_MyVar you can do the following:
Pointer_To_MyVar^ := 16;
Now MyVar = 16.
Let us know what you are trying to accomplish so we can better assist.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
Can anyone provide me with a dummies guide for using pointers. I need to look at parts of an RS232 receive buffer in my program, but i don't understand how pointers work or how to implement them.
Any help would be appreciated.
Thank You
Dave
What does the RS232 port have to do with pointers? A pointer holds an address to a memory location. Typically this is in the variable type DWORD which holds the address in memory. In the IEC 61131 they gave us the following:
ADR operator - Get the address to a variable
^ - de-reference a pointer.
VAR_IN_OUT - This is basically pass by reference instead of pass by value. You can look this up.
<identifier>: POINTER TO <datatype functionblock="">; </datatype></identifier>
I think you can do a google search and find un-godly amounts of information on pointers but in IEC 61131 the main pointers are as described above. Please see the CoDeSys help topic "Pointer".
If you don't know how they work or how to implement them then how do you know you need to use pointers?
A very brief example:
MyVar :int = 3; ( initialize the value of a variable of type int to 3 )
If I need the memory address of this variable then I can use the ADR operator
Pointer_To_MyVar = ADR(MyVar); ( So Pointer_To_MyVar holds a memory address not the value 3 )
If you want the value 3 returned you can dereference the pointer
What_Is_The_Value_MyVar := Pointer_To_MyVar^;
What_Is_The_Value_MyVar will be = 3 after this call.
If you want to change the the value of MyVar through the pointer Pointer_To_MyVar you can do the following:
Pointer_To_MyVar^ := 16;
Now MyVar = 16.
Let us know what you are trying to accomplish so we can better assist.