メインコンテンツまでスキップ

S810-MX-ADL1N からの移行ガイド(CAN/CAN FD)

本ページは、S810-MX-ADL1N(旧)から S810-MX-ADL2N(新)へ移行する際の実装差分を、既存コードの置換観点で整理したガイドです。
対象は CAN/CAN FD です。

関連リンク

移行の全体像

ADL1N から ADL2N の移行で、実装に影響するポイントは次の5点です。

  1. DLL名の変更(MPXCANFDCtrlFree* -> MPXCtrlFree*
  2. MPXOpen の引数変更(Num 追加)
  3. CAN API名の変更(MPXSetCANParam など -> MPXCAN*
  4. 一部定数名の変更(MPX_MODE_*CAN_ERR*
  5. MPXGetLog の引数型変更(StMPXCANLog** -> StMPXLog**

先に確認する移行前提

  • 旧DLL: MPXCANFDCtrlFree.DLL / MPXCANFDCtrlFree_x64.DLL
  • 新DLL: MPXCtrlFree.DLL / MPXCtrlFree_x64.DLL
  • InnerCh は従来どおり対象CHを指定(1または2)

API仕様差分(旧->新)

共通API

ADL1NADL2N互換性影響
MPXGetAPIVersion(StMPXAPIVersion*)同じ変更なし
MPXOpen(StMPXDeviceInfo* Devices, unsigned char* Count)MPXOpen(StMPXDeviceInfo* Devices, unsigned char Num, unsigned char* Count)Num 引数追加
MPXClose()同じ変更なし
MPXSetLED(...)同じ変更なし
MPXGetStatus(...)同じ変更なし
MPXMonitorStart(...)同じ変更なし
MPXMonitorStop(...)同じ変更なし
MPXGetTimeStamp(...)同じ変更なし
MPXSetLogCallBack(...)同じ変更なし
MPXSetGetLogMode(...)同じ変更なし
MPXGetLog(unsigned long, unsigned char, StMPXCANLog**, unsigned short*, unsigned char*)MPXGetLog(unsigned long, unsigned char, StMPXLog**, unsigned short*, unsigned char*)第3引数型変更

CAN/CAN FD API

ADL1NADL2N互換性影響
MPXSetCANParamMPXCANSetParamAPI名変更
MPXGetLogExMPXCANGetLogExAPI名変更
MPXSetSlotMPXCANSetSlotAPI名変更
MPXChangeSlotMPXCANChangeSlotAPI名変更
MPXSendSlotMPXCANSendSlotAPI名変更
MPXDirectSendMPXCANDirectSendAPI名変更

定数・構造体の移行ポイント

動作モード定数(名称変更)

ADL1NADL2N
MPX_MODE_LISTENMPX_CAN_MODE_LISTEN0
MPX_MODE_MONITORMPX_CAN_MODE_MONITOR1
MPX_MODE_CAN_SIMMPX_CAN_MODE_SIM2
MPX_MODE_NONEMPX_CAN_MODE_NONE0xFF

値は同じですが、旧定数名は ADL2N ヘッダに存在しません。

CANエラー定数(名称変更)

エラーフラグ

ADL1NADL2N
CAN_ERRFLG_FALSEMPX_CAN_ERRFLG_FALSE0
CAN_ERRFLG_TRUEMPX_CAN_ERRFLG_TRUE1

エラー詳細

ADL1NADL2N
CAN_ERR_NONEMPX_CAN_ERR_NONE0x0000
CAN_ERR_BUSMPX_CAN_ERR_BUS0x0001
CAN_ERR_WARNMPX_CAN_ERR_WARN0x0002
CAN_ERR_PASVMPX_CAN_ERR_PASV0x0004
CAN_ERR_BUSOFFMPX_CAN_ERR_BUSOFF0x0008
CAN_ERR_BUSWAKEMPX_CAN_ERR_BUSWAKE0x0010
CAN_ERR_OVERLOADMPX_CAN_ERR_OVERLOAD0x0020
CAN_ERR_BUSLOCKMPX_CAN_ERR_BUSLOCK0x0040
CAN_ERR_ARBLOSTMPX_CAN_ERR_ARBLOST0x0080
CAN_ERR_STAFFMPX_CAN_ERR_STAFF0x0100
CAN_ERR_FORMMPX_CAN_ERR_FORM0x0200
CAN_ERR_ACKMPX_CAN_ERR_ACK0x0400
CAN_ERR_CRCMPX_CAN_ERR_CRC0x0800
CAN_ERR_RECEIVEMPX_CAN_ERR_RECEIVE0x1000
CAN_ERR_DOMINANTMPX_CAN_ERR_DOMINANT0x2000
CAN_ERR_DELIMITERMPX_CAN_ERR_DELIMITER0x4000

変更なしの主要定数

以下は ADL1N と ADL2N で同一定義です。

  • MPX_CAN_PARAM_ABR_*
  • MPX_CAN_PARAM_SP_*
  • MPX_CAN_PARAM_DBR_*
  • MPX_CAN_FRAME_TYPE_*
  • MPX_CAN_SLOT_*
  • MPX_CAN_PROTOCOL_*
  • MPX_CAN_BRS_*
  • MPX_CAN_IDE_*
  • MPX_CAN_RTR_*
  • MPX_CAN_SIM_INC_*

CAN構造体の互換性

CAN関連構造体は ADL1N と ADL2N で互換です(名称・レイアウトとも同一)。

  • StMPXCANParam
  • StMPXCANID
  • StMPXCANFrameOption
  • StMPXCANFrameType
  • StMPXCANFrame
  • StMPXCANSlot
  • StMPXCANDirect
  • StMPXCANLog

MPXGetLog の型変更

MPXGetLog は関数名が同じでも、受け取り型が変わっています。

  • ADL1N: StMPXCANLog**
  • ADL2N: StMPXLog**

移行時は次のいずれかで対応してください。

  1. MPXCANGetLogEx へ統一する(推奨)
  2. MPXGetLog を継続利用し、StMPXLog から Misc.CAN を参照する

戻り値(ER)差分

ERコードは ADL1N と ADL2N で同一です。

定数
E_OK0
E_PARAM1
E_DEVICE2
E_COMM3
E_TGT4
E_TRG_BUSY11
E_DCT_FULL12
E_STATUS105
E_TIMEOUT202
E_OTHER255

実装手順(既存アプリ置換フロー)

  1. DLL参照名を MPXCANFDCtrlFree* から MPXCtrlFree* へ変更
  2. MPXOpen 呼び出しを3引数版へ修正
  3. CAN API名を MPXCAN* へ置換
  4. MPX_MODE_*CAN_ERR* を新定数へ置換
  5. ログ取得を MPXCANGetLogEx 中心に統一(または MPXGetLog 型変更対応)

言語別 置換例

C/C++ 置換例

// ADL1N
StMPXDeviceInfo devs[8] = {};
unsigned char count = 0;
ER er = MPXOpen(devs, &count);
unsigned long serial = (count > 0) ? devs[0].Serial : 0;
er = MPXSetCANParam(serial, innerCh, &param);
er = MPXGetLogEx(serial, innerCh, logs, num, &got, &over);

// ADL2N
StMPXDeviceInfo devs[8] = {};
unsigned char count = 0;
ER er = MPXOpen(devs, 8, &count);
unsigned long serial = (count > 0) ? devs[0].Serial : 0;
er = MPXCANSetParam(serial, innerCh, &param);
er = MPXCANGetLogEx(serial, innerCh, logs, num, &got, &over);

C/C++ CAN/CAN FDシミュレーション置換例

// ADL1N
param.Mode = MPX_MODE_CAN_SIM;
MPXSetCANParam(serial, innerCh, &param);
MPXSetSlot(serial, innerCh, slots, 2);
MPXMonitorStart(serial, MPX_SYNC_MASTER);

// ADL2N
param.Mode = MPX_CAN_MODE_SIM;
MPXCANSetParam(serial, innerCh, &param);
MPXCANSetSlot(serial, innerCh, slots, 2);
MPXMonitorStart(serial, MPX_SYNC_MASTER);

C#(P/Invoke)置換例

[DllImport("MPXCANFDCtrlFree.dll", EntryPoint = "MPXOpen", CallingConvention = CallingConvention.StdCall)]
public static extern int MPXOpen_Adl1n(
[In, Out] StMPXDeviceInfo[] devices,
ref byte count);

[DllImport("MPXCtrlFree.dll", CallingConvention = CallingConvention.StdCall)]
public static extern int MPXOpen(
[In, Out] StMPXDeviceInfo[] devices,
byte num,
ref byte count);

[DllImport("MPXCANFDCtrlFree.dll", EntryPoint = "MPXSetCANParam", CallingConvention = CallingConvention.StdCall)]
public static extern int MPXSetCANParam(uint serial, byte innerCh, ref StMPXCANParam param);

[DllImport("MPXCtrlFree.dll", CallingConvention = CallingConvention.StdCall)]
public static extern int MPXCANSetParam(uint serial, byte innerCh, ref StMPXCANParam param);

[DllImport("MPXCANFDCtrlFree.dll", EntryPoint = "MPXGetLogEx", CallingConvention = CallingConvention.StdCall)]
public static extern int MPXGetLogEx(uint serial, byte innerCh, [In, Out] StMPXCANLog[] log, ushort num, ref ushort count, ref byte over);

[DllImport("MPXCtrlFree.dll", CallingConvention = CallingConvention.StdCall)]
public static extern int MPXCANGetLogEx(uint serial, byte innerCh, [In, Out] StMPXCANLog[] log, ushort num, ref ushort count, ref byte over);

C#(P/Invoke)CAN/CAN FDシミュレーション置換例

// ADL1N
param.Mode = MPX_MODE_CAN_SIM;
er = MPXSetCANParam(serial, innerCh, ref param);
er = MPXSetSlot(serial, innerCh, slots, (byte)slots.Length);
er = MPXMonitorStart(serial, MPX_SYNC_MASTER);

// ADL2N
param.Mode = MPX_CAN_MODE_SIM;
er = MPXCANSetParam(serial, innerCh, ref param);
er = MPXCANSetSlot(serial, innerCh, slots, (byte)slots.Length);
er = MPXMonitorStart(serial, MPX_SYNC_MASTER);

Excel VBA 置換例(x64)

' ADL1N
Declare PtrSafe Function MPXOpen Lib "MPXCANFDCtrlFree_x64.DLL" (ByRef Devices As StMPXDeviceInfo, ByRef Count As Byte) As Long
Declare PtrSafe Function MPXSetCANParam Lib "MPXCANFDCtrlFree_x64.DLL" (ByVal Serial As Long, ByVal InnerCh As Byte, ByRef Param As StMPXCANParam) As Long
Declare PtrSafe Function MPXGetLogEx Lib "MPXCANFDCtrlFree_x64.DLL" (ByVal Serial As Long, ByVal InnerCh As Byte, ByRef Log As StMPXCANLog, ByVal Num As Integer, ByRef Count As Integer, ByRef BufferOver As Byte) As Long
Declare PtrSafe Function MPXSetSlot Lib "MPXCANFDCtrlFree_x64.DLL" (ByVal Serial As Long, ByVal InnerCh As Byte, ByRef Slots As StMPXCANSlot, ByVal SlotCount As Byte) As Long
Declare PtrSafe Function MPXChangeSlot Lib "MPXCANFDCtrlFree_x64.DLL" (ByVal Serial As Long, ByVal InnerCh As Byte, ByVal SlotNo As Byte, ByVal SlotEnabled As Byte, ByVal ReqInfo As Byte, ByRef Frame As StMPXCANFrame) As Long
Declare PtrSafe Function MPXSendSlot Lib "MPXCANFDCtrlFree_x64.DLL" (ByVal Serial As Long, ByVal InnerCh As Byte, ByVal SlotNo As Byte) As Long
Declare PtrSafe Function MPXDirectSend Lib "MPXCANFDCtrlFree_x64.DLL" (ByVal Serial As Long, ByVal InnerCh As Byte, ByRef Frame As StMPXCANDirect) As Long

' ADL2N
Declare PtrSafe Function MPXOpen Lib "MPXCtrlFree_x64.DLL" (ByRef Devices As StMPXDeviceInfo, ByVal Num As Byte, ByRef Count As Byte) As Long
Declare PtrSafe Function MPXCANSetParam Lib "MPXCtrlFree_x64.DLL" (ByVal Serial As Long, ByVal InnerCh As Byte, ByRef Param As StMPXCANParam) As Long
Declare PtrSafe Function MPXCANGetLogEx Lib "MPXCtrlFree_x64.DLL" (ByVal Serial As Long, ByVal InnerCh As Byte, ByRef Log As StMPXCANLog, ByVal Num As Integer, ByRef Count As Integer, ByRef BufferOver As Byte) As Long
Declare PtrSafe Function MPXCANSetSlot Lib "MPXCtrlFree_x64.DLL" (ByVal Serial As Long, ByVal InnerCh As Byte, ByRef Slots As StMPXCANSlot, ByVal SlotCount As Byte) As Long
Declare PtrSafe Function MPXCANChangeSlot Lib "MPXCtrlFree_x64.DLL" (ByVal Serial As Long, ByVal InnerCh As Byte, ByVal SlotNo As Byte, ByVal SlotEnabled As Byte, ByVal ReqInfo As Byte, ByRef Frame As StMPXCANFrame) As Long
Declare PtrSafe Function MPXCANSendSlot Lib "MPXCtrlFree_x64.DLL" (ByVal Serial As Long, ByVal InnerCh As Byte, ByVal SlotNo As Byte) As Long
Declare PtrSafe Function MPXCANDirectSend Lib "MPXCtrlFree_x64.DLL" (ByVal Serial As Long, ByVal InnerCh As Byte, ByRef Frame As StMPXCANDirect) As Long

Excel VBA CAN/CAN FDシミュレーション置換例

' ADL1N
Param.Mode = MPX_MODE_CAN_SIM
Ret = MPXSetCANParam(Serial, InnerCh, Param)
Ret = MPXSetSlot(Serial, InnerCh, Slots(0), 2)
Ret = MPXMonitorStart(Serial, MPX_SYNC_MASTER)

' ADL2N
Param.Mode = MPX_CAN_MODE_SIM
Ret = MPXCANSetParam(Serial, InnerCh, Param)
Ret = MPXCANSetSlot(Serial, InnerCh, Slots(0), 2)
Ret = MPXMonitorStart(Serial, MPX_SYNC_MASTER)

差分の大きいAPIの置換指針

MPXGetLog 継続利用時の注意

ADL2Nの MPXGetLogStMPXLog** を返します。
CANログへアクセスする場合は Misc.CAN を参照してください。

ログ取得は MPXCANGetLogEx への統一を推奨

既存の MPXGetLogEx 利用コードは、API名置換のみで移行できるため、MPXCANGetLogEx への統一が最も安全です。

移行チェックリスト

  • DLL名を MPXCANFDCtrlFree* から MPXCtrlFree* に変更した
  • MPXOpen を3引数版へ修正した
  • MPXSetCANParam などCAN APIを MPXCAN* へ置換した
  • MPX_MODE_*MPX_CAN_MODE_* へ置換した
  • CAN_ERR* / CAN_ERRFLG_*MPX_CAN_ERR* / MPX_CAN_ERRFLG_* へ置換した
  • MPXGetLogExMPXCANGetLogEx へ置換した
  • MPXGetLog を使う場合は StMPXLog** へ型変更した
  • 置換後に Open/Param/Monitor/Slot/GetLog の基本動作を確認した

関連ページ