MT_SetDioFuncMode

■機能

DIOポートの動作モードを設定します。

■書式

MT_SetDioFuncMode(fd, ucDiMode, ucDoMode)

■引数

fd
[C/C++] int
[Python] ctypes.c_int
MT_Open関数で取得したハンドルを指定してください。
ucDiMode
[C/C++] unsigned char
[Python] ctypes.c_ubyte
外部入力ピンの動作モードを設定します。
  DI_FUNCMODE_GPIO (0x00):     	GPIOモード(default)
  DI_FUNCMODE_PWR_BUTTON (0x10):	Power Button1(外部SW)[モーメンタリ動作用]
    [短押し]:シャットダウン通知、電源ON
    [長押し]:強制電源OFF
  DI_FUNCMODE_PWR_SWITCH (0x20):	Power Button2(外部SW) [オルタネート動作用]
    オープン:電源OFF
    ショート:電源ON
  ※ONからOFFへ移行時にシャットダウンイベントを発行
  
ucDoMode
[C/C++] unsigned char
[Python] ctypes.c_ubyte
外部出力ピンの動作モードを設定します。
  DO_FUNCMODE_GPIO (0x00): 	GPIOモード(default)
  DO_FUNCMODE_WDT_HIGH (0x40):	WDTでHigh出力(デフォルトLow出力)
  DO_FUNCMODE_WDT_LOW (0x50):	WDTでLow出力(デフォルトHigh出力)
  

■戻り値

[C/C++] int
[Python] ctypes.c_int
関数が成功した場合、NO_ERRORが返されます。
関数が失敗した場合、NO_ERROR以外のコードが返されます。
その他のエラー:(参照:エラーコード詳細)

■サンプルプログラム

[C/C++]
  int fd;
  int ret = 0;
  unsigned char difunc=0, dofunc=0;

  if ( (fd = MT_Open(NULL) ) < 0) {
      printf("Faild to open i2c port\n");
      return 1;
  }

  difunc = 0x10;
  dofunc = 0x40;

  printf("Set DIO Func DI:%02X  DO:%02X\n", difunc, dofunc);

  ret = MT_SetDioFuncMode(fd, difunc, dofunc);
  if (ret != 0) {
      printf("MT_SetDioFuncMode error");
  }

  ret = MT_GetDioFuncMode(fd, &difunc, &dofunc);
  if (ret == 0) {
      printf("Get DIO Func DI:%02X  DO:%02X\n", difunc, dofunc);
  }
  else {
      printf("MT_GetDioFuncMode Failled %d\n", ret);
  }

  MT_Close(fd);
  
[Python]
  import ctypes
  import sys
  import mtdll_arm

  fd = mtdll_arm.MT_Open(None);
  if fd < 0:
      print("Faild to open i2c port");
      sys.exit()

  difunc = ctypes.c_ubyte();
  dofunc = ctypes.c_ubyte();

  difunc = 0x10;
  dofunc = 0x40;

  print("Set DIO Func DI:", '{:02x}'.format(difunc), "  DO:", '{:02x}'.format(dofunc));

  ret = MT_SetDioFuncMode(fd, difunc, dofunc);
  if ret != 0:
      print("MT_SetDioFuncMode error");

  ret = mtdll_arm.MT_GetDioFuncMode(fd, difunc, dofunc);
  if ret == 0:
      print("Get DIO Func DI:", '{:02x}'.format(difunc.value), "   DO:", '{:02x}'.format(dofunc.value));
  else:
      print("MT_GetDioFuncMode Failled", '{:d}'.formart(ret));

  mtdll_arm.MT_Close(fd);
  



関数一覧