- Added QRValidation vision control system - Includes CapCleaningControl UI components - WebSocket-based barcode validation system - Support for Crevis PLC integration - Test projects for PLC emulator, motion, IO panel, and Modbus 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
279 lines
10 KiB
C#
279 lines
10 KiB
C#
using arDev.AzinAxt;
|
|
using arDev.AzinAxt.Emulator;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
|
|
namespace Project.Dialog
|
|
{
|
|
public partial class fEmulator : Form
|
|
{
|
|
public CEmuleDIO devIO { get; private set; }
|
|
public CEmulMOT devM { get; private set; }
|
|
|
|
JogController[] jobCtl;
|
|
|
|
public fEmulator(int pCnt,int aCnt, MOT mot)
|
|
{
|
|
InitializeComponent();
|
|
|
|
//motion
|
|
devM = new CEmulMOT(aCnt);
|
|
|
|
this.jobCtl = new JogController[] {
|
|
jogController1,jogController2,
|
|
jogController3,jogController4,
|
|
jogController5
|
|
};
|
|
|
|
foreach (var item in jobCtl)
|
|
{
|
|
item.arDebugMode = false;
|
|
item.ItemClick += Item_ItemClick;
|
|
}
|
|
|
|
for (int i = 0; i < aCnt; i++)
|
|
{
|
|
Boolean enb = i < aCnt;
|
|
jobCtl[i].MotionObject = mot;
|
|
jobCtl[i].Enabled = enb;
|
|
jobCtl[i].arUsage = enb;
|
|
jobCtl[i].arAutoUpdate = false;
|
|
jobCtl[i].Invalidate();
|
|
|
|
if (enb)
|
|
{
|
|
devM.MaxPosition[i] = jobCtl[i].arMaxLength;
|
|
devM.MinPosition[i] = jobCtl[i].arMinLength;
|
|
}
|
|
|
|
}
|
|
|
|
//input
|
|
devIO = new CEmuleDIO(pCnt);
|
|
devIO.IOValueChagned += Dev_IOValueChagned;
|
|
|
|
this.tblDI.SuspendLayout();
|
|
this.tblDO.SuspendLayout();
|
|
|
|
var pinNameI = new string[pCnt];
|
|
var pinNameO = new string[pCnt];
|
|
var pinTitleI = new string[pCnt];
|
|
var pinTitleO = new string[pCnt];
|
|
|
|
for (int i = 0; i < pinNameI.Length; i++)
|
|
{
|
|
pinNameI[i] = "X" + i.ToString("X2").PadLeft(3, '0');// Enum.GetName(typeof(ePLCIPin), i); //Enum.GetNames(typeof(eDIName))[i];// i.ToString();
|
|
pinTitleI[i] = string.Empty;// i.ToString();// Enum.GetName(typeof(ePLCITitle), i); //Enum.GetNames(typeof(eDITitle))[i];
|
|
|
|
}
|
|
|
|
for (int i = 0; i < pinNameO.Length; i++)
|
|
{
|
|
pinNameO[i] = "Y" + i.ToString("X2").PadLeft(3, '0');// Enum.GetName(typeof(ePLCOPin), i); // Enum.GetNames(typeof(eDOName))[i];
|
|
pinTitleO[i] = string.Empty;//i.ToString();// Enum.GetName(typeof(ePLCOTitle), i); // Enum.GetNames(typeof(eDOTitle))[i];
|
|
}
|
|
|
|
tblDI.MatrixSize = new Point(8, 8);
|
|
tblDO.MatrixSize = new Point(8, 8);
|
|
|
|
tblDI.setTitle(pinTitleI);
|
|
tblDO.setTitle(pinTitleO);
|
|
|
|
tblDI.setNames(pinNameI);
|
|
tblDO.setNames(pinNameO);
|
|
|
|
tblDI.setItemTextAlign(ContentAlignment.BottomLeft);
|
|
tblDO.setItemTextAlign(ContentAlignment.BottomLeft);
|
|
|
|
|
|
|
|
tblDI.setValue(devIO.Input);
|
|
tblDO.setValue(devIO.Output);
|
|
|
|
//dio.IOValueChanged += dio_IOValueChanged;
|
|
|
|
this.tblDI.ItemClick += tblDI_ItemClick;
|
|
this.tblDO.ItemClick += tblDO_ItemClick;
|
|
|
|
this.tblDI.Invalidate();
|
|
this.tblDO.Invalidate();
|
|
}
|
|
|
|
private void fEmulator_Load(object sender, EventArgs e)
|
|
{
|
|
timer1.Start();
|
|
}
|
|
|
|
private void Item_ItemClick(object sender, JogController.ItemClickEventArgs e)
|
|
{
|
|
//조그컨트롤에서 버튼을 누르면 동작하는 기능
|
|
JogController jog = sender as JogController;
|
|
arDev.AzinAxt.MOT mot = jog.MotionObject;
|
|
if (e.Button == MouseButtons.Left)
|
|
{
|
|
if (e.IsDown == false)
|
|
{
|
|
//마우스 업
|
|
if (e.Command.StartsWith("JOG"))
|
|
{
|
|
devM.dCmd[jog.arAxis] = devM.dAct[jog.arAxis];
|
|
mot.MoveStop("", (short)jog.arAxis);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//마우스 다운
|
|
if (e.Command == "HSET")
|
|
{
|
|
mot.isHomeSet[jog.arAxis] = !mot.isHomeSet[jog.arAxis];
|
|
Console.WriteLine("homse change : " + devM.isHSet[jog.arAxis].ToString());
|
|
}
|
|
else if (e.Command == "ALM")
|
|
{
|
|
//알람상태를 직접 변경해야한다
|
|
devM.SetMech(jog.arAxis, CEmulMOT.eMach.MotAlarm, !devM.isAlm(jog.arAxis));
|
|
}
|
|
else if (e.Command == "SVON")
|
|
{
|
|
var cVal = mot.isSERVOON[jog.arAxis];
|
|
mot.SetSVON((short)jog.arAxis, !cVal);
|
|
}
|
|
else if (e.Command == "ORG")
|
|
{
|
|
mot.Move((short)jog.arAxis, 0);
|
|
}
|
|
else if (e.Command == "JOGR")
|
|
{
|
|
mot.JOG((short)jog.arAxis, eMotionDirection.Positive);
|
|
}
|
|
else if (e.Command == "JOGL")
|
|
{
|
|
mot.JOG((short)jog.arAxis, eMotionDirection.Negative);
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
void tblDO_ItemClick(object sender, GridView.ItemClickEventArgs e)
|
|
{
|
|
var nVal = !devIO.Output[e.idx];//.Get(e.idx);// doValue[e.idx];// == 1 ? (ushort)0 : (ushort)1;
|
|
devIO.SetOutput(e.idx, nVal);
|
|
}
|
|
void tblDI_ItemClick(object sender, GridView.ItemClickEventArgs e)
|
|
{
|
|
var nVal = !devIO.Input[e.idx];
|
|
devIO.SetInput(e.idx, nVal);
|
|
}
|
|
private void Dev_IOValueChagned(object sender, CEmuleDIO.IOValueChangedArgs e)
|
|
{
|
|
if (e.Dir == CEmuleDIO.eDirection.In)
|
|
{
|
|
//해당 아이템의 값을 변경하고 다시 그린다.
|
|
if (tblDI.setValue(e.ArrIDX, e.NewValue))
|
|
tblDI.Invalidate();//.drawItem(e.ArrIDX);
|
|
Console.WriteLine(string.Format("di change {0}:{1}", e.ArrIDX, e.NewValue.ToString()));
|
|
}
|
|
else
|
|
{
|
|
//해당 아이템의 값을 변경하고 다시 그린다.
|
|
if (tblDO.setValue(e.ArrIDX, e.NewValue))
|
|
tblDO.Invalidate();//.drawItem(e.ArrIDX);
|
|
|
|
Console.WriteLine(string.Format("do change {0}:{1}", e.ArrIDX, e.NewValue.ToString()));
|
|
}
|
|
}
|
|
|
|
private void timer1_Tick(object sender, EventArgs e)
|
|
{
|
|
for (int i = 0; i < this.devM.axisCount; i++)
|
|
{
|
|
//각 축별 데이터를 표시한다
|
|
this.jobCtl[i].arIsOrg = devM.isOrg(i);
|
|
this.jobCtl[i].arIsInp = devM.isINp(i);
|
|
this.jobCtl[i].arIsAlm = devM.isAlm(i);
|
|
this.jobCtl[i].arIsLimM = devM.isLimM(i);
|
|
this.jobCtl[i].arIsLimP = devM.isLimP(i);
|
|
this.jobCtl[i].arIsSvON = devM.isSvOn(i);
|
|
|
|
this.jobCtl[i].ardAct = devM.dAct[i];
|
|
this.jobCtl[i].arIsInit = true;// MotionObject.IsInit;
|
|
this.jobCtl[i].arIsHSet = true;
|
|
|
|
this.jobCtl[i].Invalidate();
|
|
}
|
|
|
|
//motor 표시
|
|
mcv.Pin_Run = devIO.Output[(int)eDOName.CONV_RUN];
|
|
mcv.Pin_DirCW = true;
|
|
mcv.Invalidate();
|
|
|
|
m1.Pin_Run = devIO.Output[(int)eDOName.PORT1_MOT_RUN];
|
|
m1.Pin_DirCW = devIO.Output[(int)eDOName.PORT1_MOT_DIR];
|
|
m1.Invalidate();
|
|
|
|
m2.Pin_Run = devIO.Output[(int)eDOName.PORT2_MOT_RUN];
|
|
m2.Pin_DirCW = devIO.Output[(int)eDOName.PORT2_MOT_DIR];
|
|
m2.Invalidate();
|
|
|
|
m3.Pin_Run = devIO.Output[(int)eDOName.PORT3_MOT_RUN];
|
|
m3.Pin_DirCW = devIO.Output[(int)eDOName.PORT3_MOT_DIR];
|
|
m3.Invalidate();
|
|
|
|
m4.Pin_Run = devIO.Output[(int)eDOName.PORT4_MOT_RUN];
|
|
m4.Pin_DirCW = devIO.Output[(int)eDOName.PORT4_MOT_DIR];
|
|
m4.Invalidate();
|
|
}
|
|
|
|
private void button1_Click(object sender, EventArgs e)
|
|
{
|
|
//모터 svon
|
|
Pub.mot.SetSVON(true);
|
|
|
|
//emg on
|
|
devIO.SetInput((int)eDIName.BUT_EMGF, true);
|
|
devIO.SetInput((int)eDIName.BUT_EMGR, true);
|
|
|
|
devIO.SetInput((int)eDIName.AREA_PORT11, true);
|
|
devIO.SetInput((int)eDIName.AREA_PORT12, true);
|
|
|
|
devIO.SetInput((int)eDIName.AREA_PORT21, true);
|
|
devIO.SetInput((int)eDIName.AREA_PORT22, true);
|
|
|
|
devIO.SetInput((int)eDIName.AREA_PORT31, true);
|
|
devIO.SetInput((int)eDIName.AREA_PORT32, true);
|
|
|
|
devIO.SetInput((int)eDIName.AREA_PORT41, true);
|
|
devIO.SetInput((int)eDIName.AREA_PORT42, true);
|
|
|
|
//각포트는 하단에 있는걸로 한다
|
|
devIO.SetInput((int)eDIName.PORT1_LIM_UP, true);
|
|
devIO.SetInput((int)eDIName.PORT1_LIM_DN, false); //false가 감지
|
|
devIO.SetInput((int)eDIName.PORT1_DET_UP, true);
|
|
devIO.SetInput((int)eDIName.PORT1_DET_DN, true);
|
|
|
|
devIO.SetInput((int)eDIName.PORT2_LIM_UP, true);
|
|
devIO.SetInput((int)eDIName.PORT2_LIM_DN, false); //false가 감지
|
|
devIO.SetInput((int)eDIName.PORT2_DET_UP, true);
|
|
devIO.SetInput((int)eDIName.PORT2_DET_DN, true);
|
|
|
|
devIO.SetInput((int)eDIName.PORT3_LIM_UP, true);
|
|
devIO.SetInput((int)eDIName.PORT3_LIM_DN, false); //false가 감지
|
|
devIO.SetInput((int)eDIName.PORT3_DET_UP, true);
|
|
devIO.SetInput((int)eDIName.PORT3_DET_DN, true);
|
|
|
|
devIO.SetInput((int)eDIName.PORT4_LIM_UP, true);
|
|
devIO.SetInput((int)eDIName.PORT4_LIM_DN, false); //false가 감지
|
|
devIO.SetInput((int)eDIName.PORT4_DET_UP, true);
|
|
devIO.SetInput((int)eDIName.PORT4_DET_DN, true);
|
|
}
|
|
}
|
|
}
|