Serial Communication#
これは、カメラがホストと別のデバイス間の中間UARTデバイスとして機能することを意味します。
機能を使用する#
仕組み#
カメラには、送信(Tx)データ用と受信(Rx)データ用の2つの独立したシリアルポートFIFOがあります。ホストとの通信には、両方のFIFOが共通の転送バッファーを使用します。
上記のインターフェイスを使用するには、適切な通信プロトコルを実装する必要があります。プロトコルの実際の実装は、セットアップユーティリティとデバイスの特性によって異なります。
プロトコルの実装に役立つカメラパラメーターを以下に示します。
Serial Communicationの設定#
カメラと外部デバイス間のシリアル通信を設定するには、次の手順を実行します:
- パラメーターを
BslSerialBaudRate
parameter to the baud rate of the external device, e.g.,Baud9600
. - パラメーターを
BslSerialNumberOfDataBits
parameter to the number of data bits used by the external device, e.g.,Bits8
. - パラメーターを
BslSerialNumberOfStopBits
parameter to the number of stop bits used by the external device, e.g.,Bits1
. - パラメーターを
BslSerialParity
parameter 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
BslSerialRxSource
parameter to the I/O line that is to receive serial data, e.g.,Line2
. The line must be configured as input. - カメラの出力信号を設定します:
- パラメーターを
LineSelector
parameter to the I/O line that is to transmit serial data, e.g.,Line3
. The line must be configured as output. - パラメーターを
LineSource
parameter 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 theBslSerialNumberOfDataBits
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 theBslSerialTransferLength
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#
データの送信には、次のパラメーターが関係します:
BslSerialTransmit
: Execute this command to transmit the current value of the transfer buffer via the serial output line. This also updates the state of theBslSerialTxFifoEmpty
andBslSerialTxFifoOverflow
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 theBslSerialTransmit
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 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, theBslSerialTransferBuffer
parameter contains the received data, and theBslSerialTransferLength
parameter indicates the number of valid symbols received. Also, executing the command updates the state of theBslSerialRxFifoOverflow
,BslSerialRxParityError
, andBslSerialRxStopBitError
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 theBslSerialReceive
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 remainstrue
until you empty the receiving FIFO by executing theBslSerialReceive
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 remainstrue
until you empty the receiving FIFO by executing theBslSerialReceive
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 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 theBslSerialRxBreakReset
command.BslSerialRxBreakReset
: Sets theBslSerialRxBreak
parameter 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を使用して、パラメーターを簡単に設定することもできます。