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. 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. Link to comment Share on other sites More sharing options...
MVP 2023 Flex727 Posted April 4, 2016 MVP 2023 Report Share Posted April 4, 2016 Rather than an array of Structs, could you build a UDFB and call it for each motor? 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. 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? 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. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now