Annatooli Posted June 28, 2020 Report Share Posted June 28, 2020 I have two identical functions, except "Function In" has different array lengths. Inside function I can easily determine array length with "Array Size", but understandably "Function In" doesn't accept different array lengths. Is it possible declare "Function In" so it will accept different length of arrays ?? I figured if I declare short arrays they will accepts calls with longer arrays. Question, Is entire array accessible from function or only smaller subset ? Quote Link to comment Share on other sites More sharing options...
MVP 2022 Joe Tauser Posted June 28, 2020 MVP 2022 Report Share Posted June 28, 2020 The input tag parameters are pretty much set in stone when you define a function, so I'm going to guess you don't get to make the array length dynamic. Maybe one of the Creators can chime in and verify. Is there a reason why you can't define the larger array as the input parameter and then not fill it all the way? It would add extra code, but you could initialize the array to zero before you loaded it and passed it and then figure out where in the array the zeros start to determine size. If the function is not overly complex I'd just make two that fits your needs. In PLC land we often have to make due with the tools we're given. Joe T. Quote Link to comment Share on other sites More sharing options...
Saragani Posted June 28, 2020 Report Share Posted June 28, 2020 The array length is passed to the function as a parameter (if I remember correctly), but you can't use it. However, if you use a C Function then you can see it in the function declaration, and also write code that use pointers in order to get the relevant data from the desired index. This off course require knowing C, and you need to know what you are doing in order to avoid CPU Error. Quote Link to comment Share on other sites More sharing options...
Annatooli Posted June 28, 2020 Author Report Share Posted June 28, 2020 Thanks for reply. I will keep both functions for now, but If I need more of those functions I will make unified array lengths, and add parameter with length. I did look into C code but I cant figure out what to do with "bit" variable type. It is "unsigned char" in C, but not in examples nor in documentation is mentioned what I should put into those variables for returning true and false. Quote Link to comment Share on other sites More sharing options...
Saragani Posted June 28, 2020 Report Share Posted June 28, 2020 Simple, Each bit consume 1 byte. If the byte contains 0, then it's false. If the byte contains any other number (but in any case, it should be 1), then it is true Quote Link to comment Share on other sites More sharing options...
Annatooli Posted June 28, 2020 Author Report Share Posted June 28, 2020 So , like this ?? // User code starts below this comment // User code ends above this comment static void Boolean(unsigned char A, volatile unsigned char* C) { // User code starts below this comment if(!A){ *C = 0; // false }else{ *C = 1; // true } // User code ends above this comment } // User code starts below this comment It does compile, just there is "char" in type name. So I assumed it has to be some sort character. Quote Link to comment Share on other sites More sharing options...
Saragani Posted June 29, 2020 Report Share Posted June 29, 2020 I have not checked it, but it looks OK. You can test it on an actual PLC. 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.