Tutorial - VC-Z HALCON Image Acquisition Interface  1.0

Image sensor acquisition, Triggering and Sending results

Image sensor acquisition, Triggering and Sending results

1. Introduction

We have to modifiy our script to fit the real constraints of our application:

  • We have to get images from the sensor and not from an image file.
  • We have to acquire images on hardware trigger
  • We need to send the result to the process (PLC)

Let's start with the first topic.

2. Grab sensor images

There is a specific HALCON Image Acquisition Interface for the VC-Z camera. The file is called 'hAcqVC-Z.so'. You can check if it is present in /usr/lib/ folder in the camera:

FTP_HALCON_bin.png

We can see some other files:

HALCON Files Descriptions
hAcqFile.so HALCON Image Acquisition Interface for virtual acquisition of image files
hAcqVC-Z.so HALCON Image Acquisition Interface to grab image from the sensor directly with 'grab_image'
libhalcon.so This binary file contents every HALCON processing operators
libhalconc.so HALCON C Interface
libhalconcpp.so HALCON C++ Interface
libhdevenginecpp.so HDevelop Engine Interface for C++ application

We can connect to the sensor by open_framegrabber() with the interface 'VC-Z' instead of the 'File' interface:

open_framegrabber('VC-Z', 1, 1, 0, 0, 0, 0, 'default', -1, 'default', -1, 'default', 'default', 'default', -1, -1, AcqHandle)

That is all! The images grabbed by 'grab_image_async()' will come from the sensor.

A complete documentation of the 'VC-Z' Image Acquisition Interface is available here.

3. Hardware trigger

We can enable the hardware trigger by this simple line:

set_framegrabber_param(AcqHandle, 'external_trigger', 'true')

Now when there is no hardware trigger, a timeout could happens. We have to manage this behaviour around the 'grab_image_async()' call.

try
// Grab image only when a rising edge comes in the input TrigIn line
grab_image_async(Image, AcqHandle, -1)
catch (Exception)
// By default the timeout is 5sec (you can change it with the parameter 'grab_timeout')
// if there is no hardware trigger during this delay,
// you will get an exception with the error code 5322 (for timeout)
// It is a normal behaviour, continue to wait a hardware trigger...
continue
endtry

No image is taken until a rising edge happens on TrgIn.

4. Sending results

In HALCON we can handle TCP or UDP or serial communication. Have a look a the HALCON reference documentation on this topic. In our example we propose to establish a TCP socket connection between the camera and a small terminal on the HOST PC called 'TeraTerm' as a TCP client.

So we have to modify our script in order to manage a TCP communication. At first, we create a TCP server in order to accept a client connection:

// Socket connection
Protocol := 'TCP4'
Timeout := 5.0
// Open a listening socket
open_socket_accept (4660, ['protocol','timeout'], [Protocol,Timeout], AcceptingSocket)

And then we are waiting for an incoming connection from a client:

// Wait for an incoming connection, use the timeout of the
// AcceptingSocket
dev_error_var (Error, 1)
dev_set_check ('~give_error')
OpenStatus := 5
NbTry := 0
Socket := []
while (OpenStatus != 2 and NbTry < 3)
socket_accept_connect (AcceptingSocket, 'auto', Socket)
OpenStatus := Error
NbTry := NbTry + 1
endwhile
dev_set_check ('give_error')

We are waiting for a client connection 3 times during the timeout of 5 sec, so we have 15 sec to establish the connection with a client otherwise the 'Socket' variable will be empty and no result will be sent after the processing step:

// Send result
if(Socket != [])
send_data (Socket, 'z', msg + ' ', [])
endif

Have a look at the complete source code at the end of this page. We can launch the script in the camera:

/usr/bin/hrun ./tutorial_1_03.hdev -p ./procedures/

And we have 15 seconds to connect a TCP client to receive results. For example we use 'TeraTerm' client with this settings:

TeraTerm_TcpConnction.png

When the connection succeeds, a result is sent to the TCP client at each rising edge on the TrigIn line:

TeraTerm_TcpReception.png

That's all! Our first real application is done, congratulations!

5. Other examples scripts

There are some other scripts to illustrate the VC-Z HALCON acquisition interface:

  • VC-Z_simple.hdev : A simple example to show the usage of the interface. There is some processing to detect circular shapes. The images can be seen on a X-Server.
  • VC-Z_external_trigger.hdev : A example of acquisition with an external hardware trigger.
  • VC-Z_parameters.hdev : Lists all parameters of a device and log them in the console and in a txt file.
  • VC-Z_subsampling_partialscan.hdev : A example of acquisition with a subsampling and an ROI on the sensor.
  • VC-Z_CaptFPS.hdev : A example to measure the max FPS for a series of image height resolutions.
  • VC-Z_simple_color.hdev : A simple example to grab color images.

You can get the complete source code here.


Next section: Additional tips: Strobe, Flipping image and color processing.