kvlada Posted April 3, 2016 Report Share Posted April 3, 2016 Is it possible to implement struct arrays in UniLogic? For example, I have a struct for a motor: STRUCT MotorData: BIT RunCommand BIT Feedback BIT IgnoreFeedback [retained] TIMER FeedbackDelay [retained] BIT Fault UINT8 FaultCounter [retained] UINT16 WorkingHoursTotal [retained] And I want to do: GLOBALVAR MyMotors: Type: MotorData[37] Because I have 37 motors to control. And then later, I want to do things like: SET ALIAS: MyMotors.RunCommand[12] = "Motor_K4-5A_Run" SET ALIAS: MyMotors.Fault[12] = "Motor_K4-5A_Fault" SET ALIAS: MyMotors.FaultCounter[12] = "Motor_K4-5A_FaultCounter" And other wicked things, like: if (Motor_K4-5A_Fault && Motor_K4-5A_FaultCounter < 255) Motor_K4-5A_FaultCounter++; This would ease things up so much! Instead of creating 37 individual global variables for each motor, I'll need only one. Quote Link to comment Share on other sites More sharing options...
Saragani Posted April 4, 2016 Report Share Posted April 4, 2016 Well, sort of. You have Data Tables, which are basically array of structs. Quote Link to comment Share on other sites More sharing options...
MVP 2022 Flex727 Posted April 4, 2016 MVP 2022 Report Share Posted April 4, 2016 Rather than an array of Structs, could you build a UDFB and call it for each motor? Quote Link to comment Share on other sites More sharing options...
kvlada Posted April 4, 2016 Author Report Share Posted April 4, 2016 Well, sort of. You have Data Tables, which are basically array of structs. But I can't set aliases to individual fields in a data table. Rather than an array of Structs, could you build a UDFB and call it for each motor? That's what I resorted to, after trying out everything else. Quote Link to comment Share on other sites More sharing options...
Saragani Posted April 5, 2016 Report Share Posted April 5, 2016 But won'y you still need to create 37 instances of the Motor struct, even though you have a UDFB? Quote Link to comment Share on other sites More sharing options...
kvlada Posted April 5, 2016 Author Report Share Posted April 5, 2016 But won'y you still need to create 37 instances of the Motor struct, even though you have a UDFB? I made arrays in the struct definition. And then, defined aliases in a global var. Kinda cumbersome, but gets the job done. If I want to put more motors, just increase array length in struct definition, and copy-paste more UDFB to take care of data processing. UniStream has 2 MB memory for variables, and that's awesome. Don't have to worry about losing free space. Still, it would be really nice to be able to make arrays of structs. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.