adccommunitymod (AutomationDirect) asked a question.

pointers in click

Created Date: April 17,2010

Created By: jnnewton

**** This post has been imported from our legacy forum. Information in this post may be outdated and links contained in the post may no longer work.****

ok, i am trying to understand how to use pointers in the click software, and need just a couple of examples from someone who knows how c / cpp pointers work. if you could tell me how to do the following things, in the click software, I will need no more help. I have read that only ds (type int) variables can be pointers, so we will use that as my example. i know not everyone here is a c programmer, but i'll try to comment best i can. i am fairly new to the plc game, so i need to explain in c: int src, dest; //addresses already declared, just need to "nickname " int *p_src, *p_dest; //declare two pointers (not necessary in click (i think) //lets say i want to set p_dest (call it ds10) in this case to point to txt1, or src for the example p_src = &src; //p_src now points to src / txt10 nicknamed src //lets now say i want p_src to point to txt1 / nicknamed dest p_dest = &dest; //p_dest now points to dest *p_src = 7; //txt10 would now hold the value 7 *p_dest = *p_src; //txt1 now holds the value 7 p_src++; //p_src now points to the next adress, in this case txt11 thanks for the help.


  • adccommunitymod (AutomationDirect)

    Created Date: April 17,2010

    Created by: bcarlton

    As you point out, at this point the ability to use pointers is very limited in the Click. In the help file - Reference - Memory Addresses scroll down to the use of Pointers. They can only be used in the Single Copy instruction.

    They show the reference is TYPE(DS Register)

    Think of the 'pointers ' not as pointers in 'C ' but as array indexes. The 'pointer ' is just a number, not an absolute address. So if you substitute 'array index ' for 'pointer ' in the explanations your thinking may be clearer.

    So the 'pointer ' (Click terminology) is loaded not by taking the address of a specific variable but just by being set to the numeric part of the reference. Even then the 'pointer ' could be used to 'point ' to any of the data types. It is just a substitute for the numeric part of a memory reference.

    And again, it's ony usable in the Single Copy command.

    Expand Post
  • adccommunitymod (AutomationDirect)

    Created Date: April 17,2010

    Created by: milldrone

    jnnewton,

    I have a hunch that Bernie's reply answered your post to your satisfaction. But if you need more, I have a program that I wrote purely as an exercise. It has not been tested. I do not know if it works. You should be aware that I'm infamous for writing code that does not work until it's tested and modified.

    I was hoping to store values in the PLC using a pointer for advancing the memory location to a different location. The drums may be hard for you to understand.

    Expand Post
  • adccommunitymod (AutomationDirect)

    Created Date: April 19,2010

    Created by: OpZed

    bcarlton Edit2 - I wonder what happens if, at runtime, a 'pointer ' points outside the table area?

    The system bit, "SC44 _Address_Error " will turn ON.

  • adccommunitymod (AutomationDirect)

    Created Date: April 17,2010

    Created by: jnnewton

    ok, i am trying to understand how to use pointers in the click software, and need just a couple of examples from someone who knows how c / cpp pointers work. if you could tell me how to do the following things, in the click software, I will need no more help. I have read that only ds (type int) variables can be pointers, so we will use that as my example. i know not everyone here is a c programmer, but i'll try to comment best i can. i am fairly new to the plc game, so i need to explain in c:

    int src, dest; //addresses already declared, just need to "nickname "

    int *p_src, *p_dest; //declare two pointers (not necessary in click (i think)

    //lets say i want to set p_dest (call it ds10) in this case to point to txt1, or src for the example

    p_src = &src; //p_src now points to src / txt10 nicknamed src

    //lets now say i want p_src to point to txt1 / nicknamed dest

    p_dest = &dest; //p_dest now points to dest

    *p_src = 7; //txt10 would now hold the value 7

    *p_dest = *p_src; //txt1 now holds the value 7

    p_src++; //p_src now points to the next adress, in this case txt11

    thanks for the help.

    Expand Post