Store PLCnext CommunityPLCnext on LinkedInPLCnext on Instagram  PLCnext on YouTube Github PLCnext CommunityStore PLCnext Community

  1. Dan Clark
  2. PLCnext Engineer
  3. Wednesday, 02 October 2019

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!

 

Attachments (2)
Martin PLCnext Team Accepted Answer Pending Moderation
0
Votes
Undo

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:


(* Copy source bits to the destination *)
FOR i := 0 TO Length DO
    IF GET_BIT(Source, SourceBit+i) THEN
        Destination := SET_BIT(Destination, DestBit+i);
    ELSE 
        Destination := RESET_BIT(Destination, DestBit+i);
    END_IF
END_FOR

(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.

Phoenix Contact Electronics Headquarters - PLCnext Runtime Product Management and Support
  1. more than a month ago
  2. PLCnext Engineer
  3. # 1
Dan Clark Accepted Answer Pending Moderation
0
Votes
Undo

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.

  1. more than a month ago
  2. PLCnext Engineer
  3. # 2
Martin PLCnext Team Accepted Answer Pending Moderation
0
Votes
Undo

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.

Phoenix Contact Electronics Headquarters - PLCnext Runtime Product Management and Support
  1. more than a month ago
  2. PLCnext Engineer
  3. # 3
Dan Clark Accepted Answer Pending Moderation
0
Votes
Undo

Thank you for the helpful information!

  1. more than a month ago
  2. PLCnext Engineer
  3. # 4
  • Page :
  • 1


There are no replies made for this post yet.
However, you are not allowed to reply to this post.