diff --git a/DH.Commons/Enums/Enum.cs b/DH.Commons/Enums/Enum.cs index 8c17014..a53970d 100644 --- a/DH.Commons/Enums/Enum.cs +++ b/DH.Commons/Enums/Enum.cs @@ -71,38 +71,45 @@ namespace DH.Commons.Enums public enum EnumPLCOutputIO { 转盘方向=0, - 转盘速度=1, - 转盘使能=2, - 转盘启动=3, - 转盘清料=4, - 指示灯绿=5, - 指示灯黄=6, - 指示灯红=7, - 蜂鸣器=8, - 振动盘=9, - 皮带=10, - 工位1=11, - 工位2=12, - 工位3=13, - 工位4=14, - 工位5=15, - 工位6 = 16, - 工位7 = 17, - 工位8 = 18, - 工位9 = 19, - 工位10 = 20, - OK料盒 =21, - NG料盒=22, - OK吹气时间=23, - NG吹气时间=24, - 产品计数=25, - 计数清零=26, - 工件最小值=27, - 工具最大值=28, - 启用心跳=29, - 心跳地址=30, + 转盘速度, + 转盘使能, + 转盘启动, + 转盘清料, + 指示灯绿, + 指示灯黄, + 指示灯红, + 蜂鸣器, + 振动盘, + 皮带, + 工位1, + 工位2, + 工位3, + 工位4, + 工位5, + 工位6 , + 工位7 , + 工位8 , + 工位9 , + 工位10 , + OK料盒 , + NG料盒, + OK吹气时间, + NG吹气时间, + 产品计数, + 计数清零, + 工件最小值, + 工件最大值, + 启用心跳, + 心跳地址, 挡料电机回原点, 挡料电机回原点速度, + 挡料电机速度, + 挡料电机顺时针, + 挡料电机逆时针, + 挡料电机位置, + OK脉冲, + NG脉冲, + diff --git a/DH.Devices.PLC/XinJEPLCTcpNet.cs b/DH.Devices.PLC/XinJEPLCTcpNet.cs index 6a38193..221967f 100644 --- a/DH.Devices.PLC/XinJEPLCTcpNet.cs +++ b/DH.Devices.PLC/XinJEPLCTcpNet.cs @@ -13,6 +13,7 @@ using DH.Commons.Enums; using HslCommunication; using HslCommunication.Enthernet; using HslCommunication.Profinet.XINJE; +using OpenCvSharp; namespace DH.Devices.PLC { @@ -59,7 +60,7 @@ namespace DH.Devices.PLC TcpNet.Write("M122", true); MonitorPieces(); TurntableStop(); - + PrepareMotion();//心跳监听 return true; } else @@ -440,6 +441,22 @@ namespace DH.Devices.PLC OnNewPieces?.Invoke(axisIndex, pieceNumber); }); + } + public async Task HeartbeatAsync1() + { + + + + + while (Connected) + { + PLCItem pLCItem = PLCItemList.FirstOrDefault(u => u.Name == "心跳地址"); + if (pLCItem == null) + return; + string HeartbeatAddress = pLCItem.Type + pLCItem.Address; + TcpNet.Write(HeartbeatAddress, true); + await Task.Delay(900); // 非阻塞,等待1秒 + } } /// /// 入料监听 @@ -451,6 +468,7 @@ namespace DH.Devices.PLC PLCItem pLCItem= PLCItemList.FirstOrDefault(u => u.Name == "产品计数"); if (pLCItem == null) return; + string Count = pLCItem.Type + pLCItem.Address; DateTime startTime = DateTime.Now; DateTime endTime = startTime; TimeSpan timeSpan = endTime - startTime; @@ -462,7 +480,8 @@ namespace DH.Devices.PLC uint tmpPieceNumber = 0; sw.Start(); - var ret = TcpNet.ReadUInt16("D1016"); + // var ret = TcpNet.ReadUInt16("D1016"); + var ret = TcpNet.ReadUInt16(Count); sw.Stop(); if (ret.IsSuccess) @@ -504,51 +523,539 @@ namespace DH.Devices.PLC /// /// 转盘开启操作 /// - public void TurntableOpen(int speed, bool Direction) + public void TurntableOpen() { - WriteBool("M122", true); + PLCItem pLCItem = PLCItemList.FirstOrDefault(u => u.Name == "计数清零"); + if (pLCItem == null) + return; + string CountToZero = pLCItem.Type + pLCItem.Address; + PLCItem DiskSpeedItem = PLCItemList.FirstOrDefault(u => u.Name == "转盘速度"); + if (DiskSpeedItem == null) + return; + string diskSpeedadress = DiskSpeedItem.Type + DiskSpeedItem.Address; + int diskSpeedValue= Convert.ToInt32( DiskSpeedItem.Value); + PLCItem DiskDirectionItem = PLCItemList.FirstOrDefault(u => u.Name == "转盘方向"); + if (DiskDirectionItem == null) + return; + string diskDirectionadress = DiskDirectionItem.Type + DiskDirectionItem.Address; + bool Direction =Convert.ToBoolean( DiskDirectionItem.Value); + PLCItem DiskOpenItem = PLCItemList.FirstOrDefault(u => u.Name == "转盘使能"); + if (DiskOpenItem == null) + return; + string diskopenadress = DiskOpenItem.Type + DiskOpenItem.Address; + PLCItem DiskRunItem = PLCItemList.FirstOrDefault(u => u.Name == "转盘启动"); + if (DiskRunItem == null) + return; + string diskadress = DiskRunItem.Type + DiskRunItem.Address; + + + WriteBool(CountToZero, true); Thread.Sleep(10); WriteBool("M10", false); Thread.Sleep(10); //速度 - TcpNet.Write("HD10", (ushort)speed); + TcpNet.Write(diskSpeedadress, (ushort)diskSpeedValue); Thread.Sleep(10); //方向 - WriteBool("M1", Direction); + WriteBool(diskDirectionadress, Direction); Thread.Sleep(10); //使能 - WriteBool("M2", true); + WriteBool(diskopenadress, true); Thread.Sleep(10); //启动 - WriteBool("M0", true); + WriteBool(diskadress, true); + + + //WriteBool("M122", true); + //Thread.Sleep(10); + //WriteBool("M10", false); + //Thread.Sleep(10); + ////速度 + //TcpNet.Write("HD10", (ushort)10000); + //Thread.Sleep(10); + ////方向 + //WriteBool("M1", Direction); + //Thread.Sleep(10); + ////使能 + //WriteBool("M2", true); + //Thread.Sleep(10); + ////启动 + //WriteBool("M0", true); Thread.Sleep(10); // _mainMotion.CurrentState = DeviceState.DSOpen; piecesCount = 0; } - - + /// /// 转盘停止操作 /// public void TurntableStop() { - WriteBool("M122", true); + PLCItem pLCItem = PLCItemList.FirstOrDefault(u => u.Name == "计数清零"); + if (pLCItem == null) + return; + string CountToZero = pLCItem.Type + pLCItem.Address; + PLCItem DiskRunItem = PLCItemList.FirstOrDefault(u => u.Name == "转盘启动"); + if (DiskRunItem == null) + return; + string diskadress = DiskRunItem.Type + DiskRunItem.Address; + PLCItem DiskOpenItem = PLCItemList.FirstOrDefault(u => u.Name == "转盘使能"); + if (DiskOpenItem == null) + return; + string diskopenadress = DiskOpenItem.Type + DiskOpenItem.Address; + + WriteBool(CountToZero, true); Thread.Sleep(50); - WriteBool("M0", false); + WriteBool(diskadress, false); Thread.Sleep(50); - WriteBool("M2", false); + WriteBool(diskopenadress, false); Thread.Sleep(50); - WriteBool("M50", false); + WriteBool("M10", false); + + //WriteBool("M122", true); + //Thread.Sleep(50); + //WriteBool("M0", false); + //Thread.Sleep(50); + //WriteBool("M2", false); + //Thread.Sleep(50); + //WriteBool("M50", false); piecesCount = 0; } + private void PrepareMotion() + { + + + + + //心跳 + //if (X018PLCConfig.Heartbeat) + //{ + + Task.Run(async () => await HeartbeatAsync1()); + //} + + ////写入工件最大值、最小值 + ProjectValue(); + + + ////写入工位脉冲 + Workstation1Pulse(); + Workstation2Pulse(); + Workstation3Pulse(); + Workstation4Pulse(); + Workstation5Pulse(); + + ////写入吹气时间 + ChuiQiTime(); + + + ////写入吹气脉冲 + OKPulse(); + NGPulse(); + //if (_GC01Driver == null) + //{ + // _GC01Driver = DeviceCollection.FirstOrDefault(u => u is GC01Driver) as GC01Driver; + //} + //if (_GC01Driver == null) + //{ + // throw new ProcessException($"未能获取激光位移传感器驱动"); + //} + //if (_vibrationDriver == null) + //{ + // _vibrationDriver = DeviceCollection.FirstOrDefault(u => u is JYDAMDriver) as JYDAMDriver; + //} + //if (_vibrationDriver == null) + //{ + // throw new ProcessException($"未能获取振动盘控制器驱动"); + //} + + // ResetTimer = new Timer(FullResetProcessExcute, null, -1, -1); + + //feedingProductTimer = new Timer(FeedingProductTriggerExcute, null, -1, -1); + //feedingProductTimerTimer = new Timer(UpdateFeedingProductTrigger, null, -1, -1); + + //_mainMotion.OnAxisPositionChanged -= MainMotion_OnAxisPositionChanged; + //_mainMotion.OnAxisPositionChanged += MainMotion_OnAxisPositionChanged; + + //_mainMotion.OnCapturePositionChanged -= MainMotion_OnCapturePositionChanged; + //_mainMotion.OnCapturePositionChanged += MainMotion_OnCapturePositionChanged; + + // _mainMotion.OnNewPieces -= MainMotion_NewPieces; + // _mainMotion.OnNewPieces += MainMotion_NewPieces; + + //_mainMotion.OnAlarmVibrationDisk -= MainMotion_AlarmVibrationDisk; + //_mainMotion.OnAlarmVibrationDisk += MainMotion_AlarmVibrationDisk; + // PrepareLightIndexes(); + } + + /// + /// 挡料电机操作 + /// true: 顺时针 + /// False: 逆时针 + /// + /// + public void FeedingMotor( bool direction) + { + + + // 设置最大等待时间,假设为 3 秒 + int timeout = 3000; + int elapsedTime = 0; + int checkInterval = 100; // 每次检查等待 100ms + + PLCItem pLCItem = PLCItemList.FirstOrDefault(u => u.Name == "挡料电机回原点"); + if (pLCItem == null) + return; + PLCItem zerospeeditem = PLCItemList.FirstOrDefault(u => u.Name == "挡料电机回原点速度"); + if (zerospeeditem == null) + return; + + PLCItem CunSpeed = PLCItemList.FirstOrDefault(u => u.Name == "挡料电机速度"); + if (CunSpeed == null) + return; + + PLCItem CunClockwiseItem = PLCItemList.FirstOrDefault(u => u.Name == "挡料电机顺时针"); + if (CunClockwiseItem == null) + return; + + PLCItem CunCounterclockwiseItem = PLCItemList.FirstOrDefault(u => u.Name == "挡料电机逆时针"); + if (CunCounterclockwiseItem == null) + return; + + PLCItem CunPosItem = PLCItemList.FirstOrDefault(u => u.Name == "挡料电机位置"); + if (CunPosItem == null) + return; + + string CunToZero = pLCItem.Type + pLCItem.Address; + string CunToZeroSpeed = zerospeeditem.Type + zerospeeditem.Address; + string CunSpeedadress = CunSpeed.Type + CunSpeed.Address; + string CunClockwise = CunClockwiseItem.Type + CunClockwiseItem.Address; + string CunCounterclockwise = CunCounterclockwiseItem.Type + CunCounterclockwiseItem.Address; + string CunPos = CunPosItem.Type + CunPosItem.Address; + short zerospeed = (short)Convert.ToInt32(zerospeeditem.Value); + short cunSpeed = (short)Convert.ToInt32(CunSpeed.Value); + short u = (short)Convert.ToInt32(CunPosItem.Value); + // WriteBool(CountToZero, true); + + // 检查是否不在原点,如果不在,则回原点 + if (!ReadBool(CunToZero)) + { + WriteShort(CunToZeroSpeed, (short)zerospeed); // 速度 + Thread.Sleep(10); + // 发送回原点指令 + WriteBool(CunToZero, true); + Thread.Sleep(1000); // 给设备一些时间响应 + + // 等待回到原点 + while (!ReadBool(CunToZero)) + { + if (elapsedTime >= timeout) + { + break; + } + + Thread.Sleep(checkInterval); + elapsedTime += checkInterval; + } + } + + // 无论是刚回到原点还是已经在原点,执行目标位置、速度和方向设置 + + + + WriteShort(CunSpeedadress, (short)cunSpeed); + Thread.Sleep(2000); + string dir = string.Empty; + if (direction) + { + WriteBool(CunClockwise, true); // 顺时针转动 + dir = "顺时针"; + } + else + { + WriteBool(CunCounterclockwise, true); // 逆时针转动 + dir = "逆时针"; + } + Thread.Sleep(10); + WriteShort(CunPos, (short)u); // 目标位置 + Thread.Sleep(2000); + + + + } + + + /// /// 计数清零 /// public void CountToZero() { - WriteBool("M120", true); + PLCItem pLCItem = PLCItemList.FirstOrDefault(u => u.Name == "计数清零"); + if (pLCItem == null) + return; + string CountToZero = pLCItem.Type + pLCItem.Address; + WriteBool(CountToZero, true); + Thread.Sleep(10); + } + + public void RedLight(bool b) + { + PLCItem pLCItem = PLCItemList.FirstOrDefault(u => u.Name == "指示灯红"); + if (pLCItem == null) + return; + string RedLight = pLCItem.Type + pLCItem.Address; + WriteBool(RedLight, b); + Thread.Sleep(10); + } + + public void GreenLight(bool b) + { + PLCItem pLCItem = PLCItemList.FirstOrDefault(u => u.Name == "指示灯绿"); + if (pLCItem == null) + return; + string Light = pLCItem.Type + pLCItem.Address; + WriteBool(Light, b); + // WriteBool(IIConfig.GreenLight, b); + Thread.Sleep(10); } + + public void YellowLight(bool b) + { + PLCItem pLCItem = PLCItemList.FirstOrDefault(u => u.Name == "指示灯黄"); + if (pLCItem == null) + return; + string Light = pLCItem.Type + pLCItem.Address; + WriteBool(Light, b); + Thread.Sleep(10); + } + + public void Buzzer(bool b) + { + PLCItem pLCItem = PLCItemList.FirstOrDefault(u => u.Name == "蜂鸣器"); + if (pLCItem == null) + return; + string Light = pLCItem.Type + pLCItem.Address; + WriteBool(Light, b); + Thread.Sleep(10); + } + + public void Belt(bool b) + { + PLCItem pLCItem = PLCItemList.FirstOrDefault(u => u.Name == "皮带"); + if (pLCItem == null) + return; + string Light = pLCItem.Type + pLCItem.Address; + WriteBool(Light, b); + Thread.Sleep(10); + } + + + public void Workstation1Pulse() + { + PLCItem pLCItem = PLCItemList.FirstOrDefault(u => u.Name == "工位1"); + if (pLCItem == null) + return; + string Workstation1Pulse = pLCItem.Type + pLCItem.Address; + int Pulse=Convert.ToInt32(pLCItem.Value); + + string result = Regex.Replace(Workstation1Pulse, @"\D", ""); + int r = Convert.ToInt32(result) + 1; + result = "HD" + r.ToString(); + short high = (short)(Pulse >> 16); // 高 16 位 + short low = (short)(Pulse & 0xFFFF); // 低 16 位 + WriteShort(result, high); + Thread.Sleep(10); + WriteShort(Workstation1Pulse, low); + Thread.Sleep(10); + } + + public void Workstation2Pulse() + { + PLCItem pLCItem = PLCItemList.FirstOrDefault(u => u.Name == "工位2"); + if (pLCItem == null) + return; + string Workstation1Pulse = pLCItem.Type + pLCItem.Address; + int Pulse=Convert.ToInt32(pLCItem.Value); + string result = Regex.Replace(Workstation1Pulse, @"\D", ""); + int r = Convert.ToInt32(result) + 1; + result = "HD" + r.ToString(); + short high = (short)(Pulse >> 16); // 高 16 位 + short low = (short)(Pulse & 0xFFFF); // 低 16 位 + WriteShort(result, high); + Thread.Sleep(10); + WriteShort(Workstation1Pulse, low); + Thread.Sleep(10); + } + public void Workstation3Pulse() + { + PLCItem pLCItem = PLCItemList.FirstOrDefault(u => u.Name == "工位3"); + if (pLCItem == null) + return; + string Workstation1Pulse = pLCItem.Type + pLCItem.Address; + int Pulse = Convert.ToInt32(pLCItem.Value); + + string result = Regex.Replace(Workstation1Pulse, @"\D", ""); + int r = Convert.ToInt32(result) + 1; + result = "HD" + r.ToString(); + short high = (short)(Pulse >> 16); // 高 16 位 + short low = (short)(Pulse & 0xFFFF); // 低 16 位 + WriteShort(result, high); + Thread.Sleep(10); + WriteShort(Workstation1Pulse, low); + Thread.Sleep(10); + } + public void Workstation4Pulse() + { + PLCItem pLCItem = PLCItemList.FirstOrDefault(u => u.Name == "工位4"); + if (pLCItem == null) + return; + string Workstation1Pulse = pLCItem.Type + pLCItem.Address; + int Pulse = Convert.ToInt32(pLCItem.Value); + string result = Regex.Replace(Workstation1Pulse, @"\D", ""); + int r = Convert.ToInt32(result) + 1; + result = "HD" + r.ToString(); + short high = (short)(Pulse >> 16); // 高 16 位 + short low = (short)(Pulse & 0xFFFF); // 低 16 位 + WriteShort(result, high); + Thread.Sleep(10); + WriteShort(Workstation1Pulse, low); + Thread.Sleep(10); + } + + public void Workstation5Pulse() + { + PLCItem pLCItem = PLCItemList.FirstOrDefault(u => u.Name == "工位5"); + if (pLCItem == null) + return; + + string Workstation1Pulse = pLCItem.Type + pLCItem.Address; + int Pulse = Convert.ToInt32(pLCItem.Value); + string result = Regex.Replace(Workstation1Pulse, @"\D", ""); + int r = Convert.ToInt32(result) + 1; + result = "HD" + r.ToString(); + short high = (short)(Pulse >> 16); // 高 16 位 + short low = (short)(Pulse & 0xFFFF); // 低 16 位 + WriteShort(result, high); + Thread.Sleep(10); + WriteShort(Workstation1Pulse, low); + Thread.Sleep(10); + } + + + + public void ProjectValue() + { + PLCItem pLCItemmax = PLCItemList.FirstOrDefault(u => u.Name == "工件最大值"); + if (pLCItemmax == null) + return; + PLCItem pLCItemmin = PLCItemList.FirstOrDefault(u => u.Name == "工件最小值"); + if (pLCItemmin == null) + return; + int productMax =Convert.ToInt32( pLCItemmax.Value); + int productMin = Convert.ToInt32( pLCItemmin.Value); + + string ProductMax = pLCItemmax.Type + pLCItemmax.Address; + string ProductMin = pLCItemmin.Type + pLCItemmin.Address; + WriteShort(ProductMax, (short)productMax); + Thread.Sleep(10); + WriteShort(ProductMin, (short)productMin); + Thread.Sleep(10); + } + + public void OKPulse() + { + + PLCItem pLCItem = PLCItemList.FirstOrDefault(u => u.Name == "OK脉冲"); + if (pLCItem == null) + return; + + string OKPulse = pLCItem.Type + pLCItem.Address; + int Pulse =Convert.ToInt32( pLCItem.Value); + string result = Regex.Replace(OKPulse, @"\D", ""); + int r = Convert.ToInt32(result) + 1; + result = "HD" + r.ToString(); + short high = (short)(Pulse >> 16); // 高 16 位 + short low = (short)(Pulse & 0xFFFF); // 低 16 位 + WriteShort(result, high); + Thread.Sleep(10); + WriteShort(OKPulse, low); + Thread.Sleep(10); + } + + public void NGPulse() + { + PLCItem pLCItem = PLCItemList.FirstOrDefault(u => u.Name == "NG脉冲"); + if (pLCItem == null) + return; + + string NGPulse = pLCItem.Type + pLCItem.Address; + int Pulse=Convert.ToInt32(pLCItem.Value); + string result = Regex.Replace(NGPulse, @"\D", ""); + int r = Convert.ToInt32(result) + 1; + result = "HD" + r.ToString(); + short high = (short)(Pulse >> 16); // 高 16 位 + short low = (short)(Pulse & 0xFFFF); // 低 16 位 + WriteShort(result, high); + Thread.Sleep(10); + WriteShort(NGPulse, low); + Thread.Sleep(10); + } + + + public void TurnClear(bool b) + { + PLCItem pLCItem = PLCItemList.FirstOrDefault(u => u.Name == "转盘清料"); + if (pLCItem == null) + return; + + string TurnClear = pLCItem.Type + pLCItem.Address; + + WriteBool(TurnClear, b); + Thread.Sleep(10); + } + + public void OpenHeartbeat(bool v) + { + PLCItem pLCItem = PLCItemList.FirstOrDefault(u => u.Name == "心跳功能"); + if (pLCItem == null) + return; + + string Heartbeat = pLCItem.Type + pLCItem.Address; + + WriteBool(Heartbeat, v); + Thread.Sleep(10); + + + } + + public void Vibratory(bool v) + { + PLCItem pLCItem = PLCItemList.FirstOrDefault(u => u.Name == "振动盘"); + if (pLCItem == null) + return; + + + string Vibratory = pLCItem.Type + pLCItem.Address; + WriteBool(Vibratory, v); + Thread.Sleep(10); + } + + + public void ChuiQiTime() + { + PLCItem pLCItem = PLCItemList.FirstOrDefault(u => u.Name == "吹气时间"); + if (pLCItem == null) + return; + + + string ChuiQiTime = pLCItem.Type + pLCItem.Address; + short time = (short)Convert.ToInt32(pLCItem.Value); + WriteShort(ChuiQiTime, time); + Thread.Sleep(10); + } + } } diff --git a/DHSoftware/MainWindow.Designer.cs b/DHSoftware/MainWindow.Designer.cs index ad67f56..242b77d 100644 --- a/DHSoftware/MainWindow.Designer.cs +++ b/DHSoftware/MainWindow.Designer.cs @@ -30,7 +30,6 @@ { AntdUI.Tabs.StyleCard styleCard1 = new AntdUI.Tabs.StyleCard(); AntdUI.Tabs.StyleCard styleCard2 = new AntdUI.Tabs.StyleCard(); - AntdUI.Tabs.StyleCard styleCard3 = new AntdUI.Tabs.StyleCard(); AntdUI.SegmentedItem segmentedItem1 = new AntdUI.SegmentedItem(); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainWindow)); AntdUI.SegmentedItem segmentedItem2 = new AntdUI.SegmentedItem(); @@ -49,9 +48,6 @@ splitContainer1 = new SplitContainer(); splitContainer2 = new SplitContainer(); tabImgDisplay = new AntdUI.Tabs(); - tabMain = new AntdUI.TabPage(); - tabsStas = new AntdUI.Tabs(); - tabPage3 = new AntdUI.TabPage(); richTextBox1 = new RichTextBox(); tabsConfig = new AntdUI.Tabs(); tabPage2 = new AntdUI.TabPage(); @@ -76,9 +72,6 @@ splitContainer2.Panel1.SuspendLayout(); splitContainer2.Panel2.SuspendLayout(); splitContainer2.SuspendLayout(); - tabImgDisplay.SuspendLayout(); - tabsStas.SuspendLayout(); - tabPage3.SuspendLayout(); tabsConfig.SuspendLayout(); panel1.SuspendLayout(); panel3.SuspendLayout(); @@ -130,7 +123,7 @@ // label1 // label1.AutoSize = true; - label1.Location = new Point(979, 10); + label1.Location = new Point(59, 10); label1.Name = "label1"; label1.Size = new Size(64, 21); label1.TabIndex = 1; @@ -203,7 +196,7 @@ splitContainer1.Panel2.BackColor = SystemColors.ButtonFace; splitContainer1.Panel2.Controls.Add(tabsConfig); splitContainer1.Size = new Size(1024, 500); - splitContainer1.SplitterDistance = 580; + splitContainer1.SplitterDistance = 606; splitContainer1.SplitterIncrement = 2; splitContainer1.SplitterWidth = 10; splitContainer1.TabIndex = 0; @@ -221,8 +214,8 @@ // // splitContainer2.Panel2 // - splitContainer2.Panel2.Controls.Add(tabsStas); - splitContainer2.Size = new Size(580, 500); + splitContainer2.Panel2.Controls.Add(richTextBox1); + splitContainer2.Size = new Size(606, 500); splitContainer2.SplitterDistance = 320; splitContainer2.TabIndex = 0; // @@ -231,46 +224,17 @@ tabImgDisplay.Dock = DockStyle.Fill; tabImgDisplay.Location = new Point(0, 0); tabImgDisplay.Name = "tabImgDisplay"; - tabImgDisplay.Pages.Add(tabMain); - tabImgDisplay.Size = new Size(580, 320); + tabImgDisplay.Size = new Size(606, 320); tabImgDisplay.Style = styleCard1; tabImgDisplay.TabIndex = 1; tabImgDisplay.Text = "tabs1"; // - // tabMain - // - tabMain.Location = new Point(3, 28); - tabMain.Name = "tabMain"; - tabMain.Size = new Size(574, 289); - tabMain.TabIndex = 0; - tabMain.Text = "检测"; - // - // tabsStas - // - tabsStas.Dock = DockStyle.Fill; - tabsStas.Location = new Point(0, 0); - tabsStas.Name = "tabsStas"; - tabsStas.Pages.Add(tabPage3); - tabsStas.Size = new Size(580, 176); - tabsStas.Style = styleCard2; - tabsStas.TabIndex = 3; - tabsStas.Text = "tabs3"; - // - // tabPage3 - // - tabPage3.Controls.Add(richTextBox1); - tabPage3.Location = new Point(3, 28); - tabPage3.Name = "tabPage3"; - tabPage3.Size = new Size(574, 145); - tabPage3.TabIndex = 0; - tabPage3.Text = "日志"; - // // richTextBox1 // richTextBox1.Dock = DockStyle.Fill; richTextBox1.Location = new Point(0, 0); richTextBox1.Name = "richTextBox1"; - richTextBox1.Size = new Size(574, 145); + richTextBox1.Size = new Size(606, 176); richTextBox1.TabIndex = 0; richTextBox1.Text = ""; // @@ -280,8 +244,8 @@ tabsConfig.Location = new Point(0, 0); tabsConfig.Name = "tabsConfig"; tabsConfig.Pages.Add(tabPage2); - tabsConfig.Size = new Size(434, 500); - tabsConfig.Style = styleCard3; + tabsConfig.Size = new Size(408, 500); + tabsConfig.Style = styleCard2; tabsConfig.TabIndex = 2; tabsConfig.Text = "tabs2"; // @@ -289,7 +253,7 @@ // tabPage2.Location = new Point(3, 28); tabPage2.Name = "tabPage2"; - tabPage2.Size = new Size(428, 469); + tabPage2.Size = new Size(402, 469); tabPage2.TabIndex = 0; tabPage2.Text = "配置"; // @@ -467,9 +431,6 @@ splitContainer2.Panel2.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)splitContainer2).EndInit(); splitContainer2.ResumeLayout(false); - tabImgDisplay.ResumeLayout(false); - tabsStas.ResumeLayout(false); - tabPage3.ResumeLayout(false); tabsConfig.ResumeLayout(false); panel1.ResumeLayout(false); panel3.ResumeLayout(false); @@ -492,10 +453,6 @@ private SplitContainer splitContainer1; private SplitContainer splitContainer2; private AntdUI.Tabs tabImgDisplay; - private AntdUI.TabPage tabMain; - private AntdUI.Tabs tabsStas; - private AntdUI.TabPage tabPage3; - private RichTextBox richTextBox1; private AntdUI.Tabs tabsConfig; private AntdUI.TabPage tabPage2; private AntdUI.Label lbName; @@ -504,5 +461,6 @@ private AntdUI.Button btnAddProject; private AntdUI.Button btnLoadProject; public AntdUI.Select sltProjects; + private RichTextBox richTextBox1; } } \ No newline at end of file diff --git a/DHSoftware/MainWindow.cs b/DHSoftware/MainWindow.cs index 35d54a4..8d1d04f 100644 --- a/DHSoftware/MainWindow.cs +++ b/DHSoftware/MainWindow.cs @@ -176,11 +176,11 @@ namespace DHSoftware InitData(); //绑定事件 BindEventHandler(); - UserConfigFrm userControlFrm = new UserConfigFrm(); + //UserConfigFrm userControlFrm = new UserConfigFrm(); - userControlFrm.Window = this; - userControlFrm.Dock = DockStyle.Fill; - tabPage2.Controls.Add(userControlFrm); + //userControlFrm.Window = this; + //userControlFrm.Dock = DockStyle.Fill; + //tabPage2.Controls.Add(userControlFrm); } /// @@ -267,7 +267,7 @@ namespace DHSoftware cam.CameraIP = cameraBase.CameraIP; cam.IsEnabled = cameraBase.IsEnabled; Cameras.Add(cam); - //cam.CameraConnect(); + cam.CameraConnect(); cam.OnHImageOutput += OnCameraHImageOutput; } else if (cameraBase.CamType == EnumCamType.海康hik) @@ -294,6 +294,7 @@ namespace DHSoftware if (plcBase.PLCType == EnumPLCType.信捷XC网口) { PLC.IP = plcBase.IP; + PLC.PLCType = plcBase.PLCType; PLC.Enable = plcBase.Enable; PLC.PLCName = plcBase.PLCName; PLC.PLCItemList = plcBase.PLCItemList; @@ -321,8 +322,10 @@ namespace DHSoftware detectionConfig.ModelHeight = detection.ModelHeight; detectionConfig.In_lable_path = detection.In_lable_path; detectionConfig.IsEnabled = detection.IsEnabled; - detectionConfig.ShowLocation.X = detection.ShowLocation.X; - detectionConfig.ShowLocation.Y = detection.ShowLocation.Y; + detectionConfig.ShowLocation.X = (i + 1) % 5+ (i + 1) / 5; + // detectionConfig.ShowLocation.X = detection.ShowLocation.X; + detectionConfig.ShowLocation.Y = (i + 1) / 5+1; + // detectionConfig.ShowLocation.Y = detection.ShowLocation.Y; DetectionConfigs.Add(detectionConfig); } } @@ -354,6 +357,7 @@ namespace DHSoftware //初始化模型 加载模型 _visionEngine.Init(); CtrlVisionRunBase ctrlVisionRun = new CtrlVisionRunBase(_visionEngine); + ctrlVisionRun.Dock = DockStyle.Fill; tabImgDisplay.Controls.Add(ctrlVisionRun); } @@ -581,10 +585,12 @@ namespace DHSoftware PieceCount = 0; //吹气点位归置 currentRegister = 411; - - if (_PLCConfig?.Enable == true) + + if (PLC?.Enable == true) { PLC.CountToZero(); + PLC.OnNewPieces -= MainMotion_NewPieces; + PLC.OnNewPieces += MainMotion_NewPieces; } ConfigModel.CameraBaseList.ForEach(d => @@ -691,7 +697,7 @@ namespace DHSoftware PLCItem itemSpeed = PLC.PLCItemList.FirstOrDefault(u => u.Name == "转盘速度"); if (itemSpeed != null) { - PLC.TurntableOpen(Convert.ToInt32(itemSpeed.Value), true); + PLC.TurntableOpen(); } Thread.Sleep(500);