Saving images from the PLC
In this sample, images from the PLC are saved to a local drive. The function block FB_VN_WriteImage is used for this purpose.
The save process takes place asynchronously over several cycles. |
Duration of the save process The duration of the save process depends on various factors and can therefore not be stated in general terms. |
Variables
hr : HRESULT;
fbCamera : FB_VN_SimpleCameraControl;
ipImageIn : ITcVnImage;
ipImageInDisp : ITcVnDisplayableImage;
// Sample Specific Variables
fbWriteImage : FB_VN_WriteImage := (nTimeout := T#500MS);
sFilePath : STRING(255) := '';
bWriteImageTrigger : BOOL;
bWriteImageWaitResult: BOOL;
bWriteImageDone : BOOL;
nReturnCode : UDINT;
In this sample an image can be saved by setting the trigger variable bWriteImageTrigger
to TRUE
.
Code
The ipImage
transferred is already completely accepted on the first call of fbWriteImage
with a rising edge at bWrite
and can therefore be released immediately afterwards, e.g. with F_VN_TransformIntoDisplayableImage
. Thereafter, the fbWriteImage
must continue to be cyclically called until the bBusy
output is FALSE
again. This can be the case with an error or even with the first call, e.g. if no file extension or an incorrect one is specified. An evaluation of whether writing was successful or whether an error occurred takes place in the IF block below. If successful, bWriteImageDone
is set and remains unchanged until the next time bWriteImageTrigger
is set.
IF SUCCEEDED(hr) AND ipImageIn <> 0 THEN
IF NOT fbWriteImage.bBusy AND bWriteImageTrigger THEN
bWriteImageTrigger := FALSE;
bWriteImageDone := FALSE;
bWriteImageWaitResult := TRUE;
// With setting sFilePath:= '' to an empty string the images are saved under the default path
// The default path can be set at the service configuration tab of the Vision Node
// If sFilePath is set, it must contain the full path, image name and type
// for example: sFilePath := 'C:\WriteImage\ImageName.bmp'
fbWriteImage(ipImage := ipImageIn, sFilePath := sFilePath, bWrite := TRUE);
END_IF
hr := F_VN_TransformIntoDisplayableImage(ipImageIn, ipImageInDisp, hr);
END_IF
fbWriteImage(sFilepath:= '', bWrite := FALSE);
IF bWriteImageWaitResult AND NOT fbWriteImage.bBusy THEN
bWriteImageWaitResult := FALSE;
// Check if fbWriteImage was finished successfully or implement error handling
IF fbWriteImage.bError THEN
nReturnCode := fbWriteImage.nErrorId AND 16#FFF;
ELSE
bWriteImageDone := TRUE;
nReturnCode := 0;
END_IF
END_IF