Skip to content

Serial Communication#

The Serial Communication camera feature allows you to establish serial communication between a host and an external device through the camera's I/O lines.

This means the camera acts as an intermediary UART device between the host and another device.

Using the Feature#

How It Works#

The camera provides two independent serial port FIFOs: one for the outgoing (Tx) data, and one for the incoming (Rx) data. For communication with the host, both FIFOs use a common transfer buffer.

Serial Communication Diagram

To make use of the interface outlined above, you must implement a suitable communication protocol. The actual implementation of the protocol depends on your system setup and the characteristics of your devices.

Camera parameters that help you implement the protocol are listed below.

Configuring Serial Communication#

To configure serial communication between the camera and an external device:

  1. Set the BslSerialBaudRate parameter to the baud rate of the external device, e.g., Baud9600.
  2. Set the BslSerialNumberOfDataBits parameter to the number of data bits used by the external device, e.g., Bits8.
  3. Set the BslSerialNumberOfStopBits parameter to the number of stop bits used by the external device, e.g., Bits1.
  4. Set the BslSerialParity parameter to the kind of parity check performed by the external device, e.g., Even.
  5. Configure the camera's input signal. To do so, set the BslSerialRxSource parameter to the I/O line that is to receive serial data, e.g., Line2. The line must be configured as input.
  6. Configure the camera's output signal:
    1. Set the LineSelector parameter to the I/O line that is to transmit serial data, e.g., Line3. The line must be configured as output.
    2. Set the LineSource parameter to SerialTx.

Testing Serial Communication#

To test serial communication without having an external device connected to the camera, or to rule out errors caused by the external device, set the BslSerialRxSource parameter to SerialTx.

This creates a loopback: The serial input is connected to the serial output internally, so the camera receives exactly what it transmits.

Transmitting and Receiving Data#

After you have configured serial communication, you can send data to the external device and receive data from it.

Info

For more information, see the ParametrizeCamera_SerialCommunication (C++) code sample in the pylon API Documentation.

Transmit and Receive Parameters#

The following parameters are involved in both transmitting and receiving data:

  • BslSerialTransferBuffer: The transfer buffer holds the data to be transmitted, and also contains the data received. It can hold up to 16 symbols. A symbol consists of 7 or 8 bits, depending on the BslSerialNumberOfDataBits setting. On GigE cameras, the transfer buffer must be accessed in DWORDs (multiples of 4 bytes), even if the transfer length isn't a multiple of 4. For example, if you set the BslSerialTransferLength parameter to 9, you must read 12 bytes from the buffer for each transaction. On USB and CoaXPress cameras, this restriction does not apply.
  • BslSerialTransferLength: When receiving, indicates the number of symbols the camera has received during the last transaction. When transmitting, specifies how many symbols the camera should transmit per transaction. The maximum is 16.

Transmit Parameters#

The following parameters are involved in transmitting data:

  • BslSerialTransmit: Execute this command to transmit the current value of the transfer buffer via the serial output line. This also updates the state of the BslSerialTxFifoEmpty and BslSerialTxFifoOverflow parameters. See below.
  • BslSerialTxFifoEmpty: Indicates whether the transmitting FIFO is empty, i.e., whether the camera is ready to transmit data.
  • BslSerialTxFifoOverflow: Indicates whether the transmitting FIFO has overflown. An overflow occurs if new data is transferred to the transmitting FIFO faster than the previous data can be sent out, i.e., if you execute the BslSerialTransmit command too fast. Data sent during an overflow will not be written to the transmitting FIFO.
  • BslSerialTxBreak: Signals a serial break to the external device. If this parameter is set to true, the camera sets the serial output to low level (space) to signal a break. If this parameter is set to false, the camera resets the serial output to high (mark).

Receive Parameters#

The following parameters are involved in receiving data:

  • BslSerialReceive: Execute this command to receive data via the serial input line. After the transaction is completed, the BslSerialTransferBuffer parameter contains the received data, and the BslSerialTransferLength parameter indicates the number of valid symbols received. Also, executing the command updates the state of the BslSerialRxFifoOverflow, BslSerialRxParityError, and BslSerialRxStopBitError parameters. See below.
  • BslSerialRxFifoOverflow: Indicates whether the receiving FIFO has overflown. An overflow occurs if new data from the external device arrives faster than the previous data can be moved to the transfer buffer and sent to the host, i.e., if you execute the BslSerialReceive command too slowly. Data received during an overflow will be lost.
  • BslSerialRxParityError: Indicates whether the camera has detected a parity error in the data of the receiving FIFO. If an error is detected, the parameter remains true until you empty the receiving FIFO by executing the BslSerialReceive command.
  • BslSerialRxStopBitError: Indicates whether the camera has detected a stop bit error in the data of the receiving FIFO. If an error is detected, the parameter remains true until you empty the receiving FIFO by executing the BslSerialReceive command.
  • BslSerialRxBreak: Indicates whether the external device has signaled a serial break. If the serial input is low (space) for at least 12 bit periods, the camera detects a break and sets the parameter to true. Because the camera doesn't "know" how long the break signal will be, the parameter value will remain true. To reset it to false, make sure the external device has finished sending the break, then execute the BslSerialRxBreakReset command.
  • BslSerialRxBreakReset: Sets the BslSerialRxBreak parameter to false. See above.

Sample Code#

// Configure serial communication
// Example: 19200 Baud, 8 data bits, 2 stop bits, even parity
camera.BslSerialBaudRate.SetValue(BslSerialBaudRate_Baud19200);
camera.BslSerialNumberOfDataBits.SetValue(BslSerialNumberOfDataBits_Bits8);
camera.BslSerialNumberOfStopBits.SetValue(BslSerialNumberOfStopBits_Bits2);
camera.BslSerialParity.SetValue(BslSerialParity_Even);
// Configure the camera's input signal
camera.BslSerialRxSource.SetValue(BslSerialRxSource_Line2);
// Configure the camera's output signal
camera.LineSelector.SetValue(LineSelector_Line3);
camera.LineSource.SetValue(LineSource_SerialTx);
// Now, you must implement a suitable communication protocol.
// Camera parameters that help you implement the protocol are listed
// in the "Transmitting and Receiving Data" section above.
INodeMap& nodemap = camera.GetNodeMap();
// Configure serial communication
// Example: 19200 Baud, 8 data bits, 2 stop bits, even parity
CEnumParameter(nodemap, "BslSerialBaudRate").SetValue("Baud19200");
CEnumParameter(nodemap, "BslSerialNumberOfDataBits").SetValue("Bits8");
CEnumParameter(nodemap, "BslSerialNumberOfStopBits").SetValue("Bits2");
CEnumParameter(nodemap, "BslSerialParity").SetValue("Even");
// Configure the camera's input signal
CEnumParameter(nodemap, "BslSerialRxSource").SetValue("Line2");
// Configure the camera's output signal
CEnumParameter(nodemap, "LineSelector").SetValue("Line3");
CEnumParameter(nodemap, "LineSource").SetValue("SerialTx");
// Now, you must implement a suitable communication protocol.
// Camera parameters that help you implement the protocol are listed
// in the "Transmitting and Receiving Data" section above.
// Configure serial communication
// Example: 19200 Baud, 8 data bits, 2 stop bits, even parity
camera.Parameters[PLCamera.BslSerialBaudRate].SetValue(PLCamera.BslSerialBaudRate.Baud19200);
camera.Parameters[PLCamera.BslSerialNumberOfDataBits].SetValue(PLCamera.BslSerialNumberOfDataBits.Bits8);
camera.Parameters[PLCamera.BslSerialNumberOfStopBits].SetValue(PLCamera.BslSerialNumberOfStopBits.Bits2);
camera.Parameters[PLCamera.BslSerialParity].SetValue(PLCamera.BslSerialParity.Even);
// Configure the camera's input signal
camera.Parameters[PLCamera.BslSerialRxSource].SetValue(PLCamera.BslSerialRxSource.Line2);
// Configure the camera's output signal
camera.Parameters[PLCamera.LineSelector].SetValue(PLCamera.LineSelector.Line3);
camera.Parameters[PLCamera.LineSource].SetValue(PLCamera.LineSource.SerialTx);
// Now, you must implement a suitable communication protocol.
// Camera parameters that help you implement the protocol are listed
// in the "Transmitting and Receiving Data" section above.
/* Macro to check for errors */
#define CHECK(errc) if (GENAPI_E_OK != errc) printErrorAndExit(errc)
GENAPIC_RESULT errRes = GENAPI_E_OK;  /* Return value of pylon methods */
/* Configure serial communication */
/* Example: 19200 Baud, 8 data bits, 2 stop bits, even parity */
errRes = PylonDeviceFeatureFromString(hdev, "BslSerialBaudRate", "Baud19200");
CHECK(errRes);
errRes = PylonDeviceFeatureFromString(hdev, "BslSerialNumberOfDataBits", "Bits8");
CHECK(errRes);
errRes = PylonDeviceFeatureFromString(hdev, "BslSerialNumberOfStopBits", "Bits2");
CHECK(errRes);
errRes = PylonDeviceFeatureFromString(hdev, "BslSerialParity", "Even");
CHECK(errRes);
/* Configure the camera's input signal */
errRes = PylonDeviceFeatureFromString(hdev, "BslSerialRxSource", "Line2");
CHECK(errRes);
/* Configure the camera's output signal */
errRes = PylonDeviceFeatureFromString(hdev, "LineSelector", "Line3");
CHECK(errRes);
errRes = PylonDeviceFeatureFromString(hdev, "LineSource", "SerialTx");
CHECK(errRes);
/* Now, you must implement a suitable communication protocol. */
/* Camera parameters that help you implement the protocol are listed */
/* in the "Transmitting and Receiving Data" section above. */
# Configure serial communication
# Example: 19200 Baud, 8 data bits, 2 stop bits, even parity
camera.BslSerialBaudRate.Value = "Baud19200"
camera.BslSerialNumberOfDataBits.Value = "Bits8"
camera.BslSerialNumberOfStopBits.Value = "Bits2"
camera.BslSerialParity.Value = "Even"
# Configure the camera's input signal
camera.BslSerialRxSource.Value = "Line2"
# Configure the camera's output signal
camera.LineSelector.Value = "Line3"
camera.LineSource.Value = "SerialTx"
# Now, you must implement a suitable communication protocol.
# Camera parameters that help you implement the protocol are listed
# in the "Transmitting and Receiving Data" section above.

You can also use the pylon Viewer to easily set the parameters.