mshaver Posted March 26, 2014 Posted March 26, 2014 Is there a way to accomplish the following? I want to end up with an array of pointers defined as follows: ptr PosScaler(1)->Motor[1].CoordSf[6]; ptr PosScaler(2)->Motor[2].CoordSf[7]; ptr PosScaler(3)->Motor[3].CoordSf[8]; ptr PosScaler(4)->Motor[4].CoordSf[0]; ptr PosOffset(1)->Motor[1].CoordSf[32]; ptr PosOffset(2)->Motor[2].CoordSf[32]; ptr PosOffset(3)->Motor[3].CoordSf[32]; ptr PosOffset(4)->Motor[4].CoordSf[32]; And I want to be able to refer to the pointers in motion programs and PLC's using a local variable as an index, generally like the following: {expression1} = {expression2} * PosScaler(myIndex) + {expression3} * PosOffset(myIndex) Can I accomplish this or something functionally equivalent?
steve.milici Posted March 26, 2014 Posted March 26, 2014 You can do exactly this in your program or a header file (note your second set will overwrite the first set): ptr PosScaler(1)->Motor[1].CoordSf[6]; ptr PosScaler(2)->Motor[2].CoordSf[7]; ptr PosScaler(3)->Motor[3].CoordSf[8]; ptr PosScaler(4)->Motor[4].CoordSf[0]; You can then use local variables in the index as in: global myOtherVar open prog myProg local myVar myOtherVar = PosScaler(myVar) . . . close You cannot however have an expression on the left-hand side of the assignment operator (the "=" sign).
mshaver Posted March 26, 2014 Author Posted March 26, 2014 So when I place the following in global definitions; ptr PosScaler(1)->Motor[1].CoordSf[6]; ptr PosScaler(2)->Motor[2].CoordSf[7]; ptr PosScaler(3)->Motor[3].CoordSf[8]; ptr PosScaler(4)->Motor[4].CoordSf[0]; The right side is underlined in red with a message "syntax error, unexpected IDENTIFIER, EXPECTING '*', or ..." etc.etc. Tried to compile. Will not compile. Yields same error message as directly above. IDE = 1.6.0.109 ???
Sina.Sattari Posted March 27, 2014 Posted March 27, 2014 try this: ptr PosScaler(5)->*; PosScaler(1)->Motor[1].CoordSf[6]; PosScaler(2)->Motor[2].CoordSf[7]; PosScaler(3)->Motor[3].CoordSf[8]; PosScaler(4)->Motor[4].CoordSf[0];
mshaver Posted March 28, 2014 Author Posted March 28, 2014 I assume the first line should go in global definitions ptr PosScaler(5)->*; Where should the remaining pointer definitions go? In global definitions or in a plc? PosScaler(1)->Motor[1].CoordSf[6]; PosScaler(2)->Motor[2].CoordSf[7]; PosScaler(3)->Motor[3].CoordSf[8]; PosScaler(4)->Motor[4].CoordSf[0]; What's happening is the first line, PosScaler(1)->Motor[1].CoordSf[6]; ends up underlined in red and the build fails. However, if I fiddle with it long enough, such as removing the bottom two lines and then putting them back, eventually I can get the red underline to go away and then the build succeeds. Additionally, if I place any 3 of the above 4 lines in either global definitions or a PLC, the IDE accepts it. As soon as I add the 4th definition the IDE chokes and underlines the first definition in red and the build fails. The IDE is extremely buggy, finicky, unrepeatable, unpredictable, and I have no idea whether something is really going to work or fail.
Sina.Sattari Posted March 28, 2014 Posted March 28, 2014 All Global, CSGlobal and Pointer definitions should be placed in .pmh files under "Global Includes" folder under "PMAC Script Language". If you use the exact code I posted earlier in a pmh file in "Global Includes" folder, you will not get any errors in download. Disregard the red squiggly line under the pointer assignment, which I believe is caused by language service. We will look into this problem.
Recommended Posts