/* モータ制御プログラム Ver.1.0c <Position Sendコマンド送信例0> */ #include #include #include #include "rs.h" // シリアルポート制御クラス crs232c char a[25]; // シリアル送受信データバッファ crs232c rscom(1); // crs232cオブジェクトrscom(ポート番号) void pos_send(int i, int t, int d); // position send コマンドの処理 // i-id, t-mode, d-data int main(void) { int d; // 変数 while(d!=0){ printf("Moter data 1-255(0-END)=>"); // 表示 scanf("%d",&d); // データ入力 pos_send(0,4,d); } getch(); rscom.close(); // シリアルポート閉じる return 0; } void pos_send(int i, int t, int d) // position send コマンドの処理 { // i-id, t-mode, d-data int j; // Position Sendコマンド計算 a[0]=(char) 0xff; // Header a[1]=(char) (((t & 0x07) * 32 ) + (i & 0x1f)); // Data1 a[2]=(char) (d & 254); // Data2 a[3]=(char) ((a[1]^a[2]) & 0x7f); // Check Sum printf("Send: %x %x %x\n",a[1] & 0x0ff,a[2] & 0x0ff,a[3]); // 送信コマンド確認 rscom.putch(a[0]); // コマンド送信 rscom.putch(a[1]); rscom.putch(a[2]); rscom.putch(a[3]); d=0; // 受信待機ルーチン while (d<2){ j=rscom.getInque(); if (j>0){ for (i=d;i