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

Visual C#

オブジェクト

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

変数

ushort id;

オープン

int result;

id = Convert.ToUInt16(Id.Text);
result = Pmcm.Open( id, "PMC-M2C-U" );
if( result == Pmcm.PMCM_RESULT_SUCCESS )
{
    MessageBox.Show( "オープン成功", "", MessageBoxButtons.OK, MessageBoxIcon.Information );
}
else
{
    MessageBox.Show( "オープン失敗", "", MessageBoxButtons.OK, MessageBoxIcon.Stop );
}

各種設定

int result;
ushort axis;
string outputString;

axis = Pmcm.PMCM_AXIS_X + Pmcm.PMCM_AXIS_Y;

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

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

動作パラメータ設定

int result;
ushort axis;
Pmcm.MOTIONLINEPMCM motionLine = new Pmcm.MOTIONLINEPMCM();
motionLine.Initialize();
string outputString;

axis = Pmcm.PMCM_AXIS_X + Pmcm.PMCM_AXIS_Y;

motionLine.wStartMode = Pmcm.PMCM_CONST; // 起動モード
motionLine.fSpeedRate = 1; // 速度倍率
motionLine.wAccDecMode = Pmcm.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 = Pmcm.SetMotionLine( id, axis, ref motionLine );
if( result != Pmcm.PMCM_RESULT_SUCCESS ) 
{
    outputString = String.Format( "PmcmSetMotionLine ERROR : 0x{0:X}", result );
    MessageBox.Show( outputString, "", MessageBoxButtons.OK, MessageBoxIcon.Stop );
    return;
}

動作開始

int result;
string outputString;

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

動作停止

int result;
ushort axis;
ushort stopMode;
string outputString;

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

// 停止モード
stopMode = Pmcm.PMCM_IMMEDIATE_STOP;

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

クローズ

bool result;

result = Pmcm.Close( id );