# Tips and Tricks

## Forums

1. #### Best Programming Practices

Tips from Unitronics gurus

65
posts
2. #### Tips and Tricks

This is where you can post items of interest that are not covered by other forum sections.

181
posts
• ### Member Statistics

2,612
Total Members
328
Most Online

Joined

• 4
• 0
• 0
• 2
• 3

• ### Posts

• Thanks Joe, So if I understand correctly a 12ma signal will be converted to a value of 9830  which would equate to  5,000PSI which would be the result(F) value.  What I am trying to achieve is to turn a motor off when a certain PSI is reached. 4250PSI in this case.  Looking at other videos it looks like I need to use the store function and store the result value(F) into a Global Int16 Tag. I can then use this value and a compare function to enable/disable a bit and in turn, control my motor.
• Intro
A UniLogic application writer need to keep on some ground rules in order to get the best performance from his UniStream. That’s because a GIF size in is calculated in the next manner:           "Size in memory" = Width * Height * Frames * Bit depth Meaning that using a GIF without considering it dimensions can affected badly on the UniStream.
?How do I manage my GIFs
Let's move on any of the equation elements and see how we can reduce them. Our start point is the "Damper.GIF" which dimensions are: -  By right clicking on the GIF and choosing "Properties" -> "Details" Width – 1000
Height – 1000
Bit depth – 8              :By entering this link (ezgif.com) and choosing the GIF with "Choose file" and then "Upload".  In the page that opened you can use -   To resize the GIF Width & Height. The values that you want to resize to them are the size of the widget linked to the GIF in UniLogic.Enter the values and press "Resize it!".  When it's done in the frame below you can press on "Save" to download it to your PC :(Frames – You can use the same website to remove some unneeded frames (less animated GIFs). In the next tab (1 Pressing on "skip" (2 or 3) can remove the frame (first or fifth). After any change you can use "Animate it!" and see your editing result
:If we edit the example GIF to, let's say 100x100 with 5 frames (the application user can hardly tell) we save

Old    1000 * 1000 * 7 * 8 = 56,000,000 bits
New     100  *   100 * 5 * 8 =       400,000 bits

.That's 55,60,000 bits or 6.95M bytes of memory
?To what values do I need to aim
A user needs to aim as lower as possible because the memory divides between his other application features and it depends on the number of images/GIFs on the current screen. As a rule always aim to a GIF that is size is no higher than 50k
• I recently came a cross with a UniLogic application that use large structs. For example, one struct was composed of 80 members, and most of the members type was INT16, like so:

In memory the struct look like this:

struct MyStruct            //struct size is 80 * 4 = 320 bytes
{
INT32         ID;                        //size 4
INT16         Val_1;                 //size 2
CHAR[2]    padding1;       //size 2
INT16         Val_2;                 //size 2
CHAR[2]    padding2;       //size 2
//….
INT16         Val_79;              //size 2
CHAR[2]    padding79;   //size 2
}

notice the padding that added to the struct. That's  common in software in order to align the memory so work will perform more effectively. This padding cause every 2 bytes in an INT16  type an extra "weight" of 2 bytes – so every INT16 is 4 bytes. One can think that the struct size is 4 + 2 * 79 = 162 bytes, when in fact it 320 bytes, almost two times bigger (!).
Now, let's try the next approach:

In memory:

struct MyStruct_NEW            //struct size is 4 + 2  * 79 = 162 bytes
{
INT32            ID;                    //size 4
INT16[79]     Val_Arr;      //size 158
}

And we got a struct size 162 bytes, as intended. Just imagine we use struct "MyStruct" in a 3,000 line Data Table, we will waste almost 0.5M bytes (3,000  * 158), while "MyStruct_NEW"  waste nothing.   For conclusion,
when creating structs in UniLogic consider the padding factor in order to reduce your PLC memory consumption.
• Have you tried running everything from the one supply? cheers, Aus
• Thank you for the advice guys. I was actually able to solve the problem yesterday. I was working under the assumption that the general send error was a mistake in the wiring. The weighing indicator was actually continuously sending streams, so I changed the variable in the scan from decimal ascii to a stream with the exact lenght and it worked like a charm. That means Joe is spot on with the recommendation for reading the incoming streams. Once again thank you for the help and the fast response. You guys are great. Cheers!

×