Crocodile Tears
Member
Hey guys, was hoping someone could give me a bit of advice here in a couple spots. I'll start off with my dumb code and explain after
MNETC_Index_A := 1700;
Real_Index_A := 0;
For MNETC_Index_A := 1700 to 1742 by 2 do ;
FOR Real_Index_A := 0 to 21 do ;
COP (MNETC.DATA.ReadData[MNETC_Index_A],REALDATA[Real_Index_A],2) ;
END_FOR ;
END_FOR ;
COP (MNETC.DATA.ReadData[1700],REALDATA[0],2) ;
COP (MNETC.DATA.ReadData[1702],REALDATA[1],2) ;
COP (MNETC.DATA.ReadData[1704],REALDATA[2],2) ;
COP (MNETC.DATA.ReadData[1706],REALDATA[3],2) ;
COP (MNETC.DATA.ReadData[1708],REALDATA[4],2) ;
COP (MNETC.DATA.ReadData[1710],REALDATA[5],2) ;
COP (MNETC.DATA.ReadData[1712],REALDATA[6],2) ;
COP (MNETC.DATA.ReadData[1714],REALDATA[7],2) ;
COP (MNETC.DATA.ReadData[1716],REALDATA[8],2) ;
COP (MNETC.DATA.ReadData[1718],REALDATA[9],2) ;
COP (MNETC.DATA.ReadData[1720],REALDATA[10],2) ;
COP (MNETC.DATA.ReadData[1722],REALDATA[11],2) ;
COP (MNETC.DATA.ReadData[1724],REALDATA[12],2) ;
COP (MNETC.DATA.ReadData[1726],REALDATA[13],2) ;
COP (MNETC.DATA.ReadData[1728],REALDATA[14],2) ;
COP (MNETC.DATA.ReadData[1730],REALDATA[15],2) ;
COP (MNETC.DATA.ReadData[1732],REALDATA[16],2) ;
COP (MNETC.DATA.ReadData[1734],REALDATA[17],2) ;
COP (MNETC.DATA.ReadData[1736],REALDATA[18],2) ;
COP (MNETC.DATA.ReadData[1738],REALDATA[19],2) ;
COP (MNETC.DATA.ReadData[1740],REALDATA[20],2) ;
COP (MNETC.DATA.ReadData[1742],REALDATA[21],2) ;
//END_FOR ;
PQM_735.r_735G3.IA := REALDATA[0] /100.0;
PQM_735.r_735G3.IB := REALDATA[1] /100.0;
PQM_735.r_735G3.IC := REALDATA[2] /100.0;
PQM_735.r_735G3.IN := REALDATA[3] /100.0;
PQM_735.r_735G3.VA := REALDATA[4] /100.0;
PQM_735.r_735G3.VB := REALDATA[5] /100.0;
PQM_735.r_735G3.VC := REALDATA[6] /100.0;
PQM_735.r_735G3.VAB := REALDATA[7] /100.0;
PQM_735.r_735G3.VBC := REALDATA[8] /100.0;
PQM_735.r_735G3.VCA := REALDATA[9] /100.0;
PQM_735.r_735G3.W3 := REALDATA[10] /100.0;
PQM_735.r_735G3.U3 := REALDATA[11] /100.0;
PQM_735.r_735G3.Q3 := REALDATA[12] /100.0;
PQM_735.r_735G3.WA := REALDATA[13] /100.0;
PQM_735.r_735G3.WB := REALDATA[14] /100.0;
PQM_735.r_735G3.WC := REALDATA[15] /100.0;
PQM_735.r_735G3.UA := REALDATA[16] /100.0;
PQM_735.r_735G3.UB := REALDATA[17] /100.0;
PQM_735.r_735G3.UC := REALDATA[18] /100.0;
PQM_735.r_735G3.QA := REALDATA[19] /100.0;
PQM_735.r_735G3.QB := REALDATA[20] /100.0;
PQM_735.r_735G3.QC := REALDATA[21] /100.0;
Basically I'm turning modbus integers into a dint, then dumping them into a REAL, scaling appropriately, and putting them into a UDT. The bottom two large fields of COP and REALDATA scaling are the brute force method that works fine. Of course, I have to do this 23 times, so I'm hoping for something a bit more elegant.
I'm fairly certain the top pair of for loops is not going to work correctly as I have a loop that will go to MNETC_Index of 1500 and then put that into every Real_Index from 0-21, then go to 1502 and again go through the 0-21 index again, on and on and on.
Any advice to clean that up? I have always seemed to confuse myself when I end up nesting loop inside of loop and usually retreat to a brute force method.
The lowest section I'll alter as time goes on, the only variable there that will change is the r_735G3, and then the realdata 0-21 will become 50-71, 100-121, and so on. I'm pretty sure I could just do a COP or CPS of length 22 from REALDATA[0] into the individual r_735xx UDT's, as they are the same size and datatype.
MNETC_Index_A := 1700;
Real_Index_A := 0;
For MNETC_Index_A := 1700 to 1742 by 2 do ;
FOR Real_Index_A := 0 to 21 do ;
COP (MNETC.DATA.ReadData[MNETC_Index_A],REALDATA[Real_Index_A],2) ;
END_FOR ;
END_FOR ;
COP (MNETC.DATA.ReadData[1700],REALDATA[0],2) ;
COP (MNETC.DATA.ReadData[1702],REALDATA[1],2) ;
COP (MNETC.DATA.ReadData[1704],REALDATA[2],2) ;
COP (MNETC.DATA.ReadData[1706],REALDATA[3],2) ;
COP (MNETC.DATA.ReadData[1708],REALDATA[4],2) ;
COP (MNETC.DATA.ReadData[1710],REALDATA[5],2) ;
COP (MNETC.DATA.ReadData[1712],REALDATA[6],2) ;
COP (MNETC.DATA.ReadData[1714],REALDATA[7],2) ;
COP (MNETC.DATA.ReadData[1716],REALDATA[8],2) ;
COP (MNETC.DATA.ReadData[1718],REALDATA[9],2) ;
COP (MNETC.DATA.ReadData[1720],REALDATA[10],2) ;
COP (MNETC.DATA.ReadData[1722],REALDATA[11],2) ;
COP (MNETC.DATA.ReadData[1724],REALDATA[12],2) ;
COP (MNETC.DATA.ReadData[1726],REALDATA[13],2) ;
COP (MNETC.DATA.ReadData[1728],REALDATA[14],2) ;
COP (MNETC.DATA.ReadData[1730],REALDATA[15],2) ;
COP (MNETC.DATA.ReadData[1732],REALDATA[16],2) ;
COP (MNETC.DATA.ReadData[1734],REALDATA[17],2) ;
COP (MNETC.DATA.ReadData[1736],REALDATA[18],2) ;
COP (MNETC.DATA.ReadData[1738],REALDATA[19],2) ;
COP (MNETC.DATA.ReadData[1740],REALDATA[20],2) ;
COP (MNETC.DATA.ReadData[1742],REALDATA[21],2) ;
//END_FOR ;
PQM_735.r_735G3.IA := REALDATA[0] /100.0;
PQM_735.r_735G3.IB := REALDATA[1] /100.0;
PQM_735.r_735G3.IC := REALDATA[2] /100.0;
PQM_735.r_735G3.IN := REALDATA[3] /100.0;
PQM_735.r_735G3.VA := REALDATA[4] /100.0;
PQM_735.r_735G3.VB := REALDATA[5] /100.0;
PQM_735.r_735G3.VC := REALDATA[6] /100.0;
PQM_735.r_735G3.VAB := REALDATA[7] /100.0;
PQM_735.r_735G3.VBC := REALDATA[8] /100.0;
PQM_735.r_735G3.VCA := REALDATA[9] /100.0;
PQM_735.r_735G3.W3 := REALDATA[10] /100.0;
PQM_735.r_735G3.U3 := REALDATA[11] /100.0;
PQM_735.r_735G3.Q3 := REALDATA[12] /100.0;
PQM_735.r_735G3.WA := REALDATA[13] /100.0;
PQM_735.r_735G3.WB := REALDATA[14] /100.0;
PQM_735.r_735G3.WC := REALDATA[15] /100.0;
PQM_735.r_735G3.UA := REALDATA[16] /100.0;
PQM_735.r_735G3.UB := REALDATA[17] /100.0;
PQM_735.r_735G3.UC := REALDATA[18] /100.0;
PQM_735.r_735G3.QA := REALDATA[19] /100.0;
PQM_735.r_735G3.QB := REALDATA[20] /100.0;
PQM_735.r_735G3.QC := REALDATA[21] /100.0;
Basically I'm turning modbus integers into a dint, then dumping them into a REAL, scaling appropriately, and putting them into a UDT. The bottom two large fields of COP and REALDATA scaling are the brute force method that works fine. Of course, I have to do this 23 times, so I'm hoping for something a bit more elegant.
I'm fairly certain the top pair of for loops is not going to work correctly as I have a loop that will go to MNETC_Index of 1500 and then put that into every Real_Index from 0-21, then go to 1502 and again go through the 0-21 index again, on and on and on.
Any advice to clean that up? I have always seemed to confuse myself when I end up nesting loop inside of loop and usually retreat to a brute force method.
The lowest section I'll alter as time goes on, the only variable there that will change is the r_735G3, and then the realdata 0-21 will become 50-71, 100-121, and so on. I'm pretty sure I could just do a COP or CPS of length 22 from REALDATA[0] into the individual r_735xx UDT's, as they are the same size and datatype.