Serial Communication#
これは、カメラがホストと別のデバイス間の中間UARTデバイスとして機能することを意味します。
情報
The Serial Communication feature is only available on the following Basler camera models: ace 2 R GigE PRO (only 1GigE), ace 2 R USB PRO, dart M, and boost R cameras.
機能を使用する#
仕組み#
カメラには、送信(Tx)データ用と受信(Rx)データ用の2つの独立したシリアルポートFIFOがあります。ホストとの通信には、両方のFIFOが共通の転送バッファーを使用します。
上記のインターフェイスを使用するには、適切な通信プロトコルを実装する必要があります。プロトコルの実際の実装は、セットアップユーティリティとデバイスの特性によって異なります。
プロトコルの実装に役立つカメラパラメーターを以下に示します。
Serial Communicationの設定#
カメラと外部デバイス間のシリアル通信を設定するには、次の手順を実行します:
- パラメーターを
BslSerialBaudRateparameter to the baud rate of the external device, e.g.,Baud9600.
情報
If you use the opto-coupled I/O line for incoming (Rx) data, be aware that the maximum baud rate is limited to 19200 Bd. If you use the opto-coupled I/O line, set the BslSerialBaudRate parameter accordingly.
- パラメーターを
BslSerialNumberOfDataBitsparameter to the number of data bits used by the external device, e.g.,Bits8. - パラメーターを
BslSerialNumberOfStopBitsparameter to the number of stop bits used by the external device, e.g.,Bits1. - パラメーターを
BslSerialParityparameter to the kind of parity check performed by the external device, e.g.,Even. - Configure the camera's input signal. To do so, set the
BslSerialRxSourceparameter to the I/O line that is to receive serial data, e.g.,Line2. The line must be configured as input. - パラメーターを
BslSerialTransmitModeparameter toHalfDuplexまたはFullDuplex. TheBslSerialTransmitModeparameter and its values are described in the Transmit Parameters section. - カメラの出力信号を設定します:
- パラメーターを
LineSelectorparameter to the I/O line that is to transmit serial data, e.g.,Line3. The line must be configured as output. - パラメーターを
LineSourceparameter toSerialTx.
- パラメーターを
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.
これによりループバックが発生します。シリアル入力は内部的にシリアル出力に接続されるため、カメラは伝送内容を正確に受信します。
データの送受信#
シリアル通信を設定した後、外部デバイスにデータを送信して、外部デバイスからデータを受信することができます。
情報
詳細については、「pylon APIドキュメント」のParametrizeCamera_SerialCommunication (C++)コードサンプルを参照してください。
Transmit and Receive Parameters#
次のパラメーターは、データの送受信の両方に関係します:
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 theBslSerialNumberOfDataBitssetting. 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 theBslSerialTransferLengthparameter 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#
データの送信には、次のパラメーターが関係します:
BslSerialTransmitMode: This parameter determines whether the receiving FIFO (Rx) of the camera is switched off or on during transmissions from the camera to an external device. If a single I/O line was shared for transmitting and receiving data (half-duplex), the receiving FIFO (Rx) of the camera would also receive the data that is transmitted to the external device. This would fill the receiving FIFO (Rx) very fast.
パラメーターをBslSerialTransmitModeparameter toHalfDuplexto switch off the receiving FIFO (Rx) during transmissions from the camera to an external device. This way, only data transmitted by the external device will be copied into the receiving FIFO (Rx) of the camera.
If you work with two separate I/O lines, you can set theBslSerialTransmitModeparameter toFullDuplex.BslSerialTransmit: Execute this command to transmit the current value of the transfer buffer via the serial output line. This also updates the state of theBslSerialTxFifoEmptyandBslSerialTxFifoOverflowparameters.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 theBslSerialTransmitcommand 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 totrue, the camera sets the serial output to low level (space) to signal a break. If this parameter is set tofalse, the camera resets the serial output to high (mark).
Receive Parameters#
データの受信には、次のパラメーターが関係します:
BslSerialReceive: Execute this command to receive data via the serial input line. After the transaction is completed, theBslSerialTransferBufferparameter contains the received data, and theBslSerialTransferLengthparameter indicates the number of valid symbols received. Also, executing the command updates the state of theBslSerialRxFifoOverflow,BslSerialRxParityError, andBslSerialRxStopBitErrorparameters. 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 theBslSerialReceivecommand 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 remainstrueuntil you empty the receiving FIFO by executing theBslSerialReceivecommand.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 remainstrueuntil you empty the receiving FIFO by executing theBslSerialReceivecommand.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 totrue. Because the camera doesn't "know" how long the break signal will be, the parameter value will remaintrue. To reset it tofalse, make sure the external device has finished sending the break, then execute theBslSerialRxBreakResetcommand.BslSerialRxBreakReset: Sets theBslSerialRxBreakparameter tofalse. See above.
サンプルコード#
// 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.
pylon Viewerを使用して、パラメーターを簡単に設定することもできます。