Jump to content

An array as output of a function


Igi

Recommended Posts

I need to write to INT16 array in C function. Is it possible to do it? I have noticed the header of a C function contains only inputs. I tried to directly write to an array(which was the input of a function) but it did not work.

Link to comment
Share on other sites

  • 7 years later...

Hi all, I'm new to the forum myself and getting into some PLC programming - sorry to revive an old post.

I am curious what the suggested method is to update an array as suggested by @Igi . Or if you were able to find a workaround that worked for your application Igi, I would be curious to hear what you ended up doing. I was hoping to be able to implement something like this in C-code whereby I have a few functions that are 1. shifting values in an array, 2. calculate values and save them into specific locations in an array, 3. Test if values are within a certain range and then write that to a location in an array. I probably could do some of this with ladder but it would be very lengthy code and is easier to write in C which is how it was done coming from another HMI platform. Also I found that some of the documentation for array ladder functions are lacking in the documentation but was thankfully able to find some explanation in forums. I realize I only gave a very vague description of what I am trying to do but was curious if some functionality has changed since this 2016 post.

For example, here is a snip of one of the codes where I tried to write to two arrays. I have two arrays as the input and two uint16 outputs which I point to the 10th element in the respective arrays.

static void StackPush(volatile unsigned short* PSTKinF, int PSTKinFLen, volatile unsigned short* CSTKinF, int CSTKinFLen, volatile unsigned short* PSTKoutF9, volatile unsigned short* CSTKoutF9)
{
	// User code starts below this comment

volatile unsigned short Istk = 0; 

for (Istk= 0; Istk == 8; ++Istk) 
{
	*(PSTKinF+Istk) = *(PSTKinF + (Istk + 1));
	*(CSTKinF+Istk) = *(CSTKinF + (Istk + 1));
} //end for 

*(PSTKinF+9) = *(PSTKoutF9);
*(CSTKinF+9) = *(CSTKoutF9);
return;

 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

This site uses cookies. By clicking I accept, you agree to their use.