|
1. Introduction
CyberOptics Semiconductor does not support Delphi for any of our Imagenation frame grabbers, because we do not have the required expertise with the Pascal programming language. However, we always strive to make our products available to the widest possible market. To that end, we sometimes provide interface files and sample programs that were built and donated by our customers. The PXR800 Delphi Starter Kit is such a package. Please feel free to download and use this package with the understanding that while we always support our products, we may not be able to support you with specific Delphi or Pascal questions.
The "Delphi Starter Kit" provides a solid beginning and illustrates a good method for creating Delphi support for the PXR800. It gives you enough to get a sample program up and running, but there are still a number of functions that need to be defined to make the interface complete.
If you have difficulty during development, please call or email our support personnel. While we don't have any recent experience with Pascal or Delphi, it is quite possible that your difficulties may not be directly related to Delphi and we may have solutions.
EMAIL: support@imagenation.com
Toll free: 800-366-9131
2. Delphi Interface Implementation
The application interface to the PXR800 is through two Windows DLLs:
PXR800.DLL: Interface to the frame grabber control functions
PXRFRAME.DLL: Interface to the frame control functions
The PXR800 is formally supported only for C/C++. However, support can be created for almost any language by building the appropriate interface files for the two DLLs listed above.
There are two ways to create an interface file for the PXR800 for Delphi.
- Specify the complete interface for each function including the DLL name.
- Create a structure as we did for C/C++ and specify a minimal interface for each function.
The Delphi Starter Kit uses method 2. If you look at one of our C/C++
samples, you will see that we create two structures with the following two lines of code.
PXRFRAMELIB FrameLib;
PXRAPI PXR;
During initialization, a pointer to each structure is passed to the imagenation_OpenLibrary() function which then fills the structure with pointers to all of the functions in the DLL. A call to a specific function is then made by preceding each call with "PXR." (PXR-dot) or "FrameLib." (FrameLib-dot).
Hence the function call to the Grab() function looks like this:
PXR.Grab();
The function call to AllocateBuffer() looks like this:
FrameLib.AllocateBuffer();
We do this to avoid name collisions. For example, if you use another library that has a function named "Grab()" it will not collide with the Imagenation Grab() function.
Just for reference, the following two lines of code illustrate the actual
OpenLibrary() calls for each DLL in C/C++.
imagenation_OpenLibrary("pxr800.dll", &PXR, sizeof(PXRAPI));
imagenation_OpenLibrary("pxrframe.dll", &FrameLib, sizeof(PXRFRAMELIB);
The Delphi interface file, PXR_Definitions.pas, creates two type definitions called Tpxr and Tpxrframe which are equivalent to the C/C++ structure definitions PXRAPI and PXRFRAMELIB. PXR_Definitions.pas then creates two variables based on the structures called PXR and PXRFRAME that can be accessed by other Pascal units.
TPXR = record
Pad1 : longint;
Pad2 : longint;
AllocateFG : TAllocateFG;
.
.
.
end;
TPXRFRAME = record
Pad1 : longint;
Pad2 : longint;
AllocateBuffer : TAllocateBuffer;
.
.
.
end;
var
PXR : TPXR;
PXRFRAME : TPXRFRAME;
As you can see, the Delphi interface is nearly identical to the C/C++ interface.
3. Interface Files (.H and .PAS)
The PXR800 uses five header files as listed below.
- IFRAME.H
- PXRFRAME.H
- PXR800.H
- PXR800API.H
- IMAGINFO.H
The Delphi Starter Kit uses only a single interface file that incorporates elements from four of the five header files. There are currently no definitions from the IMAGINFO.H file.
The Delphi Starter Kit interface file is called PXR_Definitions.pas. It has enough definitions to build a sample program that will allocate a buffer and grab a frame. It has hooks for all of the functions. If a function that you need is not listed, all you need to do is define it in Pascal and it will work, because the interface is there.
Pointers to functions that are not defined are padded with 4 byte longints and can be replaced by pointers to actual functions at a later time.
4. Delphi Sample Program
The Delphi Starter Kit provides a sample program complete with project files and an executable file. The sample is an excellent format for beginning your own sample or defining and testing functions. The sample has a display area and ample room for buttons. As you add a definition for a new function you can add a button to test the function.
The sample is very basic and was used to build and test the interface. Please note that in its present form, you need click on the OpenLibrary button before grabbing a frame. After you grab a frame, you will see that it is very slowly written to the image component on the form. The speed can be increased if you call the normal Windows API calls from within Delphi.
NOTE: The sample in its present form is set to grab a CCIR / PAL image at a resolution of 768 x 576. If you are using an RS-170 camera, you will need to modify the sample.
5. Delphi Versions
The work of building the interface and the sample was done with Delphi 4, but should be okay with Delphi 5 or 6.
If you decide to complete the interface file, PXR_Definitions.pas, and you would like to share it, please email it to "support@imagenation.com, and we will update this package.
|