11: 2013-09-19 (木) 17:35:58 yoshida ソース 12: 2013-09-19 (木) 17:41:00 yoshida ソース
Line 87: Line 87:
***Dynamixel Library [#x91df052] ***Dynamixel Library [#x91df052]
-Dynamixelシリーズを接続していた場合[[Dynamixel Library>DXLIB2]]を使用して簡単にユーザアプリケーションを作成することが可能です。 +接続されたDynamixelシリーズを操作するにはユーザアプリケーションが必要になります。~ 
- +ユーザアプリケーションは[[Dynamixel Library>DXLIB2]]を使用することで、簡単に作成することが可能です。
-****サンプルプログラム [#ccd4be79] +
-ライブラリが用意されていない場合は電文作成と電文解析を行う必要があります。以下はDynamixelシリーズへPINGを行った際の電文作成と電文解析のサンプルとなります。 +
-#html{{ +
-<pre class="brush:c"> +
-#include <winsock2.h> +
-#include <windows.h> +
-#include <stdio.h> +
-#include <stdint.h> +
-#include <stdbool.h> +
- +
-#define COMPORT  "\\\\.\\COM6" // 環境に合わせて変更して下さい +
-#define BAUDRATE  (1000000) +
-#define TIMEOUT  (1000) +
-#define TARGETID  (2)          // DynamixelのID +
- +
-void main (void) { +
-  HANDLE hd; +
-  COMMTIMEOUTS  timeouts = { 0, 0, TIMEOUT, 0, 0 }; +
-  DCB          cDcb; +
-  COMSTAT      comStat; +
-  DWORD        dwErrors; +
-  uint8_t      buf[10]; +
-  uint32_t      wlen, len, rlen; +
-  int          i, cksum; +
-  // 通信の設定 +
-  memset (&cDcb,0,sizeof(cDcb)); +
-  cDcb.BaudRate          = BAUDRATE; +
-  cDcb.ByteSize          = 8; +
-  cDcb.fParity            = false; +
-  cDcb.Parity            = NOPARITY; +
-  cDcb.StopBits          = ONESTOPBIT; +
-  cDcb.fOutX              = false; +
-  cDcb.fInX              = false; +
-  cDcb.fTXContinueOnXoff  = true; +
-  cDcb.XonLim            = 512; +
-  cDcb.XoffLim            = 512; +
-  cDcb.XonChar            = 0x11; +
-  cDcb.XoffChar          = 0x13; +
-  cDcb.fOutxDsrFlow      = false; +
-  cDcb.fOutxCtsFlow      = false; +
-  cDcb.fRtsControl        = RTS_CONTROL_DISABLE; +
-  cDcb.fDtrControl        = DTR_CONTROL_ENABLE; +
-  cDcb.fErrorChar        = 0; +
-  cDcb.fBinary            = true; +
-  cDcb.fNull              = 0; +
-  cDcb.fAbortOnError      = false; +
-  cDcb.wReserved          = 0; +
-  cDcb.EofChar            = 0x03; +
-  cDcb.EvtChar            = 0; +
-  if ((hd = CreateFileA (COMPORT, (GENERIC_READ | GENERIC_WRITE), 0, NULL, OPEN_EXISTING, 0, NULL)) != INVALID_HANDLE_VALUE) { +
-   if ((SetCommMask (hd, 0) != 0) && SetCommState (hd, &cDcb) != 0) { +
-     PurgeComm (hd, (PURGE_TXCLEAR | PURGE_RXCLEAR)); +
-     // 機器に合った送信データの作成を記述 +
-     // テスト用にDynamixelシリーズへのPINGパケット作成 +
-     buf[0] = buf[1] = 0xff; +
-     buf[2] = cksum = TARGETID; +
-     buf[3] = 0x2; +
-     buf[4] = 0x1; +
-     cksum += (buf[3] + buf[4]); +
-     buf[5] = (uint8_t)(~(cksum) & 0xff); +
-     len = 6; +
-     // 送信処理 +
-     ClearCommError (hd, &dwErrors, &comStat); +
-     PurgeComm (hd, (PURGE_RXCLEAR)); +
-     if (WriteFile (hd, buf, len, (LPDWORD)&wlen, NULL)) { +
-       // 受信処理 +
-       SetCommTimeouts (hd, &timeouts); +
-       if (ReadFile (hd, buf, len, (LPDWORD)&rlen, NULL)) { +
-         // 電文解析処理を記述 +
-         // テスト用にDynamixelシリーズのPINGステータスを解析 +
-         for (i = 2, cksum = 0; i < rlen - 1; i++) cksum += buf[i]; +
-         if (buf[0] == 0xff && buf[1] == 0xff && buf[2] == TARGETID && buf[3] == 0x2 && buf[5] == ((~cksum) & 0xff)) { +
-           printf ("%d is Alive.\n", TARGETID); +
-         } else printf ("check failed\n"); +
-       } else printf ("read failed\n"); +
-     } else printf ("write failed\n"); +
-   } else printf ("comm failed\n"); +
-   PurgeComm (hd, (PURGE_TXABORT | PURGE_RXABORT | PURGE_TXCLEAR | PURGE_RXCLEAR)); +
-   CloseHandle (hd); +
-  } +
-+
-</pre> +
-}}+
**デバイスドライバ [#xd623de9] **デバイスドライバ [#xd623de9]


トップ   差分 リロード印刷に適した表示   全ページ一覧 単語検索 最新ページの一覧   最新ページのRSS 1.0 最新ページのRSS 2.0 最新ページのRSS Atom