Skip to content

Overview

FB_VideoPlaybackControl

This is a function block to add the feature of buffering the images from a vision system and then stitch them together to create a video. In order to do this, the PLC will communicate with a C# application. The C# application will connect as a client to the ADS of the PLC on Local and at port 851. The C# App has the ability to work on multiple cameras from one PLC.

Parameters

The Parameters_Vision are adjustable per application and have the following defaults

1
2
3
4
5
6
{attribute 'qualified_only'}
VAR_GLOBAL CONSTANT
    MAX_RESULTS_BUFFER_BYTES   : UDINT := 1000;
    MAX_NUMBER_CAMERAS : USINT := 1;
    MAX_NUMBER_IMAGES_2_VIDEO : UINT := 200;
END_VAR

GVL_Images2Video

In order to make a C# application with as little configuration as possible, the following GVL data was created so the program can run easily. The first thing the C# app does is ask how many cameras and then it creates the ability to connect to the data of each camera.

1
2
3
4
5
{attribute 'qualified_only'}
VAR_GLOBAL
    NumberOfCameras    : UINT := Parameters_Vision.MAX_NUMBER_CAMERAS;
    CameraData         : ARRAY[1..Parameters_Vision.MAX_NUMBER_CAMERAS] OF ST_Image2Video;
END_VAR

Definition

FUNCTION_BLOCK FB_VideoPlaybackControl EXTENDS FB_ListenerBase2 IMPLEMENTS I_CyclicFB

FB_ListenerBase2

Name Return Type Input Description
Execute HRESULT none This is called to run the listening code
OnAlarmRaised HRESULT fbEvent : REFERENCE TO FB_TcEvent This gets called when an alarm with this filtering happens

This is the subscription to the Events and the JSONString is:

JSONString : T_MaxString := '{"CreateVideo": 1}';

1
2
3
4
5
6
7
8
IF _Subscribe THEN
    _Subscribe := FALSE;
    JSONFilter.Clear().JsonAttribute.Value.EqualTo(JSONString); //define all events (messages and alarms) from this eventclass   
    hr := Subscribe2(JSONFilter);                               //subscribe to retrieve defined events
    IF SUCCEEDED(hr) THEN
        _Subscribed := TRUE;
    END_IF
END_IF

I_CyclicFB & I_BaseFB

1
2
3
4
5
6
7
    //Base FB
    _Busy    : BOOL := TRUE;
    _Error   : BOOL;
    _ErrorID : UDINT;

    //Cyclic FB
    _InitComplete : BOOL;

Methods

Name Return Type Input Description
AddImage BOOL ipImageIn : ITcVnImage This method will add images the ring buffer. If it is processing the images to files then it does not add them
WriteImage BOOL BufferImageSaveNameIndex : INT
Index : INT
This method will write a single file to the name 'ImageXXX.png' Where XXX is the Index and the image comes from BufferImageSaveNameIndex loacation in the buffer. It is called in the CyclicLogic up to Parameters_Vision.MAX_NUMBER_IMAGES_2_VIDEO times.
CyclicLogic None None This method calls the Execute for the FB_ListenerBase2, Subscribes/Unsubscribes and runs logic for Image to Video

Flowchart

This is the flow of the Camera state engine and what happens once an image has been received (VisionTask VisionCamera.CyclicLogic )

flowchart
b{AcquiringImage State<br>If Image Received}
c[ProcessImage Method]
c1{Buffer Enabled}
b--"Yes"-->c
c-->d[Make Displayable]
d-->c1--"Yes"-->d1
d1[Add Image to VideoPlayback Buffer]
c1--"No"-->b
d1-->b

This is the VideoPlayBack.CyclicLogic (Vision Task VisionCamera.CyclicLogic->VideoPlayback.CyclicLogic)

flowchart
e{If an alarm}
e1{If delay Passed}
f[Trigger Video<br>Disable Image buffer]
g[Write buffer Images to files]
h[set bit for C# to make Video]
i{Video Made}
j[Enable Image Buffer]

e--"Yes"-->e1--"Yes"-->f-->g-->h-->i--"Yes"-->j-->e

Data To/From C# App (ST_Image2Video)

Name Type Description
VideoPathSource STRING Location on PLC for the Video to be written
ImagePathSource STRING Location on PLC for the images to be found
VideoFilename STRING File name for the video source
VideoCreate BOOL Create the Video from images in the ImagePathSource
VideoCreated BOOL Video is created
VideoFPS UINT Video Frames Per Second
Heartbeat BOOL Heartbeat between PLC and C# app