using System;
|
using System.Collections.Generic;
|
using System.ComponentModel;
|
using System.Drawing;
|
using System.Data;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
using System.Windows.Forms;
|
using static SA_LTT.Module.Crevis;
|
using System.Threading;
|
using SA_LTT;
|
using padDLL;
|
|
namespace SA_LTT_UI.Screen
|
{
|
public partial class ScreenIO : UserControl
|
{
|
MainFrame _mainFrame;
|
Thread t_UIUpdate;
|
|
bool updateCheck;
|
|
private List<IoBar> InputIoBars = new List<IoBar>();
|
private List<IoBar> OutputIoBars = new List<IoBar>();
|
private List<AnalogBar> InputAnalogBars = new List<AnalogBar>();
|
private List<AnalogBar> OutputAnalogBars = new List<AnalogBar>();
|
|
public ScreenIO(MainFrame mainFrame)
|
{
|
InitializeComponent();
|
|
_mainFrame = mainFrame;
|
|
InitalizeData();
|
|
t_UIUpdate = new Thread(UIUpdateTh);
|
t_UIUpdate.Start();
|
}
|
|
|
private void InitalizeData()
|
{
|
FlowLayoutPanel fllayout = new FlowLayoutPanel();
|
|
int i = 0;
|
DigitalInput[] inputs = _mainFrame.equipment.crevis.DigitalInputs.Keys.ToArray();
|
foreach (DigitalInput input in inputs)
|
{
|
IoBar ioBar = new IoBar(i, input.ToString());
|
InputIoBars.Add(ioBar);
|
|
if (i % 8 == 0)
|
{
|
fllayout = new FlowLayoutPanel();
|
fllayout.AutoSize = true;
|
fllayout.BorderStyle = BorderStyle.FixedSingle;
|
fllayout.FlowDirection = FlowDirection.TopDown;
|
|
if ((i / 8) % 2 == 0)
|
{
|
flp_DigitalInputLeft.Controls.Add(fllayout);
|
}
|
else
|
{
|
flp_DigitalInputRight.Controls.Add(fllayout);
|
}
|
}
|
|
fllayout.Controls.Add(ioBar);
|
i++;
|
}
|
|
i = 0;
|
DigitalOutput[] outputs = _mainFrame.equipment.crevis.DigitalOutputs.Keys.ToArray();
|
foreach (DigitalOutput output in outputs)
|
{
|
IoBar ioBar = new IoBar(i, output.ToString());
|
ioBar.AddClickEvent(DigitalOutputClicked);
|
OutputIoBars.Add(ioBar);
|
|
if (i % 8 == 0)
|
{
|
fllayout = new FlowLayoutPanel();
|
fllayout.AutoSize = true;
|
fllayout.BorderStyle = BorderStyle.FixedSingle;
|
fllayout.FlowDirection = FlowDirection.TopDown;
|
|
if ((i / 8) % 2 == 0)
|
{
|
flp_DigitalOutputLeft.Controls.Add(fllayout);
|
}
|
else
|
{
|
flp_DigitalOutputRight.Controls.Add(fllayout);
|
}
|
}
|
|
fllayout.Controls.Add(ioBar);
|
i++;
|
}
|
|
i = 0;
|
AnalogInput[] analogInputs = _mainFrame.equipment.crevis.AnalogInputs.Keys.ToArray();
|
foreach (AnalogInput output in analogInputs)
|
{
|
AnalogBar analogBar = new AnalogBar(i, output.ToString());
|
InputAnalogBars.Add(analogBar);
|
|
if (i % 4 == 0)
|
{
|
fllayout = new FlowLayoutPanel();
|
fllayout.AutoSize = true;
|
fllayout.BorderStyle = BorderStyle.FixedSingle;
|
fllayout.FlowDirection = FlowDirection.TopDown;
|
|
if ((i / 4) % 2 == 0)
|
{
|
flp_AnalogInputLeft.Controls.Add(fllayout);
|
}
|
else
|
{
|
flp_AnalogInputRight.Controls.Add(fllayout);
|
}
|
}
|
|
fllayout.Controls.Add(analogBar);
|
i++;
|
}
|
|
i = 0;
|
AnalogOutput[] analogOutputs = _mainFrame.equipment.crevis.AnalogOutputs.Keys.ToArray();
|
foreach (AnalogOutput output in analogOutputs)
|
{
|
AnalogBar analogBar = new AnalogBar(i, output.ToString());
|
analogBar.AddClickEvent(AnalogOutputClicked);
|
OutputAnalogBars.Add(analogBar);
|
|
if (i % 4 == 0)
|
{
|
fllayout = new FlowLayoutPanel();
|
fllayout.AutoSize = true;
|
fllayout.BorderStyle = BorderStyle.FixedSingle;
|
fllayout.FlowDirection = FlowDirection.TopDown;
|
|
if ((i / 4) % 2 == 0)
|
{
|
flp_AnalogOutputLeft.Controls.Add(fllayout);
|
}
|
else
|
{
|
flp_AnalogOutputRight.Controls.Add(fllayout);
|
}
|
}
|
|
fllayout.Controls.Add(analogBar);
|
i++;
|
}
|
}
|
|
private void UIUpdateTh()
|
{
|
while (_mainFrame.equipment.IsDisposed == false)
|
{
|
Thread.Sleep(10);
|
|
if (updateCheck == false)
|
{
|
updateCheck = true;
|
UIUpdate();
|
}
|
}
|
}
|
|
private void UIUpdate()
|
{
|
if (InvokeRequired)
|
{
|
BeginInvoke(new UIUpdateDelegate(UIUpdate));
|
return;
|
}
|
else
|
{
|
try
|
{
|
int i = 0;
|
foreach(DigitalInput digitalInput in Enum.GetValues(typeof(DigitalInput)))
|
{
|
InputIoBars[i].Status = _mainFrame.equipment.crevis.DigitalInputs[digitalInput];
|
i++;
|
}
|
|
i = 0;
|
foreach (DigitalOutput digitalOutput in Enum.GetValues(typeof(DigitalOutput)))
|
{
|
OutputIoBars[i].Status = _mainFrame.equipment.crevis.DigitalOutputs[digitalOutput];
|
i++;
|
}
|
|
|
i = 0;
|
foreach (AnalogInput input in Enum.GetValues(typeof(AnalogInput)))
|
{
|
InputAnalogBars[i].Value = _mainFrame.equipment.crevis.AnalogInputs[input];
|
i++;
|
}
|
|
i = 0;
|
foreach (AnalogOutput input in Enum.GetValues(typeof(AnalogOutput)))
|
{
|
OutputAnalogBars[i].Value = _mainFrame.equipment.crevis.AnalogOutputs[input];
|
i++;
|
}
|
|
if(_mainFrame.equipment.ProcessStatus == ProcessStatus.Idle || _mainFrame.equipment.ProcessStatus == ProcessStatus.Pause)
|
{
|
if(flp_AnalogOutputLeft.Enabled == false)
|
{
|
flp_AnalogOutputLeft.Enabled = true;
|
}
|
|
if (flp_AnalogOutputRight.Enabled == false)
|
{
|
flp_AnalogOutputRight.Enabled = true;
|
}
|
|
if (flp_DigitalOutputLeft.Enabled == false)
|
{
|
flp_DigitalOutputLeft.Enabled = true;
|
}
|
|
if (flp_DigitalOutputRight.Enabled == false)
|
{
|
flp_DigitalOutputRight.Enabled = true;
|
}
|
}
|
else
|
{
|
if (flp_AnalogOutputLeft.Enabled == true)
|
{
|
flp_AnalogOutputLeft.Enabled = false;
|
}
|
|
if (flp_AnalogOutputRight.Enabled == true)
|
{
|
flp_AnalogOutputRight.Enabled = false;
|
}
|
|
if (flp_DigitalOutputLeft.Enabled == true)
|
{
|
flp_DigitalOutputLeft.Enabled = false;
|
}
|
|
if (flp_DigitalOutputRight.Enabled == true)
|
{
|
flp_DigitalOutputRight.Enabled = false;
|
}
|
}
|
}
|
catch (Exception e)
|
{
|
EquipmentLogManager.Instance.WriteExceptionLog(e.StackTrace);
|
}
|
finally
|
{
|
updateCheck = false;
|
}
|
}
|
}
|
|
private void DigitalOutputClicked(object sender, EventArgs e)
|
{
|
Control control = (Control)sender;
|
DigitalOutput digitalOutput = (DigitalOutput)control.Tag;
|
|
EquipmentLogManager.Instance.WriteButtonLog($"ScreenIO : {digitalOutput.ToString()} {!_mainFrame.equipment.crevis.DigitalOutputs[digitalOutput]}");
|
_mainFrame.equipment.crevis.WriteOutput(digitalOutput, !_mainFrame.equipment.crevis.DigitalOutputs[digitalOutput]);
|
}
|
|
private void AnalogOutputClicked(object sender, EventArgs e)
|
{
|
var nPad = new NumericPad();
|
nPad.Setup("0", "10"); //범위 변경해야 함
|
nPad.ShowDialog();
|
double value = 0;
|
if(double.TryParse(nPad.GetValue(), out value))
|
{
|
if (nPad.DialogResult != DialogResult.OK) return;
|
|
Control control = (Control)sender;
|
AnalogOutput analoglOutput = (AnalogOutput)((int)control.Tag * 10);
|
|
EquipmentLogManager.Instance.WriteButtonLog($"ScreenIO : {analoglOutput.ToString()} {value}");
|
_mainFrame.equipment.crevis.WriteAnalog(analoglOutput, value);
|
}
|
}
|
}
|
}
|