You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
241 lines
7.9 KiB
C#
241 lines
7.9 KiB
C#
using Rs.Framework;
|
|
using Rs.Motion;
|
|
using Rs.Motion.Base;
|
|
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;
|
|
using static System.Windows.Forms.VisualStyles.VisualStyleElement.StartPanel;
|
|
|
|
namespace Rs.Controls
|
|
{
|
|
public partial class InAndOut : UserControl
|
|
{
|
|
private Dictionary<string, IOStatus> ioDicIn = new Dictionary<string, IOStatus>();
|
|
private Dictionary<string, IOStatus> ioDicOut = new Dictionary<string, IOStatus>();
|
|
private IOStatus selectIOStatus;
|
|
private string m_username = "";
|
|
public InAndOut()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
public void LoadIO(IIOCard card,int btnWidth,string username="")
|
|
{
|
|
timer1.Enabled = true;
|
|
m_username = username;
|
|
panelIn.Controls.Clear();
|
|
panelOut.Controls.Clear();
|
|
ioDicIn.Clear();
|
|
ioDicOut.Clear();
|
|
if (card.DIn.Count > 0)
|
|
{
|
|
|
|
card.DIn = card.DIn.OrderBy(ob => ob.Disabled).ToList();
|
|
foreach (IIO iO in card.DIn)
|
|
{
|
|
CreateIoControl(panelIn, iO, true, btnWidth);
|
|
}
|
|
}
|
|
|
|
if (card.DOut.Count > 0)
|
|
{
|
|
card.DOut = card.DOut.OrderBy(ob => ob.Disabled).ToList();
|
|
foreach (IIO iO in card.DOut)
|
|
{
|
|
CreateIoControl(panelOut, iO, false, btnWidth);
|
|
}
|
|
}
|
|
}
|
|
|
|
void CreateIoControl(FlowLayoutPanel panel, IIO io, bool inIo = false, int btnWidth = 100)
|
|
{
|
|
try
|
|
{
|
|
IOStatus iostatus = new IOStatus();
|
|
if (inIo == false)
|
|
{
|
|
iostatus.Cursor = Cursors.Hand;
|
|
iostatus.Click += (s, e) => {
|
|
IOStatus btnIo = (IOStatus)s;
|
|
IIO _io = (IIO)btnIo.Tag;
|
|
if (btnIo.Status == 0)
|
|
{
|
|
MessageQueue.Instance.Insert($"write io {_io.Name} value 1");
|
|
IoManager.Instance.WriteOut(_io.Name, 1);
|
|
}
|
|
|
|
else
|
|
{
|
|
MessageQueue.Instance.Insert($"write io {_io.Name} value 0");
|
|
IoManager.Instance.WriteOut(_io.Name, 0);
|
|
}
|
|
|
|
};
|
|
}
|
|
iostatus.Font = new Font("宋体", 9);
|
|
//SizeF sf = this.CreateGraphics().MeasureString(io.Name, iostatus.Font);
|
|
|
|
iostatus.Tag = io;
|
|
iostatus.Margin = new Padding(15, 10, 15, 10);
|
|
iostatus.IoNO = io.Index;
|
|
iostatus.Radius = 10;
|
|
iostatus.Passed = io.Passed;
|
|
iostatus.Reverse = io.IsReverse;
|
|
iostatus.Disabled = io.Disabled;
|
|
iostatus.AutoSize = false;
|
|
iostatus.ForeColor = Color.White;
|
|
iostatus.Size = new Size(btnWidth, 50);
|
|
iostatus.Status = 0;
|
|
iostatus.Text = io.Name;
|
|
iostatus.MouseDown += Iostatus_MouseDown;
|
|
if (inIo)
|
|
{
|
|
if (!ioDicIn.ContainsKey(io.Name))
|
|
{
|
|
ioDicIn.Add(io.Name, iostatus);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (!ioDicOut.ContainsKey(io.Name))
|
|
{
|
|
ioDicOut.Add(io.Name, iostatus);
|
|
}
|
|
}
|
|
panel.Controls.Add(iostatus);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private void Iostatus_MouseDown(object sender, MouseEventArgs e)
|
|
{
|
|
if (m_username == "Admin" || m_username == "Vender")
|
|
{
|
|
if (e.Button == MouseButtons.Right)
|
|
{
|
|
IOStatus io = (IOStatus)sender;
|
|
selectIOStatus = io;
|
|
contextMenuStrip1.Show(MousePosition.X, MousePosition.Y);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void timer1_Tick(object sender, EventArgs e)
|
|
{
|
|
foreach (KeyValuePair<string, IOStatus> item in ioDicIn)
|
|
{
|
|
if (!item.Value.Disabled)
|
|
{
|
|
short value = IoManager.Instance.ReadIn(item.Value.Text);
|
|
ioDicIn[item.Value.Text].Status = value;
|
|
}
|
|
}
|
|
foreach (KeyValuePair<string, IOStatus> item in ioDicOut)
|
|
{
|
|
if (!item.Value.Disabled)
|
|
{
|
|
short value = IoManager.Instance.ReadOut(item.Value.Text);
|
|
ioDicOut[item.Value.Text].Status = value;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void reverseToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
if (selectIOStatus != null)
|
|
{
|
|
IIO io = (IIO)selectIOStatus.Tag;
|
|
io.IsReverse = !io.IsReverse;
|
|
io.Card.Save();
|
|
selectIOStatus = null;
|
|
}
|
|
}
|
|
|
|
private void checkedToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
if (selectIOStatus != null)
|
|
{
|
|
selectIOStatus.Passed = !selectIOStatus.Passed;
|
|
IIO io = (IIO)selectIOStatus.Tag;
|
|
io.Passed = selectIOStatus.Passed;
|
|
io.Card.Save();
|
|
selectIOStatus = null;
|
|
}
|
|
}
|
|
|
|
private void disabledToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
if (selectIOStatus != null)
|
|
{
|
|
selectIOStatus.Disabled = !selectIOStatus.Disabled;
|
|
IIO io = (IIO)selectIOStatus.Tag;
|
|
io.Disabled = selectIOStatus.Disabled;
|
|
io.Card.Save();
|
|
selectIOStatus = null;
|
|
}
|
|
}
|
|
|
|
private void ReloadIoStatus()
|
|
{
|
|
ioDicIn.Clear();
|
|
ioDicOut.Clear();
|
|
foreach (var ioStatus in panelIn.Controls)
|
|
{
|
|
IOStatus ios = ioStatus as IOStatus;
|
|
ioDicIn.Add(ios.Text, ios);
|
|
}
|
|
foreach (var ioStatus in panelOut.Controls)
|
|
{
|
|
IOStatus ios = ioStatus as IOStatus;
|
|
ioDicOut.Add(ios.Text, ios);
|
|
}
|
|
}
|
|
|
|
private void renameToolStripMenuItem_Click(object sender, EventArgs e)
|
|
{
|
|
//if (selectIOStatus != null)
|
|
//{
|
|
// RenameIO renameIO = new RenameIO(selectIOStatus);
|
|
// renameIO.StartPosition = FormStartPosition.CenterParent;
|
|
// DialogResult dr = renameIO.ShowDialog();
|
|
// //if(dr == DialogResult.OK)
|
|
// {
|
|
// ReloadIoStatus();
|
|
// }
|
|
//}
|
|
}
|
|
|
|
private void label1_DoubleClick(object sender, EventArgs e)
|
|
{
|
|
foreach (var item in ioDicIn)
|
|
{
|
|
((IIO)item.Value.Tag).Passed = false;
|
|
((IIO)item.Value.Tag).Disabled = false;
|
|
((IIO)item.Value.Tag).Card.Save();
|
|
}
|
|
ReloadIoStatus();
|
|
}
|
|
|
|
private void label2_DoubleClick(object sender, EventArgs e)
|
|
{
|
|
foreach (var item in ioDicOut)
|
|
{
|
|
((IIO)item.Value.Tag).Passed = false;
|
|
((IIO)item.Value.Tag).Disabled = false;
|
|
((IIO)item.Value.Tag).Card.Save();
|
|
}
|
|
ReloadIoStatus();
|
|
}
|
|
}
|
|
}
|