Bit Field Distribute Block
Hello,
I am working on trying to implement a function block that I use in RSLogix 5000 in PLCnext Engineer and was wondering if there is an existing block? Or will this have to be a custom block? It would be very helpful to have an example of it if it needs to be custom. The block is called a Bit Field Distribute (BTD).
See attached pictures of the help file of the block.
Any help would be greatly appreciated!
Comments
Hi Daniel,
I'm fairly certain there is no existing function that does this.
It is an interesting little function that shouldn't be too difficult to write.
In ST, it might look something like:
(Note: error checking needs to be added).
One snag might be the variety of Source and Destination data types - I don't think that custom Functions in PLCnext Engineer can take ANY_BIT variables as parameters, which is what you probably want.
In this case it might be a job for a C# function, which could handle ANY parameters and could probably do the copying in fewer operations - perhaps with some combination of bit shifting and masking.
- Martin.
Martin,
Will it ever be possible to use the datatype of ANY_BIT or ANY_NUM for creating function blocks in PLCnext Engineer? I have found myself creating duplicates of blocks just to change the datatype of input and output variables on a function block.
I don't know if this is on the roadmap ... for the moment, the solution is to create the FB in C# (which can handle ANY parameters) and package it as an FB library. For a generally useful function like BFD, which (a) is likely to be used in multiple projects, and (b) has an algoritm that has a nicer solution in C# than in IEC, an FB library in C# is probably a better solution in any case.
If it really must be done in IEC, I guess you could write one BFD function with LWORD variables for Source and Dest (i.e. the longest BIT type), and then ask the user of the Function to convert their BYTE, WORD and DWORD variables to and from an LWORD (using TO_LWORD and TO_x) in order to use the function.
Martin.
Thank you for the helpful information!
It would be good, if FBs and Functions in next versions of PLCnext Engineer can take ANY... variables as parameters, which are really needed.