Kpotmake Posted October 16, 2021 Report Share Posted October 16, 2021 Hello all, I was asked to write some software for a machine using a Unitronics PLC, programming in Unilogic is new to me but I've got the machine up and running quite easily, the software is verry intuitive. However it does lack structured text programming... for the more complex tasks I was told I could write my own C functions. This does however bring some limitations with it, the worst one being not being able to acces the global tags and being limited to 256 bytes of data within the functions. Is there a way to call other functions within the C function? This would be a workaround for these limitation. For example: I need to loop through an array that has 100 items, and then perform a calculation on these items. The looping part would fit in a C function but the calculation combined with the array size would require more then 256 bytes. If I could call another function when looping through the for loop this would solve my problem. 1 Quote Link to comment Share on other sites More sharing options...
Rivka Posted October 20, 2021 Report Share Posted October 20, 2021 Hello, Well... calling ladder functions from C functions is possible, as you can see below, but although calling C functions from within C functions is also possible, it is not sure it'll help you regarding local variables limitation as I can see in Help the following line 1 Quote Link to comment Share on other sites More sharing options...
Rivka Posted October 20, 2021 Report Share Posted October 20, 2021 @Saragani, do you know if the 256 bytes limitation is only on local variables or include in/out variables as well? If it is only on local variables,ย Kpotmake can get along by creating ladder function that declares all local variables and passes them as Function inputs to the C function. Do I make sense? ย 1 Quote Link to comment Share on other sites More sharing options...
Marco Mendoza Posted December 13, 2022 Report Share Posted December 13, 2022 Hello folks, I'm trying to use as input variables to aย C function a couple of unsigned integer arrays. My output is a single integer variable that contains the total result of the addition of both vectors or arrays. I have already compiled the code for C and it works well but as soon as I compile again the code on Unilogic the followingย errors arise. I would appreciate your help with this issue. ย The arrays are declared like this ones. ย My output variable is an UINT32 type. The errors that the Unilogic Compiler shows are the following ones. ย ย Quote Link to comment Share on other sites More sharing options...
Marco Mendoza Posted December 13, 2022 Report Share Posted December 13, 2022 Dear fellas, Let me thanks you for your kindness to share technical solutions. Concerning my last technical support request, I was making a mistake in the code. This symbol "*"ย must be written before the result of a function, for my case (ย *Profile_Time_Totalizer_1ย ) this is specific for the C functions in Unilogic because the C compilers doesn't require that. The arrays are well, also the inputs and output variables. Please see my basic C code with that mistake corrected below. ย Very truly yours, Marco๐ Quote Link to comment Share on other sites More sharing options...
Rivka Posted December 14, 2022 Report Share Posted December 14, 2022 Hello@Marco Antonio Mendoza Happy to hear that you solved your issue! Here, UniLogic probably saved you some time as the code you wrote before did not operate the intended operation. It saved a value into the pointer itself and not to the value pointed out by the pointer. The fact that it worked in another compiler was probably due to a different setting of warnings and errors and the other compiler permitted an assignement of type int* = int, which usually points out an error in the code. You might have a look onย https://www.programiz.com/c-programming/c-pointersย to understand better how pointers work. You can also use our new ladder element called "for loop" (search UL help) that would have solved your issue without writing a line of C code.ย Hope that helped Rivka 1 Quote Link to comment Share on other sites More sharing options...
Marco Mendoza Posted December 14, 2022 Report Share Posted December 14, 2022 Thanks Riva for your help and advice. I'm taking a look at the article in the link you shared to us. Just a detail:ย ย After I compiled the code showed above. Nor the C compiler "https://www.onlinegdb.com/online_c_compiler"ย ย ย ย using standard C version, neither the Unilogic Compiler showed me mistakes. I need to learn,ย how a pointer work in fact?.ย the article point at that.ย One more time, thanks for your kindness and guidance. Very truly yours, Marco๐๐๐ฉ ย Quote Link to comment Share on other sites More sharing options...
Rivka Posted December 15, 2022 Report Share Posted December 15, 2022 Hello, The corrected code you posted above is indeed correct : you don't assign a value to the pointer itself anymore, but to the value pointed by the pointer. That's what was intended and both compiler agree that it is ok. If you want to continue using C functions, you probably need to get acquainted with C pointers (and with C subtilities in general), but if your needs are close to the simple sum loop you just did, consider using the loop ladder element (have a look on the help, it is very simple and no need for C code)ย Hope it helped Rivka 1 Quote Link to comment Share on other sites More sharing options...
Marco Mendoza Posted December 15, 2022 Report Share Posted December 15, 2022 Thanks my brother. Rivka For the tutorial you recommended me and your follow up.ย www.programiz.com I'm delighting myself with the Unilogic/Unistream experience. Unistream is a good technology toy for good boys. Very truly yours, Marco๐๐๐ฅ๐ฉ Guatemala, Central America ย 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.