Jump to content
kvlada

Struct arrays?

Recommended Posts

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.  :)

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...