コンテンツにスキップ

Two-Wire Interface#

Two-Wire Interfaceカメラ機能を使用すると、2線式インターフェース(TWI)バスを介して、カメラと1つまたは複数の外部デバイスの間でデータを転送できます。

例えば、カメラを使用して、TWI対応レンズのフォーカスを制御できます。

機能を使用する#

仕組み#

TWIバスは2線式バスで、1本のシリアルデータライン(SDA)と1本のシリアルクロックライン(SCL)で構成されています。これらは双方向ラインです。

カメラ(マスター)と外部デバイス(スレーブ)は、データラインとクロックラインの両方に接続されています。データは、データラインを介してカメラにより送信、または要求、取得されます。クロックラインはクロック信号の送信に使用され、カメラによって制御されます。

Two-Wire Interface図

上記のTWIインターフェースを使用するには、カメラのGenICamパラメーターがスレーブデバイスの仕様に準拠している必要があります。

適切な通信プロトコルの実装に役立つカメラパラメーターを以下に示します。

TWI通信の設定#

カメラと外部デバイスの間のTWI通信を設定するには、次の手順を実行します。

  1. BslTwiBitrateパラメーターを、TWIで使用するビットレート(50kbpsなど)に設定します。
  2. カメラの入出力信号を設定します。
    1. LineSelectorパラメーターは、シリアルデータを書き込みおよび読み取りするI/Oライン(Line2など)に設定します。このラインは入出力ラインとして設定する必要があります。
    2. Set the BslLineConnection parameter to TwiSda.
    3. LineSelectorパラメーターを、クロック信号の送信に使用するI/Oライン(Line3など)に設定します。このラインは入出力ラインとして設定する必要があります。
    4. BslLineConnectionパラメーターをTwiSclに設定します。

データの書き込みと読み取り#

TWI通信を設定した後は、外部デバイスへのデータの書き込みと読み取りが可能です。

パラメーターの書き込みと読み取り#

次のパラメーターが、データの書き込みと読み取りの両方に関係します。

  • BslTwiTransferBuffer:転送バッファーには、書き込まれるデータが保持され、読み取られたデータも格納されます。最大16バイトを保持できます。
  • BslTwiTransferLength:転送バッファーとの間で送受信されるバイト数を示します。書き込み時は、転送長により、トランザクションごとにカメラが送信するバイト数を指定します。読み取り時は、最後のトランザクション中にカメラが受信したバイト数が指定されます。最大値は16です。
  • BslTwiTargetAddress:外部スレーブデバイスの7ビットターゲットアドレスを示します。

次のパラメーターがデータの書き込みに関係します。

  • BslTwiWrite:転送バッファーからスレーブデバイスのターゲットアドレスに、転送長によって指定されたバイト数を書き込むには、このコマンドを実行します。

次のパラメーターがデータの読み取りに関係します。

  • BslTwiRead:スレーブデバイスのターゲットアドレスからのデータの読み取りまたは取得には、このコマンドを実行します。読み取られたバイト数は、転送長によって指定されます。

転送ステータス#

転送ステータスは、データ転送の現在のステータスを示します。転送が正常に完了すると、転送ステータスは[成功]になります。現在の転送ステータスを取得するには、BslTwiUpdateTransferStatusコマンドを実行して転送ステータスを更新してから、BslTwiTransferStatusの値を取得します。

BslTwiTransferStatusの値が[保留]の場合は、転送ステータスが[成功]になるまで、転送ステータスを繰り返し更新して読み取る必要があります。新しいデータは、転送ステータスが[成功]の場合にのみ、書き込みや読み取りが可能です。

転送ステータスには、次の値があります。

  • 成功:最後のデータ転送が成功しました。
  • 保留:データ転送は保留中です。
  • 否定応答アドレス:最後の書き込みまたは読み取りコマンドの後に、ターゲットアドレスを確認する肯定応答ビットをカメラが受信しませんでした。この場合、データ転送は失敗しています。
  • 否定応答データ:最後の書き込みコマンドの後に、データ転送成功の肯定応答ビットをカメラが受信しませんでした。この場合、データ転送は失敗しています。

I/Oラインを低くする#

一部のTWIスレーブデバイスでは、動作を開始する前にI/Oラインを低くする必要があります。I/Oラインを低くする必要がある場合は、BslTwiPullSdaLowパラメーターかBslTwiPullSclLowパラメーター、またはその両方をtrueに設定します。いずれかがtrueである間は、データ転送が無効になります。

サンプルコード#

// Configure TWI communication
// Set the bit rate to 50 kbps
camera.BslTwiBitrate.SetValue(BslTwiBitrate_Bitrate50kbps);
// Set line 2 to input-output and use it for TWI SDA
camera.LineSelector.SetValue(LineSelector_Line2);
camera.LineMode.SetValue(LineMode_InOut);
camera.BslLineConnection.SetValue(BslLineConnection_TwiSda);
// Set line 3 to input-output and use it for TWI SCL
camera.LineSelector.SetValue(LineSelector_Line3);
camera.LineMode.SetValue(LineMode_InOut);
camera.BslLineConnection.SetValue(BslLineConnection_TwiScl);
// Now, you must implement a suitable communication protocol.
// Camera parameters that help you implement the protocol are listed
// in the "Writing and Reading and Data" section above.
INodeMap& nodemap = camera.GetNodeMap();
// Configure TWI communication
// Set the bit rate to 50 kbps
CEnumParameter(nodemap, "BslTwiBitrate").SetValue("Bitrate50kbps");
// Set line 2 to input-output and use it for TWI SDA
CEnumParameter(nodemap, "LineSelector").SetValue("Line2");
CEnumParameter(nodemap, "LineMode").SetValue("InOut");
CEnumParameter(nodemap, "BslLineConnection").SetValue("TwiSda");
// Set line 3 to input-output and use it for TWI SCL
CEnumParameter(nodemap, "LineSelector").SetValue("Line3");
CEnumParameter(nodemap, "LineMode").SetValue("InOut");
CEnumParameter(nodemap, "BslLineConnection").SetValue("TwiScl");
// Now, you must implement a suitable communication protocol.
// Camera parameters that help you implement the protocol are listed
// in the "Writing and Reading and Data" section above.
// Configure TWI communication
// Set the bit rate to 50 kbps
camera.Parameters[PLCamera.BslTwiBitrate].SetValue(PLCamera.BslTwiBitrate.Bitrate50kbps);
// Set line 2 to input-output and use it for TWI SDA
camera.Parameters[PLCamera.LineSelector].SetValue(PLCamera.LineSelector.Line2);
camera.Parameters[PLCamera.LineMode].SetValue(PLCamera.LineMode.InOut);
camera.Parameters[PLCamera.BslLineConnection].SetValue(PLCamera.BslLineConnection.TwiSda);
// Set line 3 to input-output and use it for TWI SCL
camera.Parameters[PLCamera.LineSelector].SetValue(PLCamera.LineSelector.Line3);
camera.Parameters[PLCamera.LineMode].SetValue(PLCamera.LineMode.InOut);
camera.Parameters[PLCamera.BslLineConnection].SetValue(PLCamera.BslLineConnection.TwiScl);
// Now, you must implement a suitable communication protocol.
// Camera parameters that help you implement the protocol are listed
// in the "Writing and Reading and 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 TWI communication */
/* Set the bit rate to 50 kbps */
errRes = PylonDeviceFeatureFromString(hdev, "BslTwiBitrate", "Bitrate50kbps");
CHECK(errRes);
/* Set line 2 to input-output and use it for TWI SDA */
errRes = PylonDeviceFeatureFromString(hdev, "LineSelector", "Line2");
CHECK(errRes);
errRes = PylonDeviceFeatureFromString(hdev, "LineMode", "InOut");
CHECK(errRes);
errRes = PylonDeviceFeatureFromString(hdev, "BslLineConnection", "TwiSda");
CHECK(errRes);
/* Set line 3 to input-output and use it for TWI SCL */
errRes = PylonDeviceFeatureFromString(hdev, "LineSelector", "Line3");
CHECK(errRes);
errRes = PylonDeviceFeatureFromString(hdev, "LineMode", "InOut");
CHECK(errRes);
errRes = PylonDeviceFeatureFromString(hdev, "BslLineConnection", "TwiScl");
CHECK(errRes);
/* Now, you must implement a suitable communication protocol. */
/* Camera parameters that help you implement the protocol are listed */
/* in the "Writing and Reading and Data" section above. */

pylon Viewerを使用して、パラメーターを簡単に設定することもできます。