Camera Class#
Inheritance Hierarchy#
System.Object
Basler.Pylon.Camera
Syntax#
C#
VB
The Camera type exposes the following members.
Constructors#
Name | Description | |
---|---|---|
Camera() | Creates a camera object and selects the first physical camera device found. | |
Camera(CameraSelectionStrategy) | Creates a camera using the selectionStrategy passed. | |
Camera(ICameraInfo) | Creates a specific camera using information given in the cameraInfo parameter. | |
Camera(String) | Creates a camera based on the serial number parameter. | |
Camera(IDictionary(String, String), CameraSelectionStrategy) | Creates a camera matching the key-value list passed using the selectionStrategy passed, e.g. for creating a camera with a known IP Address or Device User ID. | |
Camera(IEnumerable(KeyValuePair(String, String)), CameraSelectionStrategy) | Creates a camera matching the key-value list passed using the selectionStrategy passed, e.g. for creating a camera with a known IP Address or Device User ID. | |
Camera(String, CameraSelectionStrategy) | Creates a camera based on the camera type (GigE, USB, etc.) using the selectionStrategy passed. |
Properties#
Name | Description | |
---|---|---|
CameraInfo | Provides access to camera information. The camera information can be updated if camera properties have changed. Camera properties may change e.g. if a GigE camera has been assigned a new IP address after reconnection. | |
CanWaitForFrameTriggerReady | Checks to see whether the camera device can be queried whether it is ready to accept the next frame trigger. | |
IsConnected | Indicates if the camera device is properly connected to the camera object while the camera object is open. | |
IsOpen | Indicates if camera object has been opened. | |
Parameters | Returns the parameter collection of the camera for accessing all parameters. Example: camera.Parameters[PLCamera.Width].GetValue(); | |
StreamGrabber | Returns the stream grabber of the camera object. |
Methods#
Name | Description | |
---|---|---|
Close | Closes the connection to the camera. | |
CreateFileStream | Create a file stream for upload or download. | |
Dispose | Releases all resources used by the Camera | |
ExecuteSoftwareTrigger | Executes the software trigger command. | |
GetSfncVersion | Gets the version number of the SFNC specification that the camera complies to. | |
Open() | Opens a connection to the camera device. | |
Open(Int32, TimeoutHandling) | Tries to open a connection to the camera until a timeout occurs. If the camera device is not available, the method tries to access the camera until a timeout occurs. | |
ToString | Gets the friendly name of the camera. (Overrides Object.ToString().) | |
WaitForFrameTriggerReady | Polls the parameters of the camera until the camera is ready to receive a software trigger. |
Events#
Name | Description | |
---|---|---|
CameraClosed | Occurs after the connection to the camera has been closed. | |
CameraClosing | Occurs before the connection to the camera is closed. | |
CameraOpened | Occurs after the connection to the camera has been opened successfully via Open() or Open(Int32, TimeoutHandling). | |
CameraOpening | Occurs before the connection to the camera is opened via Open() or Open(Int32, TimeoutHandling). | |
ConnectionLost | Occurs when the physical connection to the camera has been lost unexpectedly. |
Camera.CameraClosed Event#
Occurs after the connection to the camera has been closed.
Syntax#
C#
VB
Value#
Type: System.EventHandler(EventArgs)
Implements#
Remarks#
During the execution of this event, the camera is already closed.
If an event handler throws an exception, it will be ignored and the remaining handlers will be called.
This event is fired inside the lock of the camera instance.
Camera.CameraClosing Event#
Occurs before the connection to the camera is closed.
Syntax#
C#
VB
Value#
Type: System.EventHandler(EventArgs)
Implements#
Remarks#
If the camera is closed properly, the connection to the camera is still open during the execution of this event.
If an event handler throws an exception, it will be ignored and the remaining handlers will be called.
This event is fired inside the lock of the camera instance.
Camera.CameraOpened Event#
Occurs after the connection to the camera has been opened successfully via Open() or Open(Int32, TimeoutHandling).
Syntax#
C#
VB
Value#
Type: System.EventHandler(EventArgs)
Implements#
Remarks#
During the execution of this event, the connection to the camera is already open.
If an event handler called by this event throws an exception, the connection to the camera will be closed and the exception will be propagated to the caller of Open(). No other handlers will be called.
This event is fired inside the lock of the camera instance.
Camera.CameraOpening Event#
Occurs before the connection to the camera is opened via Open() or Open(Int32, TimeoutHandling).
Syntax#
C#
VB
Value#
Type: System.EventHandler(EventArgs)
Implements#
Remarks#
During the execution of this event, the connection to the camera is not yet open.
If an event handler called by this event throws an exception, it will be propagated to the caller of Open(). No other handlers will be called.
This event is fired inside the lock of the camera instance.
Camera.ConnectionLost Event#
Occurs when the physical connection to the camera has been lost unexpectedly.
Syntax#
C#
VB
Value#
Type: System.EventHandler(EventArgs)
Implements#
Remarks#
Called event handlers should expect exceptions if they call methods of the camera. It is safe to call Close().
If an event handler throws an exception, it will be ignored and the remaining handlers will be called.
This event is fired inside the lock of the camera instance. Event handlers should make no assumptions on the thread from which the event handler is called.
Camera.Close Method#
Closes the connection to the camera.
Syntax#
C#
VB
Implements#
Remarks#
- If the connection to the camera has been already closed, the function returns successfully.
- If the camera is currently grabbing, grabbing is stopped.
- The OnClose event is raised. If any event handler throws an exception it will be ignored and the next event handler will be called.
- The connection to the camera device is closed.
- The OnClosed" is raised. If any event handler throws an exception, it will be ignored and the next event handler will be called.
Error Safety: Does not throw exceptions.
Camera.CreateFileStream Method#
Create a file stream for upload or download.
Syntax#
C#
VB
Public Overridable Function CreateFileStream (
Filename As String,
Direction As FileAccess
) As Stream
Parameters#
- Filename
- Type: System.String
Name of the file in the camera. PLCamera.FileSelector contains a list of available file names. - Direction
- Type: System.IO.FileAccess
Write to the camera or read from the camera.
Return Value#
Type: Stream
Returns a stream object for writing or reading.
Implements#
ICamera.CreateFileStream(String, FileAccess)
Remarks#
Preconditions for updating the camera info:
- The camera is open.
// Copy a file into a byte array:
using (Stream fs = m_camera.CreateFileStream( fileName, System.IO.FileAccess.Read ))
using (MemoryStream ms = new MemoryStream())
{
fs.CopyTo( ms );
byte [] Buffer = ms.ToArray();
}
It is not possible to access multiple files in parallel. Dispose the stream before opening the next.
Thread Safety: This method is synchronized with the lock of the camera object.
Error Safety: Does throw exceptions.
Camera.Dispose Method#
Releases all resources used by the Camera
Syntax#
C#
VB
Camera.ExecuteSoftwareTrigger Method#
Executes the software trigger command.
Syntax#
C#
VB
Implements#
ICamera.ExecuteSoftwareTrigger()
Remarks#
To use this method, the camera has to be configured for software triggering.
Before executing a software trigger, you should check whether the camera is ready to accept a software trigger using WaitForFrameTriggerReady(Int32, TimeoutHandling)Preconditions:
- The camera device is physically connected and a connection to the camera has been opened.
- The camera device supports software triggering.
- The grabbing is started using a stream grabber.
Error Safety:Can throw exceptions.
Camera.GetSfncVersion Method#
Gets the version number of the SFNC specification that the camera complies to.
Syntax#
C#
VB
Return Value#
Type: Version
Returns the version number of the SFNC specification that the camera complies to. If no SFNC version information is available, a version of 0.0.0.0 is returned.
Implements#
Remarks#
You can use the SFNC version number to determine which parameters the camera can provide.
Preconditions:
- The connection to the camera device must be open.
Error Safety: Can throw exceptions.
Camera.Open Method#
Opens a connection to the camera device.
Syntax#
C#
VB
Return Value#
Type: ICamera
Returns a reference to the opened camera.
Implements#
Remarks#
- If the connection to the camera is already open, the function returns successfully.
- The CameraOpening event is fired. The notification of event handlers stops in case any eventhandler throws an exception.
- The connection to the camera device is established.
- The CameraOpened event is fired if the camera object has been opened successfully. The notification of event handlers stops in case any eventhandler throws an exception.
Thread Safety: This method is synchronized with the lock of the camera object.
Error Safety: Can throw exceptions if the camera cannot be opened successfully or if any of the event handlers throws an exception.
Camera.Open Method (Int32, TimeoutHandling)#
Tries to open a connection to the camera until a timeout occurs. If the camera device is not available, the method tries to access the camera until a timeout occurs.
Syntax#
C#
VB
Public Overridable Function Open (
timeoutMs As Integer,
timeoutHandling As TimeoutHandling
) As Boolean
Parameters#
- timeoutMs
- Type: System.Int32
The timeout period in milliseconds. - timeoutHandling
- Type: Basler.Pylon.TimeoutHandling
The action to perform when the function exits with a timeout.
Return Value#
Type: Boolean
Returns false if the camera cannot be found or opened.
Implements#
ICamera.Open(Int32, TimeoutHandling)
Remarks#
- If the camera is already open, the function returns successfully.
- If the camera device is not available, the method tries to rediscover the camera by enumerating all camera devices of the same type or by checking the availability until a timeout occurs or the camera class is disposed.
- If the camera is not found, the method returns or throws an exception. The action depends on the timeoutHandling parameter.
- Calls Open()) if the camera device has been found by enumeration and it is accessible (see GetDeviceAccessibilityInfo(ICameraInfo)).
Error Safety: Can throw exceptions if the camera cannot be opened successfully or if any of the event handlers throws an exception.
Camera.ToString Method#
Gets the friendly name of the camera.
Syntax#
C#
VB
Return Value#
Type: String
Returns the friendly name of the camera.
Remarks#
Thread Safety: This method is thread-safe.
Error Safety: Does not throw exceptions.
Camera.WaitForFrameTriggerReady Method#
Polls the parameters of the camera until the camera is ready to receive a software trigger.
Syntax#
C#
VB
Public Overridable Function WaitForFrameTriggerReady (
timeoutMs As Integer,
timeoutHandling As TimeoutHandling
) As Boolean
Parameters#
- timeoutMs
- Type: System.Int32
The timeout period in milliseconds. If the SoftwareTrigger.IsDone() method does not return true within the given period, a timeout will occur. The exact timeout behavior can be set using the timeoutHandling parameter. - timeoutHandling
- Type: Basler.Pylon.TimeoutHandling
The action to perform when the functions exits with a timeout.
Return Value#
Type: Boolean
Returns true if the camera was ready to receive a software trigger within the given time period. Otherwise, the action specified in timoutHandling is performed.
Implements#
ICamera.WaitForFrameTriggerReady(Int32, TimeoutHandling)
Remarks#
After issuing a software trigger, there is a short time period within which the camera is unable to accept another trigger. During this period, all triggers are ignored. You can use this function to poll until the camera is ready to accept a trigger.
Thread Safety: This method is synchronized with the lock of the camera object.
Error Safety: Can throw exceptions.
Camera Constructor#
Creates a camera object and selects the first physical camera device found.
Syntax#
C#
VB
Remarks#
Creates a camera instance by enumerating all cameras connected to the system and selecting the first camera device found. If no cameras are found, an exception is thrown.
Error Safety:Can throw exceptions.
Camera Constructor (CameraSelectionStrategy)#
Creates a camera using the selectionStrategy passed.
Syntax#
C#
VB
Parameters#
- selectionStrategy
- Type: Basler.Pylon.CameraSelectionStrategy
Sets the selection method that should be used if multiple cameras are found.
Remarks#
Creates a camera instance by enumerating all cameras connected to the system and selecting a camera using the selectionStrategy passed. If no cameras are found, an exception is thrown.
Error Safety:Can throw exceptions.
Camera Constructor (ICameraInfo)#
Creates a specific camera using information given in the cameraInfo parameter.
Syntax#
C#
VB
Parameters#
- cameraInfo
- Type: Basler.Pylon.ICameraInfo
Contains the exact properties of the camera to be created. You can retrieve camera infos by calling Enumerate()
Remarks#
Use this constructor to create a specific camera using information returned by Enumerate(). If no camera is found, an exception is thrown.
Error Safety:Can throw exceptions.
Camera Constructor (IDictionary(String, String), CameraSelectionStrategy)#
Creates a camera matching the key-value list passed using the selectionStrategy passed, e.g. for creating a camera with a known IP Address or Device User ID.
Syntax#
C#
public Camera(
IDictionary<string, string> cameraInfoFilter,
CameraSelectionStrategy selectionStrategy
)
VB
Public Sub New (
cameraInfoFilter As IDictionary(Of String, String),
selectionStrategy As CameraSelectionStrategy
)
Parameters#
- cameraInfoFilter
- Type: System.Collections.Generic.IDictionary(String, String)
A collection of key-value pairs containing device information. You can use this to create a camera with a specific name, a specific IP address, etc. - selectionStrategy
- Type: Basler.Pylon.CameraSelectionStrategy
Sets the selection method that should be used if multiple cameras are found.
Remarks#
Creates a camera instance by a) enumerating all cameras connected to the system, b) removing all cameras not matching the key value pairs passed in propertyKeyValueList, c) selecting a camera using the selectionStrategy passed. If no cameras are found, an exception is thrown.
Error Safety:Can throw exceptions.
// Example
// Selects a USB camera with serial number 20399956
var cameraInfoFilter = new Dictionary<string, string>
{
{CameraInfoKey.SerialNumber, "20399956"},
{CameraInfoKey.DeviceType, DeviceType.Usb}
};
// Shown for demonstration purposes only.
// Selects a GigE camera with known IP Address "192.168.0.101"
var cameraInfoFilter2 = new Dictionary<string, string>
{
{CameraInfoKey.DeviceIpAddress, "192.168.0.101"},
{CameraInfoKey.DeviceType, DeviceType.GigE}
};
// Shown for demonstration purposes only.
// Selects a USB camera with DeviceUserID TopCamera
// See https://docs.baslerweb.com/#t=en%2Fdevice_information_parameters.htm
// or PLCamera.DeviceUserID for more information.
var cameraInfoFilter3 = new Dictionary<string, string>
{
{CameraInfoKey.UserDefinedName, "TopCamera"},
{CameraInfoKey.DeviceType, DeviceType.Usb}
};
// Shown for demonstration purposes only.
// Selects a GigE camera model acA1920-50gc having device DeviceUserID TopCamera
var cameraInfoFilter4 = new Dictionary<string, string>
{
{CameraInfoKey.ModelName, "acA1920-50gc"},
{CameraInfoKey.UserDefinedName, "TopCamera"},
{CameraInfoKey.DeviceType, DeviceType.GigE}
};
using (ICamera cameraTest = new Camera(cameraInfoFilter, CameraSelectionStrategy.Unambiguous))
{
//use the camera
}
Camera Constructor (IEnumerable(KeyValuePair(String, String)), CameraSelectionStrategy)#
Creates a camera matching the key-value list passed using the selectionStrategy passed, e.g. for creating a camera with a known IP Address or Device User ID.
Syntax#
C#
public Camera(
IEnumerable<KeyValuePair<string, string>> cameraInfoFilter,
CameraSelectionStrategy selectionStrategy
)
VB
Public Sub New (
cameraInfoFilter As IEnumerable(Of KeyValuePair(Of String, String)),
selectionStrategy As CameraSelectionStrategy
)
Parameters#
- cameraInfoFilter
- Type: System.Collections.Generic.IEnumerable(KeyValuePair(String, String))
A collection of key-value pairs containing device information. You can use this to create a camera with a specific name, a specific IP address, etc. - selectionStrategy
- Type: Basler.Pylon.CameraSelectionStrategy
Sets the selection method that should be used if multiple cameras are found.
Remarks#
Creates a camera instance by a) enumerating all cameras connected to the system, b) removing all cameras not matching the key value pairs passed in propertyKeyValueList, c) selecting a camera using the selectionStrategy passed. If no cameras are found, an exception is thrown.
Error Safety:Can throw exceptions.
// Example
// Selects a USB camera with serial number 20399956
var cameraInfoFilter = new Dictionary<string, string>
{
{CameraInfoKey.SerialNumber, "20399956"},
{CameraInfoKey.DeviceType, DeviceType.Usb}
};
// Shown for demonstration purposes only.
// Selects a GigE camera with known IP Address "192.168.0.101"
var cameraInfoFilter2 = new Dictionary<string, string>
{
{CameraInfoKey.DeviceIpAddress, "192.168.0.101"},
{CameraInfoKey.DeviceType, DeviceType.GigE}
};
// Shown for demonstration purposes only.
// Selects a USB camera with DeviceUserID TopCamera
// See https://docs.baslerweb.com/#t=en%2Fdevice_information_parameters.htm
// or PLCamera.DeviceUserID for more information.
var cameraInfoFilter3 = new Dictionary<string, string>
{
{CameraInfoKey.UserDefinedName, "TopCamera"},
{CameraInfoKey.DeviceType, DeviceType.Usb}
};
// Shown for demonstration purposes only.
// Selects a GigE camera model acA1920-50gc having device DeviceUserID TopCamera
var cameraInfoFilter4 = new Dictionary<string, string>
{
{CameraInfoKey.ModelName, "acA1920-50gc"},
{CameraInfoKey.UserDefinedName, "TopCamera"},
{CameraInfoKey.DeviceType, DeviceType.GigE}
};
using (ICamera cameraTest = new Camera(cameraInfoFilter, CameraSelectionStrategy.Unambiguous))
{
//use the camera
}
Camera Constructor (String)#
Creates a camera based on the serial number parameter.
Syntax#
C#
VB
Parameters#
- serialNumber
- Type: System.String
A string containing the serial number of the camera. You can read the serial number from the label attached to the camera or by using the pylonViewer.
Remarks#
Creates a camera instance by enumerating all cameras connected to the system and selecting the camera matching the serial number passed. If no cameras are found, an exception is thrown.
Error Safety:Can throw exceptions.
Camera Constructor (String, CameraSelectionStrategy)#
Creates a camera based on the camera type (GigE, USB, etc.) using the selectionStrategy passed.
Syntax#
C#
VB
Parameters#
- deviceType
- Type: System.String
A string containing the camera type (GigE, USB, etc.). You can use the DeviceType class to retrieve valid strings for this parameter. - selectionStrategy
- Type: Basler.Pylon.CameraSelectionStrategy
Sets the selection method that should be used if multiple cameras are found.
Remarks#
Creates a camera instance by enumerating all cameras of the specified type connected to the system and selecting a camera using the selectionStrategy passed. If no cameras are found, an exception is thrown.
using (ICamera camera = new Camera(DeviceType.Usb, CameraSelectionStrategy.FirstFound))
{
//use the first found USB camera
}
Error Safety:Can throw exceptions.
Camera.Open Method#
Overload List#
Name | Description | |
---|---|---|
Open() | Opens a connection to the camera device. | |
Open(Int32, TimeoutHandling) | Tries to open a connection to the camera until a timeout occurs. If the camera device is not available, the method tries to access the camera until a timeout occurs. |
Camera Constructor#
Overload List#
Name | Description | |
---|---|---|
Camera() | Creates a camera object and selects the first physical camera device found. | |
Camera(CameraSelectionStrategy) | Creates a camera using the selectionStrategy passed. | |
Camera(ICameraInfo) | Creates a specific camera using information given in the cameraInfo parameter. | |
Camera(String) | Creates a camera based on the serial number parameter. | |
Camera(IDictionary(String, String), CameraSelectionStrategy) | Creates a camera matching the key-value list passed using the selectionStrategy passed, e.g. for creating a camera with a known IP Address or Device User ID. | |
Camera(IEnumerable(KeyValuePair(String, String)), CameraSelectionStrategy) | Creates a camera matching the key-value list passed using the selectionStrategy passed, e.g. for creating a camera with a known IP Address or Device User ID. | |
Camera(String, CameraSelectionStrategy) | Creates a camera based on the camera type (GigE, USB, etc.) using the selectionStrategy passed. |
Camera.CameraInfo Property#
Provides access to camera information. The camera information can be updated if camera properties have changed. Camera properties may change e.g. if a GigE camera has been assigned a new IP address after reconnection.
Syntax#
C#
VB
Return Value#
Type: ICameraInfo
Returns information about the camera.
Implements#
Remarks#
Returns the camera information collection containing detailed camera information, e.g. name or serial number.
Preconditions for updating the camera info:
- The camera is closed.
- The properties SerialNumber and the DeviceType of the updated camera information and the current camera information are identical.
- The updated camera information is provided by the CameraFinder.
Error Safety: Does not throw exceptions when read. Can throw exceptions when set and the preconditions are not met.
Camera.CanWaitForFrameTriggerReady Property#
Checks to see whether the camera device can be queried whether it is ready to accept the next frame trigger.
Syntax#
C#
VB
Return Value#
Type: Boolean
Returns true if the camera is open and the camera device can be queried whether it is ready to accept the next frame trigger.
Remarks#
If 'FrameTriggerWait' can be selected for 'AcquisitionStatusSelector' and 'AcquisitionStatus' is readable, the camera device can be queried whether it is ready to accept the next frame trigger.
If the nodes mentioned above are not available and the 'SoftwareTrigger' node is readable, the camera device can be queried whether it is ready to accept the next frame trigger.
Thread Safety: This method is synchronized with the lock of the camera object.
Error Safety: Can throw exceptions.
Camera.IsConnected Property#
Indicates if the camera device is properly connected to the camera object while the camera object is open.
Syntax#
C#
VB
Return Value#
Type: Boolean
Returns true if the camera device is properly connected to the camera object while the camera object is open. Returns false if the camera object is closed.
Implements#
Remarks#
The connection to the camera device can be lost if it is physically disconnected from the PC.
Thread Safety:This method is synchronized with the lock of the camera object.
Error Safety: Does not throw exceptions.
Camera.IsOpen Property#
Indicates if camera object has been opened.
Syntax#
C#
VB
Return Value#
Type: Boolean
Returns true if camera object has been opened.
Implements#
Remarks#
The camera object will not automatically close itself if the connection to the camera device is lost, e.g., if the camera device is physically disconnected from the PC.
Thread Safety: This method is synchronized with the lock of the camera object.
Error Safety: Does not throw exceptions.
Camera.Parameters Property#
Returns the parameter collection of the camera for accessing all parameters. Example: camera.Parameters[PLCamera.Width].GetValue();
Syntax#
C#
VB
Return Value#
Type: IParameterCollection
Returns the parameter collection of the camera.
Implements#
Remarks#
You can use the parameter collection to configure the camera device and the camera instance through parameters. You can access parameters by their name or predefined parameter lists.
There are several predefined parameter lists available:
- PLCamera
- PLCameraInstance
- PLStreamGrabber
- PLEventGrabber
- PLTransportLayer
You can access parameters by passing a key from a parameter list to the index operator, e.g. C#
Thread Safety: This method is synchronized with the lock of the camera object.
Error Safety: Does not throw exceptions
Camera.StreamGrabber Property#
Returns the stream grabber of the camera object.
Syntax#
C#
VB
Return Value#
Type: IStreamGrabber
Returns the stream grabber of the camera object.
Implements#
Remarks#
The stream grabber can be used retrieve images from the camera.
Thread Safety: This method is synchronized with the lock of the camera object.
Error Safety: Does not throw exceptions.