static bool bPause = false;
bool posCommandFinished = false;
void StartMotosThreads()
{
Task task0 = Task.Factory.StartNew(()=> {
while (true)
{
if (!bPause)
{
if (!posCommandFinished)
{
posCommandFinished = false;
double targetPos = 5000000;
//-----------------------------------------------------------------
// Create a command value.
//-----------------------------------------------------------------
Motion.PosCommand posCommand = new Motion.PosCommand();
posCommand.Profile.Type = WMX3ApiCLR.ProfileType.SCurve;
posCommand.Axis = 0;
posCommand.Target = targetPos;
posCommand.Profile.Velocity = 100000;
posCommand.Profile.Acc = 1000000;
posCommand.Profile.Dec = 1000000;
//-----------------------------------------------------------------
// Execute command to move from current position to
// specified position.
//-----------------------------------------------------------------
//Wmx3Lib_cm.Motion.StartMov(posCommand);
Wmx3Lib_cm.Motion.StartPos(posCommand);
//-----------------------------------------------------------------
// Wait until the axis moves to the target position and stops.
//-----------------------------------------------------------------
Wmx3Lib_cm.Motion.Wait(0);
double currPos = 0;
Wmx3Lib_cm.AxisControl.GetPosFeedback(0, ref currPos);
if (currPos == targetPos)
{
posCommandFinished = true;
}
System.Threading.Thread.Sleep(2000);
}
}
}
});
}
private void button_PauseMotos_Click(object sender, EventArgs e)
{
if ("暂停" == button_PauseMotos.Text)
{
button_PauseMotos.Text = "恢复";
bPause = true;
Wmx3Lib_cm.Motion.Stop(0);
Logger.Warning("电机暂停...");
}
else
{
button_PauseMotos.Text = "暂停";
bPause = false;
Logger.Warning("电机恢复...");
}
}
最后修改:2021/8/12 10:29:05