add emulator
This commit is contained in:
37
Emulator/AGVEmulator/UC/AgvViewer.Designer.cs
generated
Normal file
37
Emulator/AGVEmulator/UC/AgvViewer.Designer.cs
generated
Normal file
@@ -0,0 +1,37 @@
|
||||
|
||||
namespace AGVEmulator.UC
|
||||
{
|
||||
partial class AgvViewer
|
||||
{
|
||||
/// <summary>
|
||||
/// 필수 디자이너 변수입니다.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// 사용 중인 모든 리소스를 정리합니다.
|
||||
/// </summary>
|
||||
/// <param name="disposing">관리되는 리소스를 삭제해야 하면 true이고, 그렇지 않으면 false입니다.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region 구성 요소 디자이너에서 생성한 코드
|
||||
|
||||
/// <summary>
|
||||
/// 디자이너 지원에 필요한 메서드입니다.
|
||||
/// 이 메서드의 내용을 코드 편집기로 수정하지 마세요.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
components = new System.ComponentModel.Container();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
272
Emulator/AGVEmulator/UC/AgvViewer.cs
Normal file
272
Emulator/AGVEmulator/UC/AgvViewer.cs
Normal file
@@ -0,0 +1,272 @@
|
||||
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 AGVEmulator.UC
|
||||
{
|
||||
public partial class AgvViewer : Control
|
||||
{
|
||||
|
||||
public AgvViewer()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
// Set Optimized Double Buffer to reduce flickering
|
||||
this.SetStyle(ControlStyles.UserPaint, true);
|
||||
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
|
||||
this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
|
||||
|
||||
// Redraw when resized
|
||||
this.SetStyle(ControlStyles.ResizeRedraw, true);
|
||||
}
|
||||
|
||||
public class TagArgs : EventArgs
|
||||
{
|
||||
public string Data { get; set; }
|
||||
public bool Active { get; set; }
|
||||
public TagArgs(string tag,bool act)
|
||||
{
|
||||
this.Data = tag;
|
||||
this.Active = act;
|
||||
}
|
||||
}
|
||||
public event EventHandler<TagArgs> TagTouched;
|
||||
public event EventHandler<TagArgs> MarkTouched;
|
||||
public event EventHandler<TagArgs> Command;
|
||||
|
||||
public bool StopbyMark { get; set; }
|
||||
public float mpos = 100;
|
||||
public float posmax = 1200;
|
||||
public float posmin = 0;
|
||||
public float mspd = 10;
|
||||
public System.Diagnostics.Stopwatch wat = new System.Diagnostics.Stopwatch();
|
||||
public Font FontTag { get; set; }
|
||||
public Font FontMrk { get; set; }
|
||||
public int dir = 1;
|
||||
|
||||
public class ptdata
|
||||
{
|
||||
public float pos { get; set; } = 0f;
|
||||
public string data { get; set; } = string.Empty;
|
||||
public Boolean active { get; set; } = false;
|
||||
}
|
||||
public ptdata[] listMRK { get; set; }
|
||||
public ptdata[] listTAG { get; set; }
|
||||
|
||||
public string lasttag { get; set; } = string.Empty;
|
||||
public string lasttagdir { get; set; } = string.Empty;
|
||||
public string lastmark { get; set; } = string.Empty;
|
||||
public string lastmarkdir { get; set; } = string.Empty;
|
||||
|
||||
protected override void OnPaint(PaintEventArgs pe)
|
||||
{
|
||||
pe.Graphics.Clear(this.BackColor);
|
||||
var r = new Rectangle(DisplayRectangle.Left + Padding.Left,
|
||||
DisplayRectangle.Top + Padding.Top,
|
||||
DisplayRectangle.Width - Padding.Right - Padding.Left - 1,
|
||||
DisplayRectangle.Height - Padding.Top - Padding.Bottom - 1);
|
||||
|
||||
|
||||
// pe.Graphics.FillRectangle(new SolidBrush(this.BackColor), DisplayRectangle);
|
||||
pe.Graphics.DrawRectangle(Pens.Black, r);
|
||||
|
||||
|
||||
var ptwidth = 25;
|
||||
var ptheight = 35;
|
||||
if (listMRK != null && listMRK.Any() && FontMrk != null)
|
||||
{
|
||||
foreach (var item in listMRK)
|
||||
{
|
||||
var x = r.Left + ((item.pos * 1f) / posmax) * r.Width;
|
||||
var rr = new RectangleF(x - ptwidth, r.Top + r.Height / 2f - ptheight / 2f, ptwidth * 2, ptheight);
|
||||
pe.Graphics.DrawLine(Pens.Gray, x, r.Top, x, r.Bottom);
|
||||
pe.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(120, Color.Gold)), rr);
|
||||
pe.Graphics.DrawRectangle(Pens.DimGray, rr.Left, rr.Top, rr.Width, rr.Height);
|
||||
pe.Graphics.DrawString(item.data, FontMrk, Brushes.Gray, rr, new StringFormat
|
||||
{
|
||||
Alignment = StringAlignment.Center,
|
||||
LineAlignment = StringAlignment.Center,
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
ptwidth = 15;
|
||||
if (listTAG != null && listTAG.Any() && FontTag != null)
|
||||
{
|
||||
var lst = listTAG.Where(t => t.data.EndsWith("1"));
|
||||
foreach (var item in lst)
|
||||
{
|
||||
var x = r.Left + ((item.pos * 1f) / posmax) * r.Width;
|
||||
var rr = new RectangleF(x - ptwidth, r.Top + 5, ptwidth * 2, 15);
|
||||
pe.Graphics.DrawLine(Pens.Orange, x, r.Top, x, rr.Top);
|
||||
pe.Graphics.FillRectangle(Brushes.Orange, rr);
|
||||
pe.Graphics.DrawRectangle(Pens.DimGray, rr.Left, rr.Top, rr.Width, rr.Height);
|
||||
pe.Graphics.DrawString(item.data, FontTag, Brushes.Black, rr, new StringFormat
|
||||
{
|
||||
Alignment = StringAlignment.Center,
|
||||
LineAlignment = StringAlignment.Center,
|
||||
});
|
||||
}
|
||||
|
||||
lst = listTAG.Where(t => t.data.EndsWith("0"));
|
||||
foreach (var item in lst)
|
||||
{
|
||||
var x = r.Left + ((item.pos * 1f) / posmax) * r.Width;
|
||||
var rr = new RectangleF(x - ptwidth, r.Bottom - 20, ptwidth * 2, 15);
|
||||
pe.Graphics.DrawLine(Pens.Orange, x, rr.Bottom, x, r.Bottom);
|
||||
pe.Graphics.FillRectangle(Brushes.Orange, rr);
|
||||
pe.Graphics.DrawRectangle(Pens.DimGray, rr.Left, rr.Top, rr.Width, rr.Height);
|
||||
pe.Graphics.DrawString(item.data, FontTag, Brushes.Black, rr, new StringFormat
|
||||
{
|
||||
Alignment = StringAlignment.Center,
|
||||
LineAlignment = StringAlignment.Center,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
var posX = r.Left + (mpos / posmax) * r.Width;
|
||||
var posY = r.Top + r.Height / 2f;
|
||||
var boxw = r.Width * 0.030f;
|
||||
var boxh = r.Height * 0.15f;
|
||||
var box = new RectangleF(posX - boxw, posY - boxh, boxw * 2, boxh * 2);
|
||||
var box2 = new RectangleF(box.Left - 5, box.Top + 3, 10, box.Height - 6);
|
||||
for (int i = 0; i < posmax; i += 100)
|
||||
{
|
||||
var x = r.Left + ((i * 1f) / posmax) * r.Width;
|
||||
pe.Graphics.DrawLine(Pens.Black, x, r.Bottom - 3, x, r.Bottom);
|
||||
if (i > 0)
|
||||
pe.Graphics.DrawString($"{i / 10f}m", this.Font, Brushes.Black, x - 12, r.Bottom - 15);
|
||||
}
|
||||
pe.Graphics.FillRectangle(Brushes.LightSkyBlue, box);
|
||||
pe.Graphics.DrawRectangle(Pens.Black, box.Left, box.Top, box.Width, box.Height);
|
||||
pe.Graphics.DrawLine(new Pen(Color.Black, 4), posX, box.Top - 5, posX, box.Bottom + 5);
|
||||
|
||||
pe.Graphics.FillRectangle(Brushes.Gold, box2);
|
||||
pe.Graphics.DrawRectangle(Pens.Black, box2.Left, box2.Top, box2.Width, box2.Height);
|
||||
//pe.Graphics.DrawString((mpos / 10f).ToString("N1") + "m", this.Font, Brushes.Black, box, new StringFormat
|
||||
//{
|
||||
// Alignment = StringAlignment.Center,
|
||||
// LineAlignment = StringAlignment.Center,
|
||||
//});
|
||||
|
||||
if (StopbyMark)
|
||||
pe.Graphics.DrawString("!MRK-STP!", this.Font, Brushes.Blue, r.Left+2, r.Top+2);
|
||||
|
||||
if (wat.IsRunning)
|
||||
{
|
||||
var newpos = mspd * (wat.ElapsedMilliseconds / 1000f);
|
||||
if (dir < 0) //forward
|
||||
{
|
||||
if (mpos - newpos < 0)
|
||||
mpos = posmax;
|
||||
else mpos -= newpos;
|
||||
|
||||
//내위치주변에 마커가 있는지 본다
|
||||
var mlist = listMRK.Where(t => t.pos <= mpos && (mpos - t.pos) < 10);
|
||||
var mrk = mlist.FirstOrDefault();
|
||||
if (mrk != null)
|
||||
{
|
||||
//대상마커가있다
|
||||
if (lastmark.Equals(mrk.data) == false || lastmarkdir.Equals("F") == false)
|
||||
{
|
||||
lastmark = mrk.data;
|
||||
lastmarkdir = "F";
|
||||
mrk.active = true;
|
||||
MarkTouched?.Invoke(this, new TagArgs(mrk.data,true));
|
||||
if(StopbyMark)
|
||||
{
|
||||
Command?.Invoke(this, new TagArgs("stop",true));
|
||||
StopbyMark = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (string.IsNullOrEmpty(lastmark) == false)
|
||||
{
|
||||
foreach(var item in listMRK.Where(t=>t.active))
|
||||
{
|
||||
item.active = false;
|
||||
MarkTouched?.Invoke(this, new TagArgs(item.data,false));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//주변태그확인
|
||||
var tlist = listTAG.Where(t => t.pos <= mpos && (mpos - t.pos) < 10);
|
||||
var tag = tlist.FirstOrDefault();
|
||||
if (tag != null)
|
||||
{
|
||||
//대상마커가있다
|
||||
if (lasttag.Equals(tag.data) == false || lasttagdir.Equals("F") == false)
|
||||
{
|
||||
lasttag = tag.data;
|
||||
lasttagdir = "F";
|
||||
TagTouched?.Invoke(this, new TagArgs(tag.data, true));
|
||||
}
|
||||
}
|
||||
}
|
||||
else //backward
|
||||
{
|
||||
if (mpos + newpos > posmax)
|
||||
mpos = 0;
|
||||
else mpos += newpos;
|
||||
|
||||
//내위치주변에 마커가 있는지 본다
|
||||
var mlist = listMRK.Where(t => t.pos >= mpos && (t.pos - mpos) < 10);
|
||||
var mrk = mlist.FirstOrDefault();
|
||||
if (mrk != null)
|
||||
{
|
||||
//대상마커가있다
|
||||
if (lastmark.Equals(mrk.data) == false || lastmarkdir.Equals("B") == false)
|
||||
{
|
||||
lastmark = mrk.data;
|
||||
lastmarkdir = "B";
|
||||
mrk.active = true;
|
||||
MarkTouched?.Invoke(this, new TagArgs(mrk.data, true));
|
||||
if (StopbyMark)
|
||||
{
|
||||
Command?.Invoke(this, new TagArgs("stop", true));
|
||||
StopbyMark = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (string.IsNullOrEmpty(lastmark) == false)
|
||||
{
|
||||
foreach (var item in listMRK.Where(t => t.active))
|
||||
{
|
||||
item.active = false;
|
||||
MarkTouched?.Invoke(this, new TagArgs(item.data, false));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//주변태그확인
|
||||
var tlist = listTAG.Where(t => t.pos >= mpos && (t.pos - mpos) < 10);
|
||||
var tag = tlist.FirstOrDefault();
|
||||
if (tag != null)
|
||||
{
|
||||
//대상마커가있다
|
||||
if (lasttag.Equals(tag.data) == false || lasttagdir.Equals("B") == false)
|
||||
{
|
||||
lasttag = tag.data;
|
||||
lasttagdir = "B";
|
||||
TagTouched?.Invoke(this, new TagArgs(tag.data, true));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
wat.Restart();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
162
Emulator/AGVEmulator/UC/SerialConn.Designer.cs
generated
Normal file
162
Emulator/AGVEmulator/UC/SerialConn.Designer.cs
generated
Normal file
@@ -0,0 +1,162 @@
|
||||
|
||||
namespace AGVEmulator
|
||||
{
|
||||
partial class SerialConn
|
||||
{
|
||||
/// <summary>
|
||||
/// 필수 디자이너 변수입니다.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// 사용 중인 모든 리소스를 정리합니다.
|
||||
/// </summary>
|
||||
/// <param name="disposing">관리되는 리소스를 삭제해야 하면 true이고, 그렇지 않으면 false입니다.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region 구성 요소 디자이너에서 생성한 코드
|
||||
|
||||
/// <summary>
|
||||
/// 디자이너 지원에 필요한 메서드입니다.
|
||||
/// 이 메서드의 내용을 코드 편집기로 수정하지 마세요.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.cmbBaud = new System.Windows.Forms.ComboBox();
|
||||
this.cmbPOrt = new System.Windows.Forms.ComboBox();
|
||||
this.panel1 = new System.Windows.Forms.Panel();
|
||||
this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel();
|
||||
this.lbrx = new System.Windows.Forms.Label();
|
||||
this.lbtx = new System.Windows.Forms.Label();
|
||||
this.button1 = new System.Windows.Forms.Button();
|
||||
this.panel1.SuspendLayout();
|
||||
this.tableLayoutPanel1.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// cmbBaud
|
||||
//
|
||||
this.cmbBaud.Dock = System.Windows.Forms.DockStyle.Top;
|
||||
this.cmbBaud.Font = new System.Drawing.Font("굴림", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(129)));
|
||||
this.cmbBaud.FormattingEnabled = true;
|
||||
this.cmbBaud.Items.AddRange(new object[] {
|
||||
"9600",
|
||||
"12800",
|
||||
"25600",
|
||||
"38400",
|
||||
"512000"});
|
||||
this.cmbBaud.Location = new System.Drawing.Point(0, 28);
|
||||
this.cmbBaud.Name = "cmbBaud";
|
||||
this.cmbBaud.Size = new System.Drawing.Size(134, 28);
|
||||
this.cmbBaud.TabIndex = 0;
|
||||
this.cmbBaud.Text = "9600";
|
||||
//
|
||||
// cmbPOrt
|
||||
//
|
||||
this.cmbPOrt.Dock = System.Windows.Forms.DockStyle.Top;
|
||||
this.cmbPOrt.Font = new System.Drawing.Font("굴림", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(129)));
|
||||
this.cmbPOrt.FormattingEnabled = true;
|
||||
this.cmbPOrt.Location = new System.Drawing.Point(0, 0);
|
||||
this.cmbPOrt.Name = "cmbPOrt";
|
||||
this.cmbPOrt.Size = new System.Drawing.Size(134, 28);
|
||||
this.cmbPOrt.TabIndex = 1;
|
||||
//
|
||||
// panel1
|
||||
//
|
||||
this.panel1.Controls.Add(this.tableLayoutPanel1);
|
||||
this.panel1.Controls.Add(this.cmbBaud);
|
||||
this.panel1.Controls.Add(this.cmbPOrt);
|
||||
this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.panel1.Location = new System.Drawing.Point(0, 0);
|
||||
this.panel1.Name = "panel1";
|
||||
this.panel1.Size = new System.Drawing.Size(134, 96);
|
||||
this.panel1.TabIndex = 2;
|
||||
//
|
||||
// tableLayoutPanel1
|
||||
//
|
||||
this.tableLayoutPanel1.ColumnCount = 2;
|
||||
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
|
||||
this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50F));
|
||||
this.tableLayoutPanel1.Controls.Add(this.lbrx, 0, 0);
|
||||
this.tableLayoutPanel1.Controls.Add(this.lbtx, 1, 0);
|
||||
this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 56);
|
||||
this.tableLayoutPanel1.Name = "tableLayoutPanel1";
|
||||
this.tableLayoutPanel1.RowCount = 1;
|
||||
this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F));
|
||||
this.tableLayoutPanel1.Size = new System.Drawing.Size(134, 40);
|
||||
this.tableLayoutPanel1.TabIndex = 4;
|
||||
//
|
||||
// lbrx
|
||||
//
|
||||
this.lbrx.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||
this.lbrx.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.lbrx.Font = new System.Drawing.Font("Microsoft Sans Serif", 15F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(129)));
|
||||
this.lbrx.Location = new System.Drawing.Point(0, 0);
|
||||
this.lbrx.Margin = new System.Windows.Forms.Padding(0);
|
||||
this.lbrx.Name = "lbrx";
|
||||
this.lbrx.Size = new System.Drawing.Size(67, 40);
|
||||
this.lbrx.TabIndex = 2;
|
||||
this.lbrx.Text = "RX";
|
||||
this.lbrx.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||
//
|
||||
// lbtx
|
||||
//
|
||||
this.lbtx.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
|
||||
this.lbtx.Dock = System.Windows.Forms.DockStyle.Fill;
|
||||
this.lbtx.Font = new System.Drawing.Font("Microsoft Sans Serif", 15F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(129)));
|
||||
this.lbtx.Location = new System.Drawing.Point(67, 0);
|
||||
this.lbtx.Margin = new System.Windows.Forms.Padding(0);
|
||||
this.lbtx.Name = "lbtx";
|
||||
this.lbtx.Size = new System.Drawing.Size(67, 40);
|
||||
this.lbtx.TabIndex = 3;
|
||||
this.lbtx.Text = "TX";
|
||||
this.lbtx.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
|
||||
//
|
||||
// button1
|
||||
//
|
||||
this.button1.Dock = System.Windows.Forms.DockStyle.Right;
|
||||
this.button1.FlatAppearance.BorderColor = System.Drawing.Color.DodgerBlue;
|
||||
this.button1.FlatAppearance.BorderSize = 3;
|
||||
this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
|
||||
this.button1.Font = new System.Drawing.Font("맑은 고딕", 18F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(129)));
|
||||
this.button1.Location = new System.Drawing.Point(134, 0);
|
||||
this.button1.Margin = new System.Windows.Forms.Padding(0);
|
||||
this.button1.Name = "button1";
|
||||
this.button1.Size = new System.Drawing.Size(82, 96);
|
||||
this.button1.TabIndex = 3;
|
||||
this.button1.Text = "연결";
|
||||
this.button1.UseVisualStyleBackColor = true;
|
||||
this.button1.Click += new System.EventHandler(this.button1_Click);
|
||||
//
|
||||
// SerialConn
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 12F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.Controls.Add(this.panel1);
|
||||
this.Controls.Add(this.button1);
|
||||
this.Name = "SerialConn";
|
||||
this.Size = new System.Drawing.Size(216, 96);
|
||||
this.panel1.ResumeLayout(false);
|
||||
this.tableLayoutPanel1.ResumeLayout(false);
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private System.Windows.Forms.ComboBox cmbBaud;
|
||||
private System.Windows.Forms.ComboBox cmbPOrt;
|
||||
private System.Windows.Forms.Panel panel1;
|
||||
private System.Windows.Forms.Button button1;
|
||||
private System.Windows.Forms.Label lbtx;
|
||||
private System.Windows.Forms.Label lbrx;
|
||||
private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1;
|
||||
}
|
||||
}
|
||||
130
Emulator/AGVEmulator/UC/SerialConn.cs
Normal file
130
Emulator/AGVEmulator/UC/SerialConn.cs
Normal file
@@ -0,0 +1,130 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace AGVEmulator
|
||||
{
|
||||
public partial class SerialConn : UserControl
|
||||
{
|
||||
public AR.Dev.RS232 dev { get; set; }
|
||||
public SerialConn()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
void AttachEvent()
|
||||
{
|
||||
dev.Message += Dev_Message;
|
||||
}
|
||||
void DetachEvent()
|
||||
{
|
||||
dev.Message -= Dev_Message;
|
||||
}
|
||||
private void Dev_Message(object sender, AR.Dev.RS232.MessageEventArgs e)
|
||||
{
|
||||
if (e.MsgType == AR.Dev.RS232.MessageType.Recv)
|
||||
ToggleRX();
|
||||
else if (e.MsgType == AR.Dev.RS232.MessageType.Send)
|
||||
ToggleTX();
|
||||
}
|
||||
|
||||
public void SetPortList(string[] list)
|
||||
{
|
||||
cmbPOrt.Items.Clear();
|
||||
foreach (var item in list)
|
||||
cmbPOrt.Items.Add(item);
|
||||
}
|
||||
public string PortName
|
||||
{
|
||||
get
|
||||
{
|
||||
return cmbPOrt.Text;
|
||||
}
|
||||
set { this.cmbPOrt.Text = value; }
|
||||
}
|
||||
public int BaudRate
|
||||
{
|
||||
get
|
||||
{
|
||||
return int.Parse(cmbBaud.Text);
|
||||
}
|
||||
set
|
||||
{
|
||||
cmbBaud.Text = value.ToString();
|
||||
}
|
||||
}
|
||||
public void ToggleTX()
|
||||
{
|
||||
if (lbtx.BackColor == Color.DeepSkyBlue)
|
||||
lbtx.BackColor = Color.White;
|
||||
else lbtx.BackColor = Color.DeepSkyBlue;
|
||||
}
|
||||
public void ToggleRX()
|
||||
{
|
||||
if (lbrx.BackColor == Color.Lime)
|
||||
lbrx.BackColor = Color.White;
|
||||
else lbrx.BackColor = Color.Lime;
|
||||
}
|
||||
public void Disconnect()
|
||||
{
|
||||
if (this.dev.IsOpen)
|
||||
{
|
||||
DetachEvent();
|
||||
dev.Close();
|
||||
}
|
||||
if (dev.IsOpen)
|
||||
button1.BackColor = Color.Lime;
|
||||
else button1.BackColor = Color.Tomato;
|
||||
}
|
||||
public void Connect()
|
||||
{
|
||||
if (this.dev.IsOpen)
|
||||
{
|
||||
DetachEvent();
|
||||
dev.Close();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.dev.PortName = cmbPOrt.Text;
|
||||
this.dev.BaudRate = int.Parse(cmbBaud.Text);
|
||||
AttachEvent();
|
||||
try
|
||||
{
|
||||
dev.Open();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
button1.BackColor = Color.Red;
|
||||
}
|
||||
}
|
||||
|
||||
if (dev.IsOpen)
|
||||
button1.BackColor = Color.Lime;
|
||||
else button1.BackColor = Color.Tomato;
|
||||
}
|
||||
|
||||
private void button1_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (this.dev == null)
|
||||
{
|
||||
MessageBox.Show("시리얼 개체가 연결되지 않았습니다");
|
||||
return;
|
||||
}
|
||||
if(int.TryParse(cmbBaud.Text,out int baud)==false)
|
||||
{
|
||||
MessageBox.Show("Baudrate 값이 올바르지 않습니다");
|
||||
return;
|
||||
}
|
||||
Connect();
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
120
Emulator/AGVEmulator/UC/SerialConn.resx
Normal file
120
Emulator/AGVEmulator/UC/SerialConn.resx
Normal file
@@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
||||
Reference in New Issue
Block a user