To allow you to use the Framegrabber API in programs you create with C#, you are provided with a C# Framgrabber API wrapper. This wrapper wraps the functionality of the Framegrabber API into a C# API.
All C Framegrabber API functions are wrapped as static functions in one C# class SiSoCsRt. The usage and function declaration is in most parts defined as described in the Framegrabber API documentation. The differences are detailed in the following sections.
Add a reference to the SiSoCsInterface.dll in your C# project. You find the file in your Framegrabber SDK installation: Basler\FramegrabberSDK5.x.x\lib
Copy SiSoCsRt.dll to your PATH directory before running your program. You find the file in your Framegrabber SDK installation: Basler\FramegrabberSDK5.x.x\bin
Each function of the Framegrabber API has a corresponding public static function in the class SiSoCsRt.
Framegrabber API functions that create a reference to a struct and return an error code, are modified such that they return the reference directly (or null if an error occurred), and write back the error code in an out argument. For example, the function Fg_getAppletIterator is defined as:
Each callback function must have the signature of its corresponding delegate. The SiSoCallback class includes all declarations of the available function delegates.
For example, the following code is used to register an APC handler:
The API of the wrapper is basically the same as that of the Framegrabber API. This section contains only the definitions of those functions that are renamed, or have a different order of arguments.
The functions provided here are grouped by library:
For detailed information about using a specific function, as well as for information regarding functions not listed here, refer to the Framegrabber API documentation.
int Fg_getParameterWith… (Fg_Struct Fg, int Parameter, out … Value, uint DmaIndex)#
List of overloaded functions that are used to get frame grabber parameters with information of different types. They replace the Framegrabber API function Fg_getParameterWithType, according to the passed type as follows:
int Fg_setParameterWith…(Fg_Struct Fg, int Parameter, … Value, uint DmaIndex)#
List of overloaded functions that are used to set frame grabber parameters with information of different types. They replace the Framegrabber API function Fg_setParameterWithType, according to the passed type as following:
In Fg_getImagePtrand Fg_getImagePtrEx function, the return type is changed from void pointer, which directly represents the image bytes, in the Framegrabber API into SisoImage instance.
To get again the byte array from SisoImage, the function SisoImage.toByteArray(uint imageSize) can be called.
Additionally, it can be used directly with DrawBuffer function.
In the following function, the error code is written into out int errorCode instead of being returned from the function. While the created handle is returned from the function instead of being passed as an argument. If an error occurred, errorCode will have a value other than 0, and the return value will be null.
C# Framegrabber API Wrapper
Framegrabber API
CLSerialRef clSerialInit(uint serialIndex, out int errorCode)
int clSerialInit(unsigned int serialIndex, void *serialRefPtr)
In the following functions, the error code is written into out int errorCode instead of being returned from the function. While the created handle is returned from the function instead of being passed as an argument. If an error occurred, errorCode will have a value other than 0, and the return value will be null.
C# Framegrabber API Wrapper
Framegrabber API
SgcBoardHandle Sgc_initBoard(Fg_Struct fg, int initFlag, out int errorCode)
int Sgc_initBoard(Fg_Struct* fg, int initFlag, SgcBoardHandle* boardHandle)
SgcBoardHandle Sgc_initBoardEx(Fg_Struct fg, uint initFlag, uint portMask, uint slaveMode, out int errorCode)
int Sgc_initBoardEx(Fg_Struct* fg, unsigned int initFlag, SgcBoardHandle* boardHandle, unsigned int portMask, unsigned int slaveMode)
SgcCameraHandle Sgc_getCamera(SgcBoardHandle boardHandle, uint port, out int errorCode)
int Sgc_getCamera(SgcBoardHandle* boardHandle, const unsigned int port, SgcCameraHandle* cameraHandle)
SgcCameraHandle Sgc_getCameraByIndex(SgcBoardHandle boardHandle, uint index, out int errorCode)
int Sgc_getCameraByIndex(SgcBoardHandle* boardHandle, const unsigned int index, SgcCameraHandle* cameraHandle)
SgcConnectionProfile Sgc_LoadConnectionProfile(Fg_Struct fg, string boardConfigurationFilePath, out int errorCode)
int Sgc_LoadConnectionProfile(Fg_Struct* fg, const char* boardConfigurationFilePath, SgcConnectionProfile* connectionProfilePtr)
string Sgc_getStringValue(SgcCameraHandle cameraHandle, string name, out int errorCode)
int Sgc_getStringValue(SgcCameraHandle* cameraHandle, const char* name, const char* valuePtr)
string Sgc_getEnumerationValueAsString(SgcCamer aHandle cameraHandle, string name, out int errorCode)
int Sgc_getEnumerationValueAsString(SgcCa meraHandle* cameraHandle, const char* name, const char* valuePtr)
In DrawBuffer function, the ulpBuf argument type is changed from void pointer, which directly represents the image bytes, in the Framegrabber API into SisoImage instance.
SisoImage is created using Fg_getImagePtr and Fg_getImagePtrEx functions. Additionally, SisoImage can be created from byte array using the following constructor:
SisoImage(byte[]imagePtr,uintpixelCount)
If such a SisoImage instance is used as a DMA buffer by calling fg_AddMem on it, it must be ensured that the byte array is neither collected nor moved around in memory by the garbage collector. This can be achieved using gcHandle = GCHandle.Alloc(image, GCHandleType.Pinned). The handle can be released with gcHandle.Free() after the memory was removed from the DMA buffer with fg_DelMem.
In the following functions, the error code is written into out int errorCode instead of being returned from the function. While the created handle is returned from the function instead of being passed as an argument. If an error occurred, errorCode will have a value other than 0, and the return value will be null.
C# Framegrabber API Wrapper
Framegrabber API
AviRef IoCreateAVIGray(string filename, int width, int height, double fps, out int errorCode)
int IoCreateAVIGray(void *AviRef, const char *filename, int width, int height, double fps)
AviRef IoCreateAVIGrayW(string filename, int width, int height, double fps, out int errorCode)
int IoCreateAVIGrayW(void *AviRef, const LPCWSTR filename, int width, int height, double fps)
AviRef IoCreateAVIColor(string filename, int width, int height, double fps, out int errorCode)
int IoCreateAVIGrayColor(void *AviRef, const char *filename, int width, int height, double fps)
AviRef IoCreateAVIColorW(string filename, int width, int height, double fps, out int errorCode)
int IoCreateAVIGrayColorW(void *AviRef, const LPCWSTR filename, int width, int height, double fps)
AviRef IoOpenAVI(string fileName, out int width, out int height, out int bitDepth, out int errorCode)
int IoOpenAVI(void *AviRef, const char *fileName, int *width, int *height, int *bitDepth)
SeqRef IoCreateSeq(string pFilename, int width, int height, int bitdepth, int format, out int errorCode)
int IoCreateSeq(void *SeqRef, const char *pFilename, int width, int height, int bitdepth, int format)
SeqRef IoOpenSeq(string pFilename, out int width, out int height, out int bitdepth, int mode, out int errorCode)
int IoOpenSeq(void *SeqRef, const char *pFilename, int* width, int* height, int* bitdepth, int mode)
SisoIoImageEngine IoImageOpen(string filename, out int errorCode)
int IoImageOpen(const char *filename, SisoIoImageEngine *handle)
SisoIoImageEngine IoImageOpenEx(string filename, int RGBSequence, out int errorCode)
int IoImageOpenEx(const char *filename, SisoIoImageEngine *handle, int RGBSequence)
Functions With Different Return Data Types and Out Argument Data Types#
In the following functions, the return type is changed from void pointer, which represents an image handle, to a more specific handle type.
The output arguments unsigned char ** data, which are set to a pointer to the raw image data, are changed to SisoImage, which is a handle for image data in unmanaged memory. To retrieve the data from SisoImage as a byte array, the functions SisoImage.toByteArray(uint imageSize) and SisoImage.asByteArray() are provided.
C# Framegrabber API Wrapper
Framegrabber API
TIFFHandle IoReadTiff(string filename, out SisoImage data, out int width, out int height, out int bitPerSample, out int samplePerPixel)
void *IoReadTiff(const char *filename, unsigned char*data, int *width, int *height, int *bitPerSample, int *samplePerPixel)
TIFFHandle IoReadTiffW(string filename, out SisoImage data, out int width, out int height, out int bitPerSample, out int samplePerPixel)
void *IoReadTiffW(const LPCWSTR filename, unsigned char*data, int *width, int *height, int *bitPerSample, int *samplePerPixel)
TIFFHandle IoReadTiffEx(string filename, out SisoImage data, out int width, out int height, out int bitPerSample, out int samplePerPixel, int RGBSequence)
void *IoReadTiffEx(const char *filename, unsigned char*data, int *width, int *height, int *bitPerSample, int *samplePerPixel, int RGBSequence)
TIFFHandle IoReadTiffExW(string filename, out SisoImage data, out int width, out int height, out int bitPerSample, out int samplePerPixel, int RGBSequence)
void *IoReadTiffExW(const LPCWSTR filename, unsigned char*data, int *width, int *height, int *bitPerSample, int *samplePerPixel, int RGBSequence)
BMPHandle IoReadBmp(string filename, out SisoImage data, out int width, out int height, out int bits)