| LB_SmartVision/Forms/Pages/CommunicatorPage/CommunicatorForm.Designer.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| LB_SmartVision/Forms/Pages/CommunicatorPage/CommunicatorForm.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| LB_VisionProcesses/MotionControl/BaseMotionControl.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| LB_VisionProcesses/MotionControl/IMotionControl.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
| LB_VisionProcesses/MotionControl/MotionControlConfig.cs | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
LB_SmartVision/Forms/Pages/CommunicatorPage/CommunicatorForm.Designer.cs
@@ -36,10 +36,12 @@ txtSendMsg = new TextBox(); grpSetting = new GroupBox(); txtAddress = new TextBox(); cmbVarType = new ComboBox(); cmbType = new ComboBox(); txtIP = new TextBox(); txtPort = new TextBox(); lblPort = new Label(); lbVarType = new Label(); cmbIP = new ComboBox(); lblType = new Label(); lblAddress = new Label(); @@ -134,10 +136,12 @@ // grpSetting.BackColor = Color.FromArgb(32, 41, 50); grpSetting.Controls.Add(txtAddress); grpSetting.Controls.Add(cmbVarType); grpSetting.Controls.Add(cmbType); grpSetting.Controls.Add(txtIP); grpSetting.Controls.Add(txtPort); grpSetting.Controls.Add(lblPort); grpSetting.Controls.Add(lbVarType); grpSetting.Controls.Add(cmbIP); grpSetting.Controls.Add(lblType); grpSetting.Controls.Add(lblAddress); @@ -164,6 +168,17 @@ txtAddress.Size = new Size(124, 24); txtAddress.TabIndex = 9; txtAddress.TextChanged += txtAddress_TextChanged; // // cmbVarType // cmbVarType.DropDownStyle = ComboBoxStyle.DropDownList; cmbVarType.FormattingEnabled = true; cmbVarType.Location = new Point(533, 32); cmbVarType.Margin = new Padding(4); cmbVarType.Name = "cmbVarType"; cmbVarType.Size = new Size(124, 26); cmbVarType.TabIndex = 8; cmbVarType.SelectedIndexChanged += cmbVarType_SelectedIndexChanged; // // cmbType // @@ -201,6 +216,16 @@ lblPort.TabIndex = 4; lblPort.Text = "端å£"; // // lbVarType // lbVarType.AutoSize = true; lbVarType.Location = new Point(463, 35); lbVarType.Margin = new Padding(4, 0, 4, 0); lbVarType.Name = "lbVarType"; lbVarType.Size = new Size(68, 18); lbVarType.TabIndex = 0; lbVarType.Text = "åéç±»å"; // // cmbIP // cmbIP.FormattingEnabled = true; @@ -228,7 +253,7 @@ lblAddress.Name = "lblAddress"; lblAddress.Size = new Size(38, 18); lblAddress.TabIndex = 0; lblAddress.Text = "å°å"; lblAddress.Text = "åéå°å"; // // lblIP // LB_SmartVision/Forms/Pages/CommunicatorPage/CommunicatorForm.cs
@@ -28,10 +28,14 @@ { InitializeComponent(); cmbType.Items.Clear(); if (communicator != null && !string.IsNullOrEmpty(communicator.CommunicatorConnections["åå·"]?.ToString())) { cmbType.Items.Add(communicator.CommunicatorConnections["åå·"]?.ToString()); } cmbVarType.Items.Clear(); if (!string.IsNullOrEmpty(communicator.CommunicatorConnections["åéç±»å"]?.ToString())) { cmbVarType.Items.Add(communicator.CommunicatorConnections["åéç±»å"]?.ToString()); } } @@ -39,8 +43,9 @@ { InitializeComponent(); if (communicator == null) { return; } cmbIP.Enabled = false; txtIP.Enabled = false; txtPort.Enabled = false; @@ -56,23 +61,20 @@ this.Text = name; if (communicator is UARTPort) { //ç»è®¡å¯ç¨ç«¯å£ SerialPortStream temp = new SerialPortStream(); string[] ArryPort = temp.GetPortNames(); for (int i = 0; i < ArryPort.Length; i++) { cmbIP.Items.Add(ArryPort[i]); } cmbIP.Text = communicator.CommunicatorConnections["å°å"]?.ToString(); txtPort.Text = communicator.CommunicatorConnections["端å£"]?.ToString(); txtIP.Visible = false; cmbIP.Visible = true; this.btnRuleSend.Visible = true; lblType.Visible = false; lblAddress.Visible = false; cmbType.Visible = false; @@ -89,10 +91,7 @@ txtPort.Text = communicator.CommunicatorConnections["端å£"]?.ToString(); txtIP.Visible = true; cmbIP.Visible = false; this.btnRuleSend.Visible = false; lblType.Visible = false; lblAddress.Visible = false; cmbType.Visible = false; @@ -108,7 +107,6 @@ txtIP.Text = communicator.CommunicatorConnections["å°å"]?.ToString(); txtPort.Text = communicator.CommunicatorConnections["端å£"]?.ToString(); cmbType.Items.Clear(); if (!string.IsNullOrEmpty(communicator.CommunicatorConnections["åå·"]?.ToString())) { cmbType.Items.Add(communicator.CommunicatorConnections["åå·"]?.ToString()); @@ -130,7 +128,6 @@ txtIP.Visible = true; cmbIP.Visible = false; this.btnRuleSend.Visible = false; lblType.Visible = true; lblAddress.Visible = true; cmbType.Visible = true; @@ -313,5 +310,18 @@ communicatorChanged(communicator); } } private void cmbVarType_SelectedIndexChanged(object sender, EventArgs e) { if (communicator != null && !communicator.CommunicatorConnections.Contains("åéç±»å")) { communicator.CommunicatorConnections.Add("åéç±»å", cmbVarType.Text); } else if (communicator != null) { communicator.CommunicatorConnections["åéç±»å"] = cmbVarType.Text; communicatorChanged(communicator); } } } } LB_VisionProcesses/MotionControl/BaseMotionControl.cs
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,49 @@ using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace LB_VisionProcesses.MotionControl { public class BaseMotionControl : IMotionControl { /// <summary> /// è¿å¨æ§å¶åç§° /// </summary> public string MotionControlName { get; set; } = string.Empty; /// <summary> /// æ¯å¦è¿æ¥ /// </summary> public bool bConnected = true; public bool Connect() { throw new NotImplementedException(); } public bool Disconnect() { throw new NotImplementedException(); } public void Dispose() { throw new NotImplementedException(); } public string ReceiveMsg() { throw new NotImplementedException(); } public void SendHeartbeat() { throw new NotImplementedException(); } public bool SendMessage(string message) { throw new NotImplementedException(); } } } LB_VisionProcesses/MotionControl/IMotionControl.cs
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,42 @@ using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace LB_VisionProcesses.MotionControl { public interface IMotionControl : IDisposable { /// <summary> /// è¿æ¥é讯 /// </summary> /// <returns></returns> bool Connect(); /// <summary> /// æå¼è¿æ¥ /// </summary> /// <returns></returns> bool Disconnect(); /// <summary> /// æ¥æ¶æ¶æ¯ /// </summary> /// <returns></returns> string ReceiveMsg(); /// <summary> /// åéæ¶æ¯ /// </summary> /// <param name="message"></param> /// <returns></returns> bool SendMessage(string message); /// <summary> /// åéå¿è·³ä¿¡å· /// </summary> void SendHeartbeat(); } } LB_VisionProcesses/MotionControl/MotionControlConfig.cs
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,189 @@ using LB_VisionProcesses.Communicators; using Newtonsoft.Json; using Newtonsoft.Json.Serialization; using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; namespace LB_VisionProcesses.MotionControl { [Serializable] [Process("è¿å¨æ§å¶æ¨¡å", Category = "è¿å¨æ§å¶å·¥å ·", Description = "å建è¿å¨æ§å¶å·¥å ·")] public class MotionControlConfig : IProcess { /// <summary> /// è¿å¨æ§å¶æ¨¡åéå(Key:é讯åï¼Value:éè®¯å¥æ) /// </summary> public ConcurrentDictionary<string, BaseMotionControl> dicMotionControls { get; set; } /// <summary> /// é讯éå(Key:é讯åï¼Value:éè®¯å¥æ) /// </summary> public ConcurrentDictionary<string, BaseCommunicator> dicCommunicators { get; set; } public MotionControlConfig(ConcurrentDictionary<string, BaseMotionControl> dicMotionControl) { this.dicMotionControls = dicMotionControl; strProcessClass = "LB_VisionProcesses.Communicators.MotionControlConfig"; Params.Inputs.Add("è¿å¨æ§å¶åç§°", ""); //Params.Inputs.Add("Xè½´PLCå°å", ""); //Params.Inputs.Add("Xè½´æ£æµä½ç½®", ""); //Params.Inputs.Add("Yè½´PLCå°å", ""); //Params.Inputs.Add("Zè½´PLCå°å", ""); //Params.Inputs.Add("Wè½´PLCå°å", ""); Params.Outputs.Add("æ¶å°çä¿¡æ¯", ""); } public override object Clone() { return MemberwiseClone(); } public override void Dispose() { return; } public override void InitRunParams() { Result = true; Msg = ""; if (Record != null) { Record.Dispose(); } } /// <summary> /// å è½½ç®æ³ /// </summary> /// <param name="fullPath">宿´è·¯å¾å¸¦.json</param> /// <returns></returns> public override bool Load(string fullPath) { try { if (string.IsNullOrEmpty(fullPath)) return false; if (!fullPath.Contains(".json")) { Debug.WriteLine("æä»¶è·¯å¾ä¸å®æ´"); return false; } if (string.IsNullOrEmpty(fullPath) || fullPath.Trim() == "") { Debug.WriteLine("æä»¶è·¯å¾ä¸å®æ´"); return false; } // è·åä¸å¸¦æä»¶åçç®å½è·¯å¾ string directoryPath = Path.GetDirectoryName(fullPath); strProcessName = Path.GetFileNameWithoutExtension(fullPath); if (!File.Exists(fullPath)) { Debug.WriteLine("æä»¶ä¸åå¨å建空æä»¶"); Save(directoryPath); return true; } string strJson = string.Empty; using (StreamReader streamReader = new StreamReader(fullPath, Encoding.UTF8)) { strJson = streamReader.ReadToEnd(); streamReader.Close(); } Params = JsonConvert.DeserializeObject<ProcessParams>(strJson); if (Params == null) return false; Params.FixDeserializedData(); return true; } catch { return false; } } public override bool Run() { InitRunParams(); Params.Outputs["æ¶å°æ¶æ¯"] = ""; string MotionControlName = Params.Inputs["è¿å¨æ§å¶åç§°"].ToString(); if (!dicMotionControls.ContainsKey(MotionControlName)) { Msg = $"è¿å¨æ§å¶[{MotionControlName}]ä¸åå¨"; Result = false; return Result; } BaseMotionControl BaseMotionControl = dicMotionControls[MotionControlName]; if (BaseMotionControl == null) { Msg = $"è¿å¨æ§å¶[{MotionControlName}]æªå®ä¾å"; Result = false; return Result; } if (!BaseMotionControl.bConnected) { Msg = $"è¿å¨æ§å¶[{MotionControlName}]æªè¿æ¥"; Result = false; return Result; } return true; } /// <summary> /// ä¿åç®æ³ /// </summary> /// <param name="filePath">ä¸å¸¦.json</param> /// <returns></returns> public override bool Save(string filePath = null) { try { if (string.IsNullOrEmpty(filePath) || filePath.Trim() == "") { Debug.WriteLine("æä»¶è·¯å¾ä¸å®æ´"); return false; } string strJson = string.Empty; var settings = new JsonSerializerSettings { Formatting = Newtonsoft.Json.Formatting.Indented, // èªå®ä¹ç¼©è¿ï¼4ç©ºæ ¼ï¼ ContractResolver = new DefaultContractResolver { NamingStrategy = new CamelCaseNamingStrategy() } }; strJson = JsonConvert.SerializeObject(Params, settings); Params = JsonConvert.DeserializeObject<ProcessParams>(strJson); if (Params == null) return false; //夿æä»¶å¤¹æ¯å¦åå¨ï¼é²åè¾å ¥ä¸ºæä»¶åç§° if (!Directory.Exists(filePath)) { try { Directory.CreateDirectory(filePath); } catch (Exception) { } } File.WriteAllText(filePath + "//" + strProcessName + ".json", strJson, Encoding.UTF8); return true; } catch { return false; } } } }