コンテンツにスキップ
サンプルプログラム > MotionLine >

Visual C++/CLI

オブジェクト

テキストボックス Name
ID番号 idTextBox

変数

unsigned short id;

オープン

int result;

id = Convert::ToUInt16(idTextBox->Text);
result = PmcmOpen(id, "PMC-M2C-U");
if (result == PMCM_RESULT_SUCCESS) {
    MessageBox::Show("オープン成功", "", MessageBoxButtons::OK, MessageBoxIcon::Information);
} else {
    MessageBox::Show("オープン失敗", "", MessageBoxButtons::OK, MessageBoxIcon::Error);
}

各種設定

int result;
unsigned short axis;
String^ messageText;

axis = PMCM_AXIS_X + PMCM_AXIS_Y;

// センサ設定
// オンで検知するセンサを接続している場合や、リミットスイッチを接続していない場合はモーターが動作しません
// その場合は以下の関数を実行してセンサ設定を"オンで検知"に変更してください
//result = PmcmSetSensorConfig(id, axis, PMCM_LOGIC, 0x3F);
//if (result != PMCM_RESULT_SUCCESS) {
//    messageText = String::Format("PmcmSetSensorConfig ERROR : 0x{0:X}", result);
//    MessageBox::Show(messageText, "", MessageBoxButtons::OK, MessageBoxIcon::Error);
//    return;
//}

// パルス出力モード設定
// 使用しているドライバに合致したパルス出力モードを選択してください
result = PmcmSetPulseConfig(id, axis, PMCM_PULSE_OUT, 7);
if (result != PMCM_RESULT_SUCCESS) {
    messageText = String::Format("PmcmSetPulseConfig ERROR : 0x{0:X}", result);
    MessageBox::Show(messageText, "", MessageBoxButtons::OK, MessageBoxIcon::Error);
    return;
}

動作パラメータ設定

int result;
unsigned short axis;
MOTIONLINEPMCM motionLine;
String^ messageText;

axis = PMCM_AXIS_X + PMCM_AXIS_Y;

motionLine.wStartMode = PMCM_CONST; // 起動モード
motionLine.fSpeedRate = 1; // 速度倍率
motionLine.wAccDecMode = PMCM_ACC_LINEAR; // 加減速モード
motionLine.fLowSpeed = 1000; // 起動時速度
motionLine.fSpeed = 1000; // 移動速度
motionLine.wAccTime = 0; // 加速時間
motionLine.wDecTime = 0; // 減速時間
motionLine.fSAccSpeed = 0; // 加速S字区間
motionLine.fSDecSpeed = 0; // 減速S字区間
motionLine.lSlowdown = -1; // スローダウンポイント
motionLine.lStep[0] = 500; // 移動パルス数,移動方向
motionLine.lStep[1] = 1000; // 移動パルス数,移動方向
motionLine.bAbsolute[0] = 0; // 絶対座標指定
motionLine.bAbsolute[1] = 0; // 絶対座標指定
// 動作パラメータ設定
result = PmcmSetMotionLine(id, axis, &motionLine);
if (result != PMCM_RESULT_SUCCESS) {
    messageText = String::Format("PmcmSetMotionLine ERROR : 0x{0:X}", result);
    MessageBox::Show(messageText, "", MessageBoxButtons::OK, MessageBoxIcon::Error);
    return;
} 

動作開始

int result;
String^ messageText;

// 動作開始
result = PmcmStartMotionLine(id);
if (result != PMCM_RESULT_SUCCESS) {
    messageText = String::Format("PmcmStartMotionLine ERROR : 0x{0:X}", result);
    MessageBox::Show(messageText, "", MessageBoxButtons::OK, MessageBoxIcon::Error);
    return;
}

動作停止

int result;
unsigned short axis;
unsigned short stopMode;
String^ messageText;

// 停止させる軸
axis = PMCM_AXIS_X + PMCM_AXIS_Y;

// 停止モード
stopMode = PMCM_IMMEDIATE_STOP;

// 動作停止
result = PmcmStopMotion(id, axis, stopMode);
if (result != PMCM_RESULT_SUCCESS) {
    messageText = String::Format("PmcmStopMotion ERROR : 0x{0:X}", result);
    MessageBox::Show(messageText, "", MessageBoxButtons::OK, MessageBoxIcon::Error);
    return;
}

クローズ

bool result;

result = PmcmClose(id);