84 lines
2.0 KiB
C#
84 lines
2.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace AuroraPLC
|
|
{
|
|
public abstract partial class PLCBase
|
|
{
|
|
// PLC Motor 용 모션 제어 로직들
|
|
|
|
public List<PLCMotorBase> _plcMotorList = new List<PLCMotorBase>();
|
|
public bool HasMotionAxes { get; set; }
|
|
|
|
#region 스레드
|
|
protected bool bThread_Run = false;
|
|
Thread Thread_aLive = null;
|
|
public bool bThreadStop = false;
|
|
|
|
// 기본 60 Hz = 16.667
|
|
// 기본 100 Hz = 10 ms
|
|
public int loopPeriodMS = 10;
|
|
|
|
|
|
public void StartPLCMotionThread()
|
|
{
|
|
if (!bThread_Run) {
|
|
Thread_Run();
|
|
}
|
|
}
|
|
|
|
public void StopPLCMotionThread()
|
|
{
|
|
Thread_Stop();
|
|
}
|
|
|
|
void Thread_Run()
|
|
{
|
|
if (Thread_aLive == null)
|
|
Thread_aLive = new Thread(ThreadFunction);
|
|
|
|
Thread.Sleep(300);
|
|
|
|
if (!bThread_Run) {
|
|
bThread_Run = true;
|
|
Thread_aLive.Start();
|
|
Log.V("PLCMotion Thread: Start");
|
|
}
|
|
}
|
|
|
|
public void Thread_Stop()
|
|
{
|
|
if (bThread_Run) {
|
|
bThread_Run = false;
|
|
Thread.Sleep(loopPeriodMS*2);
|
|
Thread_aLive.Abort();
|
|
Log.V("PLCMotion Thread: Stop");
|
|
}
|
|
|
|
Thread_aLive = null;
|
|
}
|
|
|
|
private void ThreadFunction()
|
|
{
|
|
while (bThread_Run) {
|
|
try {
|
|
if (!bThreadStop) {
|
|
// 모션 업데이트 로직들
|
|
foreach (var axis in _plcMotorList) {
|
|
axis.UpdateMotion();
|
|
}
|
|
}
|
|
} catch (Exception ex) {
|
|
Log.E($"Exceptoin: {ex.Message}");
|
|
}
|
|
Thread.Sleep(loopPeriodMS);
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
}
|