Hi all,
I've got a PLC program that's supposed to read the data of the individual ports on a Stratix switch (for example, the MAC address) through CIP messaging and then store this data in an array of UDTs that represent the switch port. The structure of the program is as follows:
0) There are two controller tags: Port_Index and Last_Port_Index that represent the index of the port that is currently being read and the index of the port that was last read, respectively. These start at 1 and 0, respectively.
1) There is a rung with a label called Port_Message_Trigger. It checks to see if Port_Index is not equal to Last_Port_Index. If this evaluates to true, the rest of the rung will copy Port_Index into the Instance parameter of the MSG instructions, which pull the data from the port and push it into a UDT called Temp_Port.
2) The next rung checks to see if Port_Index is equal to Last_Port_Index. If this evaluates to true, Port_Index is incremented by 1, or if it is already at the maximum (26, representing the 26 ports on the switch), it is reset to 1. Then a jump instruction is called to go back to the rung labeled Port_Message_Trigger.
3) The next rung checks if the MSG instructions have completed and, if so, copies the data from Temp_Port into the array of UDTs at the index specified by Port_Index.
4) The next rung moves the value of Port_Index into Last_Port_Index.
5) The routine is executed again from the beginning.
The idea behind this program is that the Class and Attribute are identical for a specific parameter for any given port on the switch. The only thing that changes is the Instance number, which ranges from 1 to 26 according to the EDS. So the program will start at Instance 1, read the data, copy it into the UDT array at that index, update to show that Instance 1 has already been read, and then move on to the next Instance until it has read all 26 ports.
What I find happening, however, is that the indices in my array are being overwritten by data that matches to other ports. For example, the MAC address of Port 1 is XX-XX-XX-XX-XX-41. Port 2 is XX-XX-XX-XX-XX-42, and so on. After the program runs, what should happen is that index 1 of my array gets the MAC address ending with 41, index 2 gets 42, etc. What is actually happening is that every index is getting MAC 41, and then every index is getting MAC 42, and so on.
The copy instruction I have explicitly copies the values in Temp_Port into PortUDTArray[Port_Index], and to my understanding, Temp_Port should only ever be storing the data from the MSG instruction with the Instance at whatever Port_Index is during the current scan cycle. So I'm struggling to figure out why my data is constantly being overwritten.
What exactly am I missing here?
I've got a PLC program that's supposed to read the data of the individual ports on a Stratix switch (for example, the MAC address) through CIP messaging and then store this data in an array of UDTs that represent the switch port. The structure of the program is as follows:
0) There are two controller tags: Port_Index and Last_Port_Index that represent the index of the port that is currently being read and the index of the port that was last read, respectively. These start at 1 and 0, respectively.
1) There is a rung with a label called Port_Message_Trigger. It checks to see if Port_Index is not equal to Last_Port_Index. If this evaluates to true, the rest of the rung will copy Port_Index into the Instance parameter of the MSG instructions, which pull the data from the port and push it into a UDT called Temp_Port.
2) The next rung checks to see if Port_Index is equal to Last_Port_Index. If this evaluates to true, Port_Index is incremented by 1, or if it is already at the maximum (26, representing the 26 ports on the switch), it is reset to 1. Then a jump instruction is called to go back to the rung labeled Port_Message_Trigger.
3) The next rung checks if the MSG instructions have completed and, if so, copies the data from Temp_Port into the array of UDTs at the index specified by Port_Index.
4) The next rung moves the value of Port_Index into Last_Port_Index.
5) The routine is executed again from the beginning.
The idea behind this program is that the Class and Attribute are identical for a specific parameter for any given port on the switch. The only thing that changes is the Instance number, which ranges from 1 to 26 according to the EDS. So the program will start at Instance 1, read the data, copy it into the UDT array at that index, update to show that Instance 1 has already been read, and then move on to the next Instance until it has read all 26 ports.
What I find happening, however, is that the indices in my array are being overwritten by data that matches to other ports. For example, the MAC address of Port 1 is XX-XX-XX-XX-XX-41. Port 2 is XX-XX-XX-XX-XX-42, and so on. After the program runs, what should happen is that index 1 of my array gets the MAC address ending with 41, index 2 gets 42, etc. What is actually happening is that every index is getting MAC 41, and then every index is getting MAC 42, and so on.
The copy instruction I have explicitly copies the values in Temp_Port into PortUDTArray[Port_Index], and to my understanding, Temp_Port should only ever be storing the data from the MSG instruction with the Instance at whatever Port_Index is during the current scan cycle. So I'm struggling to figure out why my data is constantly being overwritten.
What exactly am I missing here?