Files
ENIG/Cs_HMI/Project/ViewForm/fIO.cs
2025-01-07 16:08:02 +09:00

205 lines
6.9 KiB
C#

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.ViewForm
{
public partial class fIO : Form
{
public fIO()
{
InitializeComponent();
tblMain.SuspendLayout();
//이름설정 INput #1
List<string> namearray = new List<string>(32);
List<string> tagarray = new List<string>(32);
namearray.Clear();
tagarray.Clear();
for (byte i = 0; i < 16; i++)
{
var flagName = ((arDev.FakePLC.DIName)i).ToString();
var enumValue = Enum.Parse(typeof(arDev.FakePLC.DIPin), flagName);
if (flagName == i.ToString()) tagarray.Add(string.Empty);
else
{
//동일한 이름의 pin 번호르 찾아서 할당해준다.
var eV = (arDev.FakePLC.DIPin)enumValue;
tagarray.Add(((byte)eV).ToString());
}
namearray.Add(flagName.Replace("_", "\n"));
}
for (byte i = 0; i < 8; i++)
{
var flagName = ((arDev.FakePLC.DOName)i).ToString();
var enumValue = Enum.Parse(typeof(arDev.FakePLC.DOPin), flagName);
if (flagName == i.ToString()) tagarray.Add(string.Empty);
else
{
//동일한 이름의 pin 번호르 찾아서 할당해준다.
var eV = (arDev.FakePLC.DOPin)enumValue;
tagarray.Add(((byte)eV).ToString());
}
namearray.Add(flagName);
}
this.tblMain.setTitle(namearray.ToArray());
this.tblMain.setTag(tagarray.ToArray());
this.tblMain.setItemTextAlign(ContentAlignment.BottomLeft);
//값설정
List<Boolean> fgValueM = new List<bool>();
List<Boolean> fgValueS = new List<bool>();
//mainplc
for (byte i = 0; i < 16; i++)
fgValueM.Add(PUB.PLC.GetValueI(i));
for (byte i = 0; i < 16; i++)
fgValueM.Add(PUB.PLC.GetValueO(i));
tblMain.setValue(fgValueM.ToArray());
tblMain.ResumeLayout();
this.FormClosed += FIO_FormClosed;
UpdateControl();
}
void Update_HWStatus()
{
var rownum = 1;
var colIdx = 0;
if (PUB.AGV.IsOpen == false) BlinkGridViewItem(HWState, rownum, colIdx++, 3, 4);
else HWState.setValue(rownum, colIdx++, 2); //
if (PUB.XBE.IsOpen == false) BlinkGridViewItem(HWState, rownum, colIdx++, 3, 4);
else HWState.setValue(rownum, colIdx++, 2); //
if (PUB.PLC.IsOpen == false) BlinkGridViewItem(HWState, rownum, colIdx++, 3, 4);
else HWState.setValue(rownum, colIdx++, 2); //
if (PUB.BMS.IsOpen == false) BlinkGridViewItem(HWState, rownum, colIdx++, 3, 4);
else HWState.setValue(rownum, colIdx++, 2); //
}
void BlinkGridViewItem(arFrame.Control.GridView ctl, int row, int col, int value1, int value2)
{
var curValue = ctl.getValue(row, col);
ctl.setValue(row, col, (byte)(curValue == value1 ? value2 : value1)); //
}
void UpdateControl()
{
var rowNum = 1;
var colIdx = 0;
HWState.setTitle(0, colIdx++, "AGV");
HWState.setTitle(0, colIdx++, "XBE");
HWState.setTitle(0, colIdx++, "PLC");
HWState.setTitle(0, colIdx++, "BAT");
colIdx = 0;
HWState.setTitle(rowNum, colIdx++, PUB.setting.Port_AGV);
HWState.setTitle(rowNum, colIdx++, PUB.setting.Port_XBE);
HWState.setTitle(rowNum, colIdx++, PUB.setting.Port_PLC);
HWState.setTitle(rowNum, colIdx++, PUB.setting.Port_BAT);
HWState.Invalidate();
}
private void fIO_Load(object sender, EventArgs e)
{
this.timer1.Start();
}
private void FIO_FormClosed(object sender, FormClosedEventArgs e)
{
//Pub.plcM.ValueChanged -= Plc1_ValueChanged;
//Pub.plcS.ValueChanged -= Plc2_ValueChanged;
}
private void tblIn1_ItemClick(object sender, arFrame.Control.GridView.ItemClickEventArgs e)
{
var dataIndex = (byte)e.idx;
if (dataIndex >= 16)
{
var ctl = sender as arFrame.Control.GridView;
var pinNoStr = ctl.Tags[e.idx];
if (pinNoStr.isEmpty() == true)
{
Util.MsgE("해당 포트는 핀번호가 설정되지 않았습니다", true);
}
else
{
var pinNo = byte.Parse(pinNoStr);
var curVal = PUB.PLC.GetValueO((byte)(dataIndex - 16));
PUB.PLC.SetOutput(pinNo, !curVal);// .Sendcommand(Device.PLC1.eCommand.SET_DOUTPUT, pinNo, newval);
}
}
else Util.MsgE("해당 주소는 허용되지 않습니다.", true);
}
bool tmrun = false;
private void timer1_Tick(object sender, EventArgs e)
{
if (this.Visible == false) return;
if (tmrun == true) return;
tmrun = true;
label1.Text = string.Format("{0} / {1}",
PUB.PLC.ioBinStr, PUB.PLC.SetupStr);
label3.Text = PUB.PLC.LastMessage;
Update_HWStatus();
List<Boolean> fgValueM = new List<bool>();
List<Boolean> fgValueS = new List<bool>();
//mainplc
for (byte i = 0; i < 16; i++)
this.tblMain.setValue(i, PUB.PLC.GetValueI(i));
for (byte i = 0; i < 16; i++)
this.tblMain.setValue(i + 16, PUB.PLC.GetValueO(i));
this.tblMain.Invalidate();
tmrun = false;
}
private void fIO_VisibleChanged(object sender, EventArgs e)
{
this.timer1.Enabled = this.Visible;
if (timer1.Enabled) timer1.Start();
else timer1.Stop();
}
private void button1_Click(object sender, EventArgs e)
{
PUB.PLC.ZMot(arDev.FakePLC.ZMotDirection.Up);
}
private void button2_Click(object sender, EventArgs e)
{
PUB.PLC.ZMot(arDev.FakePLC.ZMotDirection.Stop);
}
private void button3_Click_1(object sender, EventArgs e)
{
PUB.PLC.ZMot(arDev.FakePLC.ZMotDirection.Down);
}
}
}