Browse Source

最新版更新

WIN-GH9CEESPLTB\Administrator 4 months ago
parent
commit
be77378729

+ 443 - 0
MainForm/Atlas/AtlasScrew.cs

@@ -0,0 +1,443 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading;
+using MathNet.Numerics.RootFinding;
+using Newtonsoft.Json;
+
+namespace CommonLib
+{
+    public class AtlasScrew : BaseScrew
+    {
+        MTF6KConnStus connFlow = new MTF6KConnStus();
+        public TightResult tightResult = new TightResult();
+
+        string receiveMsg;
+
+        //连接状态
+        //public bool connectStaus = false;
+
+        public Thread MTF6KThread;
+
+        public AtlasScrew(object ip, object port, int connectTimeOut,int sendDataTimeOut,string direction)
+        {
+            Ip = ip.ToString();
+            Port = port.ToString();
+            ConnectTimeOut = connectTimeOut;
+            SendDataTimeOut = sendDataTimeOut;
+            IsCarriage = true;
+            IsShield = false;
+            Direction = direction;
+        }
+
+        /// <summary>
+        /// MTF6K连接流程结构体
+        /// </summary>
+        enum MTF6KConnStus
+        {
+            Idle,
+            Disconnect,
+            Connected,
+            CheckConnect,
+            SelectPSET,
+            CheckSelectPSET,
+            SelectBatch,
+            CheckSelectBatch,
+            SubscribeResult,
+            CheckSubscribeResult1,
+            CheckSubscribeResult2,
+            CheckSubscribeResult3,
+            SubscribeCurve,
+            CheckSubscribeCurve,
+            Ready,
+            UnsubcribeResult,
+            UnsubscribeCurve,
+        };
+
+        /// <summary>
+        /// 拧紧结果
+        /// </summary>
+        public class TightResult
+        {
+            public double[] torque;
+            public double[] angle;
+            public double torCoef = 0.0;
+            public double angCoef = 0.0;
+            public double PearkTorque = 0.0;//峰值扭矩
+            public double TotalAngle = 0.0;//总角度
+            public double TotalDuration;//总持续时间
+            public int ResultCode = 0;//结果代码
+
+            public TightResult()
+            {
+
+            }
+            public void Reset()
+            {
+                torCoef = 0.0;
+                angCoef = 0.0;
+                ResultCode = 0;
+                PearkTorque = 0.0;//峰值扭矩
+                TotalAngle = 0.0;//总角度
+                TotalDuration = 0.0;//总持续时间
+                MTF6K.isDataRecvFinish = false;
+            }
+
+        }
+        private Communicate TCP;
+        public override void Initial()
+        {
+            base.Initial();
+            try
+            {
+                // 如果线程已经存在,先关闭旧线程
+                if (MTF6KThread != null && MTF6KThread.IsAlive)
+                {
+                    MTF6KThread.Abort(); // 强制终止线程(注意:Abort 不推荐使用,建议改用信号机制)
+                    MTF6KThread = null;
+                }
+
+                // 如果 TCP 已经连接,先关闭连接
+                if (TCP != null)
+                {
+                    TCP.ConnectedResult -= new Communicate.ConnectResultEventHandler(Comm_ConnectedResult);
+                    TCP.MessageReceived -= new Communicate.MessageReceivedEventHandler(Comm_MessageReceived);
+                    TCP.closeSocket();
+                    TCP = null;
+                }
+
+                TCP = new Communicate("TCP1", Ip, Convert.ToInt32(Port));
+                TCP.FormOpening = true;
+                TCP.ConnectedResult += new Communicate.ConnectResultEventHandler(Comm_ConnectedResult);
+                TCP.MessageReceived += new Communicate.MessageReceivedEventHandler(Comm_MessageReceived);
+
+                MTF6KThread = new Thread(MTF6KFlow);
+                MTF6KThread.IsBackground = true;
+                MTF6KThread.Start();
+                IsOk = true;
+            }
+            catch (Exception)
+            {
+                IsOk = IsShield ? true : false;
+            }
+        }
+
+        /// <summary>
+        /// MTF6K -TCP连接状态
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
+        public void Comm_ConnectedResult(object sender, Communicate.ResultEventArgs e)
+        {
+            if (e.conResult)
+            {
+                connFlow = MTF6KConnStus.Connected;
+                connectStaus = true;
+
+            }
+            else
+            {
+                connectStaus = false;
+            }
+
+        }
+
+        /// <summary>
+        /// 接收数据-MTF6K
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
+        public void Comm_MessageReceived(object sender, Communicate.MessageEventArgs e)
+        {
+            if (connFlow == MTF6KConnStus.Ready)
+                MTF6K.ParseKerwords(e.byteMes, false);
+            else
+            {
+                MTF6K.ParseKerwords(e.byteMes, true);
+            }
+        }
+        /// <summary>
+        /// 连接MTF6K流程
+        /// </summary>
+        private void MTF6KFlow()
+        {
+            while (true)
+            {
+                Thread.Sleep(20);
+                while (connectStaus)
+                {
+                    Thread.Sleep(20);
+                    try
+                    {
+                        switch (connFlow)
+                        {
+                            case MTF6KConnStus.Idle:
+                                break;
+                            case MTF6KConnStus.Disconnect:
+                                {
+                                    TCP.SendMessage(MTF6K.disconnect);
+                                    connectStaus = false;
+                                    TCP.FormOpening = false;
+                                    TCP.ConnectedResult -= new Communicate.ConnectResultEventHandler(Comm_ConnectedResult);
+                                    TCP.MessageReceived -= new Communicate.MessageReceivedEventHandler(Comm_MessageReceived);
+                                    TCP.closeSocket();
+                                    TCP = null;
+                                }
+                                break;
+                            case MTF6KConnStus.Connected:
+                                TCP.SendMessage(MTF6K.disconnect);
+                                Thread.Sleep(20);
+                                TCP.SendMessage(MTF6K.connect);
+                                connFlow = MTF6KConnStus.CheckConnect;
+                                break;
+                            case MTF6KConnStus.CheckConnect:
+                                if (MTF6K.MID == "0002")
+                                {
+                                    TCP.SendMessage(MTF6K.keepAlive);
+                                    connFlow = MTF6KConnStus.SelectPSET;
+                                }
+                                else
+                                { }
+                                break;
+                            case MTF6KConnStus.SelectPSET:
+                                TCP.SendMessage(MTF6K.switchPSET1);
+                                connFlow = MTF6KConnStus.CheckSelectPSET;
+                                break;
+                            case MTF6KConnStus.CheckSelectPSET:
+                                if (MTF6K.MID == "0005")
+                                {
+                                    connFlow = MTF6KConnStus.SubscribeResult;
+                                }
+                                else if (MTF6K.MID == "0004")
+                                {
+                                    connFlow = MTF6KConnStus.SubscribeResult;
+                                }
+                                break;
+                            case MTF6KConnStus.SubscribeResult:
+                                TCP.SendMessage(MTF6K.subscribeTightingResult);
+                                connFlow = MTF6KConnStus.CheckSubscribeResult1;
+                                break;
+                            case MTF6KConnStus.CheckSubscribeResult1:
+                                if (MTF6K.MID == "1202")
+                                {
+                                    connFlow = MTF6KConnStus.SubscribeCurve;
+                                }
+                                else
+                                { }
+                                break;
+                            case MTF6KConnStus.SubscribeCurve:
+                                TCP.SendMessage(MTF6K.subscribeLastTightingCurve);
+                                connFlow = MTF6KConnStus.CheckSubscribeCurve;
+                                break;
+                            case MTF6KConnStus.CheckSubscribeCurve:
+                                if (MTF6K.MID == "0005")
+                                {
+                                    connFlow = MTF6KConnStus.Ready;
+                                }
+                                else
+                                { }
+                                break;
+                            case MTF6KConnStus.Ready:
+
+                                {
+                                    if (MTF6K.MID == "0901" && MTF6K.isDataRecvFinish == true)
+                                    {
+                                        MTF6K.MID = "error";
+                                        MTF6K.TightingResult.Convert(out tightResult.ResultCode, out tightResult.PearkTorque, out tightResult.TotalAngle, out tightResult.TotalDuration);
+                                        
+                                        tightResult.torque = new double[MTF6K.CurveResult.SampleCount];
+                                        tightResult.angle = new double[MTF6K.CurveResult.SampleCount];
+                                        MTF6K.CurveResult.Convert(out tightResult.torque, out tightResult.torCoef, out tightResult.angle, out tightResult.angCoef);
+                                        tightResult.PearkTorque = tightResult.PearkTorque / 98;
+                                       
+                                        #region
+                                        double preDegree = 0;
+                                        double curDegree = 0;
+                                        bool Step3 = false;
+                                        double PearkTorque = 0.0;
+                                        double Pearkdegree = 0.0;
+                                        double mindegree = 0;
+                                        double minvalue = 0;
+                                        JD.Clear();
+                                        NL.Clear();
+                                        List<double> pearkTorqueList = new List<double>(); // 存储 PearkTorque
+                                        List<double> pearkDegreeList = new List<double>(); // 存储 Pearkdegree
+                                        for (int i = 0; i < tightResult.angle.Length; i++)
+                                        {
+                                            double degree = tightResult.angle[i] * tightResult.angCoef;
+                                            double torque = tightResult.torque[i] * tightResult.torCoef / 98;
+                                            preDegree = curDegree;
+                                            curDegree = degree;
+                                            if (i > tightResult.angle.Length - 5 && torque <= 0)
+                                            {
+                                                continue;
+                                            }
+                                            JD.Add(Math.Round(degree,0).ToString());
+                                            NL.Add(Math.Round(torque,2).ToString());
+                                            //反转
+                                            if (curDegree - preDegree <= 0 && degree < 0)
+                                            {
+                                                if (torque > PearkTorque)
+                                                {
+                                                    PearkTorque = torque;
+                                                    Pearkdegree = degree;
+                                                }
+
+                                                if (torque < mindegree)
+                                                {
+                                                    mindegree = torque;
+                                                    minvalue = degree;
+                                                }
+
+                                            }
+                                            else if (curDegree - preDegree > 0)//正转
+                                            {
+                                                if (degree < 360 && !Step3)//切换扭矩值
+                                                {
+                                                    if (torque > PearkTorque)
+                                                    {
+                                                        PearkTorque = torque;
+                                                        Pearkdegree = degree;
+                                                    }
+                                                }
+                                                else
+                                                {
+                                                    Step3 = true;
+                                                    if (torque > PearkTorque)
+                                                    {
+                                                        PearkTorque = torque;
+                                                        Pearkdegree = degree;
+                                                    }
+                                                }
+                                            }
+                                            pearkTorqueList.Add(Math.Round(Pearkdegree)); // 添加到列表
+                                            pearkDegreeList.Add(Math.Round(PearkTorque, 2)); // 添加到列表
+                                        }
+                                        
+                                        //精度
+                                        JD_MEAN = Math.Round(Pearkdegree);
+                                        //扭力
+                                        NL_MEAN = Math.Round(PearkTorque, 2);
+                                        // 调用 AddData 方法,存储数据
+                                        AddData(JD_MEAN, NL_MEAN, pearkTorqueList.ToArray(), pearkDegreeList.ToArray());
+                                        #endregion
+                                    }
+                                }
+                                break;
+                            case MTF6KConnStus.UnsubscribeCurve:
+                                TCP.SendMessage(MTF6K.unsubscribeLastTightingCurve);
+                                break;
+                            case MTF6KConnStus.UnsubcribeResult:
+                                TCP.SendMessage(MTF6K.unsubscribeTightingResult);
+                                break;
+                        }
+                    }
+                    catch (Exception e)
+                    {
+                        //logHelper.WriteLog("阿特拉斯通讯异常:" + e.StackTrace);
+                    }
+                }
+            }
+        }
+         // 线程安全锁对象
+        private readonly object _queueLock = new object();
+        // 添加数据到缓存
+        private readonly Queue<(double JD_MEAN, double NL_MEAN, double[] PearkTorque, double[] Pearkdegree)> _dataQueueLeft = new Queue<(double JD_MEAN, double NL_MEAN, double[] PearkTorque, double[] Pearkdegree)>();
+        private readonly Queue<(double JD_MEAN, double NL_MEAN, double[] PearkTorque, double[] Pearkdegree)> _dataQueueRight = new Queue<(double JD_MEAN, double NL_MEAN, double[] PearkTorque, double[] Pearkdegree)>();
+
+        // 添加数据到缓存
+        public void AddData(double jdMean, double nlMean, double[] pearkTorque, double[] pearkDegree)
+        {
+            lock (_queueLock)
+            {
+                if (Direction == "Left")
+                {
+                    _dataQueueLeft.Enqueue((jdMean, nlMean, pearkTorque, pearkDegree));
+                }
+                else if (Direction == "Right")
+                {
+                    _dataQueueRight.Enqueue((jdMean, nlMean, pearkTorque, pearkDegree));
+                }
+            }
+        }
+
+        // 获取并清空缓存中的所有数据(左侧)
+        public IEnumerable<(double JD_MEAN, double NL_MEAN, double[] PearkTorque, double[] Pearkdegree)> GetCachedDataLeft()
+        {
+            lock (_queueLock)
+            {
+                var cachedData = _dataQueueLeft.ToList(); // 将当前队列内容复制到列表
+                _dataQueueLeft.Clear(); // 清空队列
+                return cachedData;
+            }
+        }
+
+        // 获取并清空缓存中的所有数据(右侧)
+        public IEnumerable<(double JD_MEAN, double NL_MEAN, double[] PearkTorque, double[] Pearkdegree)> GetCachedDataRight()
+        {
+            lock (_queueLock)
+            {
+                var cachedData = _dataQueueRight.ToList(); // 将当前队列内容复制到列表
+                _dataQueueRight.Clear(); // 清空队列
+                return cachedData;
+            }
+        }
+
+        public void DrawCurveDegTor()
+        {
+            double preDegree = 0;
+            double curDegree = 0;
+            bool Step3 = false;
+            double PearkTorque = 0.0;
+            double Pearkdegree = 0.0;
+            for (int i = 0; i < tightResult.angle.Length; i++)
+            {
+                double degree = tightResult.angle[i] * tightResult.angCoef;
+                double torque = tightResult.torque[i] * tightResult.torCoef / 98;
+                preDegree = curDegree;
+                curDegree = degree;
+
+                //反转
+                if (curDegree - preDegree <= 0 && degree < 0)
+                {
+
+                    if (torque > PearkTorque)
+                    {
+                        PearkTorque = torque;
+                        Pearkdegree = degree;
+                    }
+                }
+                else if (curDegree - preDegree > 0)//正转
+                {
+                    if (degree < 360 && !Step3)//切换扭矩值
+                    {
+
+                        if (torque > PearkTorque)
+                        {
+                            PearkTorque = torque;
+                            Pearkdegree = degree;
+                        }
+                    }
+                    else
+                    {
+                        Step3 = true;
+
+                        if (torque > PearkTorque)
+                        {
+                            PearkTorque = torque;
+                            Pearkdegree = degree;
+                        }
+                    }
+                    //bianliang.NL_MEAN = PearkTorque;
+                    //   bianliang.JD_MEAN = Pearkdegree;
+                }
+
+            }
+        }
+
+
+
+
+    }
+}

+ 117 - 0
MainForm/Atlas/BaseScrew.cs

@@ -0,0 +1,117 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net.Sockets;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+
+namespace CommonLib
+
+{
+    public class BaseScrew
+    {
+        
+        public string StationName { get; protected set; }
+        public string Name { get; protected set; }
+        public int IndexNo { get; protected set; }
+        public bool IsOk { get; set; }
+
+        //连接状态
+        public bool connectStaus = false;
+
+        /// <summary>
+        /// 参数
+        /// </summary>
+        public List<string> KeyParam { get; set; } = new List<string>();
+
+        /// <summary>
+        /// IP
+        /// </summary>
+        public string Ip { get; set; }
+        /// <summary>
+        /// 端口号
+        /// </summary>
+        public string Port { get; set; }
+
+
+        /// <summary>
+        /// 回车换行
+        /// </summary>
+        public bool IsCarriage { get; set; } = true;
+        /// <summary>
+        /// 连接超时
+        /// </summary>
+        public int ConnectTimeOut { get; set; } = 3000;
+        /// <summary>
+        /// 发送超时
+        /// </summary>
+        public int SendDataTimeOut { get; set; } = 3000;
+
+        /// <summary>
+        /// 是否屏蔽初始化结果
+        /// </summary>
+        public bool IsShield { get; set; } = false;
+
+        /// <summary>
+        /// 左右机台
+        /// </summary>
+        public string Direction { get; set; }
+
+
+        public  double NL_MEAN = 0;
+        public  double JD_MEAN = 0;
+        public double NL_MEAN1 = 0;
+        public double JD_MEAN1 = 0;
+        public double NL_MEAN2 = 0;
+        public double JD_MEAN2 = 0;
+        public List<string> NL = new List<string>();
+        public List<string> JD = new List<string>();
+        public virtual void Initial()
+        {
+            SetKeyParam();
+            SetParam();
+        }
+
+        public virtual void Close()
+        {
+
+        }
+
+        public virtual void Save()
+        {
+            //AppInfo.AppDeviceConfig.Save();
+            SetParam();
+        }
+
+        public virtual void SetKeyParam()
+        {
+
+        }
+
+        public virtual void SetParam()
+        {
+
+        }
+        /// <summary>
+        /// 开始发送
+        /// </summary>
+        public virtual void BeginSend()
+        {
+            
+            
+            //var recStr = codeSocketClient.SendString(StartTrigger, BarcodeLength);
+            //if (recStr.Length == BarcodeLength)
+            //    Barcode = recStr;
+            //else
+            //    //Barcode = Client.SendString(StartTrigger, BarcodeLength);
+            //    Barcode = codeSocketClient.SendString(StartTrigger, BarcodeLength);
+            //if (EndTrigger != "NO")
+            //    //Client.SendString(EndTrigger, 0);
+            //    codeSocketClient.SendString(EndTrigger, 0);
+
+        }
+
+    }
+}

+ 526 - 0
MainForm/Atlas/Communicate.cs

@@ -0,0 +1,526 @@
+using System;
+using System.Runtime.Serialization.Formatters.Binary;
+using System.IO;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Net;
+using System.Net.Sockets;
+
+namespace CommonLib
+{
+    public class Communicate
+    {
+        private Socket mySocket;
+        private IPEndPoint myIPEndPoint;
+        private byte[] tempByte = new byte[8];
+        private string receiveMess;
+        private NetPara _netPara;
+        public bool FormOpening = false;
+        public NetPara CommunicatePara
+        {
+            get { return this._netPara; }
+           
+        }
+
+        public string ReadMess
+        {
+            get
+            {
+                if (receiveMess != null)
+                {
+                    return this.receiveMess;
+                }
+                else
+                    return "0000000";
+            }
+        }
+
+        public string NetName
+        {
+            set;
+            get;
+        }
+
+        private bool conResult = false;
+
+        public delegate void ConnectResultEventHandler(object sender, ResultEventArgs e);
+
+        public delegate void MessageReceivedEventHandler(object sender, MessageEventArgs e);
+
+        public event MessageReceivedEventHandler MessageReceived;//接受到数据事件
+
+        public event ConnectResultEventHandler ConnectedResult;//连接成功事件
+
+
+        public Communicate(string commName,string ip,int port )
+        {
+            try
+            {
+                this.NetName = commName;
+                this._netPara = new NetPara(commName);
+                this.myIPEndPoint = new IPEndPoint(IPAddress.Parse(ip), port);
+                mySocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
+
+            }
+            catch (Exception ex)
+            {
+                System.Windows.Forms.MessageBox.Show("ERROR IP,Please reset." + ex.Message + ";" + ex.StackTrace);
+            }
+            System.Threading.Thread connectThread = new System.Threading.Thread(Connect);
+            connectThread.IsBackground = true;
+            connectThread.Start();
+
+            System.Threading.Thread receiveThread = new System.Threading.Thread(ReceiveMessage);
+            receiveThread.IsBackground = true;
+            receiveThread.Start();
+
+        }
+
+        public class ResultEventArgs : EventArgs
+        {
+            public readonly bool conResult;
+
+            public ResultEventArgs(bool conResult)
+            {
+                this.conResult = conResult;
+            }
+        }
+
+        public class MessageEventArgs : EventArgs
+        {
+            public readonly string Message;
+            public readonly byte[] byteMes;
+
+            public MessageEventArgs(string Message, byte[] byteMes)
+            {
+                this.Message = Message;
+                this.byteMes = byteMes;
+
+            }
+
+            //public MessageEventArgs(byte[] byteMes)
+            //{
+            //    this.byteMes = byteMes;
+            //}
+        }
+
+        public string IpAddress//定义属性--IP地址
+        {
+            set
+            {
+                this.myIPEndPoint.Address = IPAddress.Parse(value);
+            }
+            get
+            {
+                return this.myIPEndPoint.Address.ToString();
+            }
+
+        }
+
+        public int Port//定义属性--端口号
+        {
+            set
+            {
+                this.myIPEndPoint.Port = value;
+            }
+            get
+            {
+                return myIPEndPoint.Port;
+            }
+
+        }
+        int numberOfException = 0;
+        public void Connect()//尝试连接服务器或者客户端
+        {
+            while (true)
+            {
+
+
+                if (CommunicatePara.客户端Or服务器 == NetBehavior.Client)
+                {
+                    try
+                    {
+                        System.Threading.Thread.Sleep(300);
+                        mySocket.Connect(myIPEndPoint);
+                        conResult = true;
+                        ResultEventArgs e = new ResultEventArgs(conResult);
+                        ResultToDo(e);
+
+                        receiveMess = "";
+                        break;
+                    }
+                    catch
+                    {
+                        conResult = false;
+                        ResultEventArgs e = new ResultEventArgs(conResult);
+                        ResultToDo(e);
+                    }
+                }
+                else
+                {
+                    System.Threading.Thread.Sleep(500);
+                    try
+                    {
+                        this.mySocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
+                        myIPEndPoint.Address = IPAddress.Parse(this.IpAddress);
+                        mySocket.Bind(myIPEndPoint);
+                        mySocket.Listen(1);
+                        mySocket = mySocket.Accept();
+                        conResult = true;
+                        ResultEventArgs e = new ResultEventArgs(conResult);
+                        ResultToDo(e);
+                    }
+                    catch (Exception ex)
+                    {
+                        if ((ex is System.Net.Sockets.SocketException) && (numberOfException < 4))
+                        {
+                            if (mySocket.IsBound)
+                            {
+                                EndPoint edp = mySocket.RemoteEndPoint;
+                                mySocket.Shutdown(SocketShutdown.Both);
+                                mySocket.Close(100);
+                                Connect();
+                                numberOfException++;
+                            }
+                        }
+                        else
+                        {
+                            System.Windows.Forms.MessageBox.Show("网络可能没有成功连接,发送数据时出现错误!\n" + ex.ToString());
+                        }
+                    }
+                    return;
+                }
+
+            }
+
+        }
+
+        public void closeSocket()
+        {
+            if (!FormOpening)
+            {
+                if (this.mySocket.Connected)
+                {
+                    this.mySocket.Shutdown(SocketShutdown.Both);
+                }
+                if (this.mySocket != null)
+                {
+                    this.mySocket.Close(100);
+                    this.mySocket = null;
+                }
+            }
+        }
+
+        protected virtual void ResultToDo(ResultEventArgs e)
+        {
+            if (ConnectedResult != null)
+            {
+                ConnectedResult(this, e);
+            }
+        }
+
+
+        int headSize = 8;//包头长度 固定8
+        byte StopByte = 0x00;
+        int totalLen;
+        int bodySize;
+        int MID;
+        byte[] surplusBuffer = null;//完整的数据包
+        byte[] recvByte = null;//待发送的字节
+        public void ReceiveMessage()//接收数据
+        {
+            while (FormOpening)
+            {
+                System.Threading.Thread.Sleep(20);
+                if (mySocket != null)
+                {
+                    if (mySocket.Connected)
+                    {
+
+                        int numReceive = 0;
+                        try
+                        {
+                            if (surplusBuffer == null)
+                            {
+                                numReceive = mySocket.Receive(tempByte, SocketFlags.None);
+                            }
+                            else
+                            {
+                                numReceive = mySocket.Receive(surplusBuffer, SocketFlags.None);
+                            }
+
+                            if (numReceive == 0)
+                            {
+                                byte[] temp = Encoding.Default.GetBytes(" ");
+                                mySocket.Send(temp);
+                            }
+                        }
+                        catch
+                        {
+                            if (this.mySocket != null)
+                            {
+                                conResult = false;
+                                ResultEventArgs e = new ResultEventArgs(conResult);
+                                ResultToDo(e);
+                                if (this.mySocket.Connected)
+                                {
+                                    this.mySocket.Shutdown(SocketShutdown.Both);
+                                }
+
+                                this.mySocket.Close();
+                                this.mySocket = null;
+
+                                GC.Collect();
+                                this.mySocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
+                                System.Threading.Thread connectThread = new System.Threading.Thread(Connect);
+                                connectThread.IsBackground = true;
+                                connectThread.Priority = System.Threading.ThreadPriority.Normal;
+                                connectThread.Start();
+
+                            }
+                        }
+                        if (numReceive > 0)
+                        {
+                            if (numReceive == 1)
+                                continue;
+                            if (surplusBuffer == null)//判断是不是第一次接收,为空则是第一次
+                            {
+                                if (tempByte[0].Equals(0x00))
+                                {
+                                    bodySize = int.Parse(Encoding.ASCII.GetString(tempByte, 1, 4));//从包头里面分析出包体长度
+                                    surplusBuffer = new byte[bodySize - headSize + 1];
+                                    recvByte = new byte[headSize - 1];
+                                    Buffer.BlockCopy(tempByte, 1, recvByte, 0, headSize - 1);
+                                }
+                                else
+                                {
+                                    bodySize = int.Parse(Encoding.ASCII.GetString(tempByte, 0, 4));//从包头里面分析出包体长度
+                                    surplusBuffer = new byte[bodySize - headSize];
+                                    recvByte = tempByte;
+                                }
+
+                                //try
+                                //{
+                                //    bodySize = int.Parse(Encoding.ASCII.GetString(tempByte, 0, 4));//从包头里面分析出包体长度
+                                //    surplusBuffer = new byte[bodySize - headSize];
+                                //    recvByte = tempByte;
+                                //}
+                                //   catch
+                                //{
+                                //    bodySize = int.Parse(Encoding.ASCII.GetString(tempByte, 1, 4));//从包头里面分析出包体长度
+                                //    surplusBuffer = new byte[bodySize - headSize+1];
+                                //      recvByte = new byte[bodySize];
+                                //        Buffer.BlockCopy(tempByte, 1, recvByte, 0, headSize - 1);
+                                //}
+
+
+                                // }
+
+
+
+                            }
+                            else
+                            {
+                                // String receiveMess = bodySize.ToString("0000") + MID.ToString("0000") + Encoding.ASCII.GetString(surplusBuffer, 0, bodySize - headSize);
+                                recvByte = recvByte.Concat(surplusBuffer).ToArray();
+                                MessageEventArgs e = new MessageEventArgs(receiveMess, recvByte);
+
+                                if (MessageReceived != null)
+                                {
+                                    MessageReceived(this, e);
+                                }
+
+                                surplusBuffer = null;//设置空 回到原始状态
+                                recvByte = null;
+                                totalLen = 0;//清0
+                                bodySize = 0;
+                                MID = 0;
+
+                            }
+                        }
+
+
+                    }
+                }
+
+            }
+        }
+
+        public void SendMessage(string s)//发送数据
+        {
+
+            if (FormOpening)
+            {
+                if (mySocket != null)
+                {
+                    if (mySocket.Connected)
+                    {
+                        byte[] buffer = Encoding.Default.GetBytes(s);
+                        try
+                        {
+                            mySocket.Send(buffer, buffer.Length, SocketFlags.None);
+                        }
+                        catch
+                        {
+                            System.Windows.Forms.MessageBox.Show("网络可能没有成功连接,发送数据时出现错误!");
+                        }
+                    }
+                    else
+                    {
+
+                        if (mySocket.Connected)
+                        {
+                            byte[] buffer = Encoding.Default.GetBytes(s);
+                            try
+                            {
+                                mySocket.Send(buffer, buffer.Length, SocketFlags.None);
+                            }
+                            catch
+                            {
+                                System.Windows.Forms.MessageBox.Show("网络可能没有成功连接,发送数据时出现错误!");
+                            }
+                        }
+                        else
+                        {
+
+                            if (mySocket.Connected)
+                            {
+                                byte[] buffer = Encoding.Default.GetBytes(s);
+                                try
+                                {
+                                    mySocket.Send(buffer, buffer.Length, SocketFlags.None);
+                                }
+                                catch
+                                {
+                                    System.Windows.Forms.MessageBox.Show("网络可能没有成功连接,发送数据时出现错误!");
+                                }
+                            }
+                            else
+                            {
+                                System.Windows.Forms.MessageBox.Show("网络未连接!");
+                            }
+                        }
+                    }
+                }
+            }
+        }
+
+        ////public System.Windows.Forms.DialogResult SetPara()
+        ////{
+        ////    return new frmTcpIpConfig(this).ShowDialog();
+        ////}
+    }
+    [Serializable]
+    public enum NetBehavior
+    {
+        Server = 1, Client = 2
+    }
+
+    [Serializable]
+    public class NetPara
+    {
+        private string _ip = "192.168.0.16";
+        private int _port = 8080;
+        private NetBehavior _behavior = NetBehavior.Client;
+        private string _netParaName = System.Windows.Forms.Application.StartupPath + "\\dn.np";
+
+        public string Ip
+        {
+            get { return _ip; }
+            set { _ip = value; }
+        }
+        public int Port
+        {
+            get { return _port; }
+            set { _port = value; }
+        }
+        public NetBehavior 客户端Or服务器
+        {
+            set
+            {
+                this._behavior = value;
+            }
+            get
+            {
+                return this._behavior;
+            }
+        }
+        public string NetParaName
+        {
+            private set
+            {
+                this._netParaName = value;
+            }
+            get
+            {
+                return this._netParaName;
+            }
+        }
+
+        public void SetPara(string ip, int port, NetBehavior 客户端Or服务器)
+        {
+            try
+            {
+                this._ip = ip;
+                this._port = port;
+                this._behavior = 客户端Or服务器;
+            }
+            catch (Exception ex)
+            {
+                System.Windows.Forms.MessageBox.Show("ERROR\r\n" + ex.Message, "Set param...");
+            }
+        }
+
+        public void SavePara()
+        {
+            try
+            {
+                BinaryFormatter bf = new BinaryFormatter();
+                FileStream fs = new FileStream(_netParaName, FileMode.OpenOrCreate, FileAccess.Write);
+                bf.Serialize(fs, this);
+                fs.Flush();
+                fs.Close();
+                //System.Windows.Forms.MessageBox.Show("用户数据保存成功!", "用户保存...");
+            }
+            catch (Exception ex)
+            {
+                System.Windows.Forms.MessageBox.Show("Save fail!\r\n " + ex.Message, "Save param......");
+            }
+        }
+
+        public void IniPara()
+        {
+            //if (System.IO.File.Exists(_netParaName))
+            {
+                try
+                {
+                    //BinaryFormatter bf = new BinaryFormatter();
+                    //FileStream fs = new FileStream(_netParaName, FileMode.Open, FileAccess.Read);
+                    //NetPara netPara = (NetPara)bf.Deserialize(fs);
+                    //fs.Flush();
+                    //fs.Close();
+                    //this.Ip = netPara.Ip;
+                    //this.Port = netPara.Port;
+                    this.客户端Or服务器 = NetBehavior.Client;
+                    //this.NetParaName = netPara.NetParaName;
+                }
+                catch (Exception ex)
+                {
+                    System.Windows.Forms.MessageBox.Show("Init Fail!\r\n" + ex.Message, "Init...");
+                }
+            }
+        }
+
+        public NetPara(string paraName)
+        {
+            this._netParaName = string.Format("{0}\\{1}.np", System.Windows.Forms.Application.StartupPath, paraName);
+            IniPara();
+        }
+
+    }
+
+
+
+
+}

+ 326 - 0
MainForm/Atlas/MTF6K.cs

@@ -0,0 +1,326 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace CommonLib
+{  
+   public class MTF6K
+    {
+        public const string connect = "002000010060         ";
+        public const string keepAlive = "002099990010         ";
+        public const string switchPSET1 = "002300180010        001 ";
+        public const string switchPSET2 = "002300180010        002 ";
+        public const string switchPSET3 = "002300180010        003 ";
+        public const string switchBatch1 = "002400380020        0001 ";
+        public const string switchBatch2 = "002400380020        0002 ";
+        public const string switchBatch3 = "002400380020        0003 ";
+        public const string subscribeTightingResult = "006000080010        1201001310000000000000000000000000000001 ";
+        public const string subscribeLastTightingCurve = "006700080010        0900001380                             02001002 ";
+        public const string unsubscribeTightingResult = "002900090010        120100100 ";
+        public const string unsubscribeLastTightingCurve = "003700090010        09000010802001002 ";
+        public const string starttighting = "002302240010        001 ";
+        public const string startloosening = "002302240010        003 ";
+        public const string stoptighting = "002302240010        005 ";
+        public const string disconnect = "002000030010         ";
+        public static string MID;
+        public static int Length = 0;
+        public static string otherData;
+        public static bool isDataRecvFinish = false;
+        public static class TightingResult
+        {
+            public static string PearkTorque;//峰值扭矩
+            public static string TotalAngle;//总角度
+            public static string TotalDuration;//总持续时间
+            public static string ResultCode;//结果代码
+            public static string PearkTorque1;//峰值扭矩
+            public static string TotalAngle1;//总角度
+            public static void Convert(out int _ResultCode, out double _pearkTorque, out double _totalAngle, out double _totalDuration)
+            {
+                try
+                {
+                    _pearkTorque = double.Parse(PearkTorque);
+                    _totalAngle = double.Parse(TotalAngle);
+                    _totalDuration = double.Parse(TotalDuration);
+                    _ResultCode = int.Parse(ResultCode);
+                }
+
+                catch (Exception e)
+                {
+                    _pearkTorque = 0.0;
+                    _totalAngle = 0.0;
+                    _totalDuration = 0.0;
+                    //NOK
+                    _ResultCode = 3;
+                }
+            }
+        }
+        public static class CurveResult
+        {
+            public static string torCoef;//PID系数C-扭矩
+                                         // public static string torB;//值-扭矩
+            public static byte[] torBByte;//值-扭矩
+            public static string angCoef;//PID系数C-角度
+                                         // public static string angB;//值-角度
+            public static byte[] angBByte;//值-角度
+            public static string TraceType;
+            public static int SampleCount;//点个数
+            public static bool GetResult = false;
+            public static void Convert(out double[] _torBInt, out double _torCoef, out double[] _angBInt, out double _angCoef)
+            {
+                double[] res1 = new double[SampleCount];
+                double[] res2 = new double[SampleCount];
+                try
+                {
+                    byte[] tmp = new byte[SampleCount * 2];
+                    //tmp = Encoding.Default.GetBytes(angB);
+                    tmp = angBByte;
+                    int j = 0;
+                    for (int i = 0; i < SampleCount; i++)
+                    {
+                        //res1[i] = tmp[i + 1] * 16 + tmp[i];
+                        res1[i] = HexStringToDec(tmp[j + 1].ToString("x2") + tmp[j].ToString("x2")) * 1.0;
+                        j += 2;
+                    }
+                    _angBInt = res1;
+                    _angCoef = double.Parse(angCoef);
+                }
+                catch (Exception e)
+                {
+                    _angBInt = res1;
+                    _angCoef = 0.0;
+                }
+
+                try
+                {
+                    byte[] tmp = new byte[SampleCount * 2];//torB.Length
+                    //tmp = Encoding.Default.GetBytes(torB);
+                    tmp = torBByte;
+                    int j = 0;
+                    for (int i = 0; i < SampleCount; i++)//torB.Length
+                    {
+                        //res2[i] = tmp[i + 1] * 16 + tmp[i];
+                        res2[i] = HexStringToDec(tmp[1 + j].ToString("x2") + tmp[j].ToString("x2")) * 1.0;
+                        j += 2;
+                    }
+                    _torBInt = res2;
+                    _torCoef = double.Parse(torCoef);
+                }
+                catch (Exception e)
+                {
+                    _torBInt = res2;
+                    _torCoef = 0.0;
+                }
+                finally
+                {
+
+                    GetResult = true;
+                }
+            }
+        }
+
+        /// <summary> 
+        /// 十六进制转为负数
+
+        ///</summary>
+        ///<param name="strNumber"></param>
+        ///<returns></returns>
+        private static int HexStringToDec(string strNumber)
+        {
+
+            int iNegate = 0;
+
+            int iNumber = Convert.ToInt32(strNumber, 16);
+
+            if (iNumber > 32767)
+            {
+
+                int iComplement = iNumber - 1;
+
+                string strNegate = string.Empty;
+
+                char[] binChar = Convert.ToString(iComplement, 2).PadLeft(16, '0').ToArray();
+                foreach (char ch in binChar)
+                {
+                    //反转
+                    if (Convert.ToInt32(ch) == 48)
+                    {
+
+                        strNegate += "1";
+
+                    }
+
+                    else
+                    {
+
+                        strNegate += "0";
+
+                    }
+
+                }
+
+                iNegate = -Convert.ToInt32(strNegate, 2);
+
+            }
+            else
+            {
+                iNegate = iNumber;
+            }
+
+
+
+            return iNegate;
+
+        }
+
+
+
+        /// <summary>
+        /// 对接收到的数据进行解析
+        /// </summary>
+        /// <param name="keywords"></param>
+        /// <returns></returns>
+        public static void ParseKerwords(byte[] bytes, bool isConnMTF6K)
+        {
+            //var dl = DebugLabel.解析MID_PID;
+            string words = Encoding.ASCII.GetString(bytes);
+            if (!isConnMTF6K)
+            {
+                try
+                {
+                    MID = words.Substring(4, 4);
+                    Length = int.Parse(words.Substring(0, 4));
+                    if (MID == "1202")
+                    {
+
+                        TightingResult.ResultCode = words.Substring(106, 1);
+                        TightingResult.PearkTorque = words.Substring(709, 100);
+                        TightingResult.TotalAngle = words.Substring(755, 12);
+                        TightingResult.TotalDuration = words.Substring(814, 12);
+                        //bianliang.NL_MEAN = Convert.ToDouble(TightingResult.PearkTorque);
+                        //bianliang.JD_MEAN = Convert.ToDouble(TightingResult.TotalAngle);
+                        //bianliang.Sls_time = Convert.ToDouble(TightingResult.TotalDuration);
+                        //TightingResult.ResultCode = words.Substring(106, 1);
+                        //TightingResult.PearkTorque = words.Substring(709, 12);
+                        //TightingResult.TotalAngle = words.Substring(738, 12);
+                        //TightingResult.TotalDuration = words.Substring(767, 12);
+
+                        string[] Timestr = words.Substring(words.IndexOf("30232") + 15, 14).Split(new string[] { "e" }, StringSplitOptions.RemoveEmptyEntries);
+                        int timemulti = Convert.ToInt32(Timestr[1]);
+                        double time = Convert.ToDouble(Timestr[0]);
+                        //bianliang.Sls_time = time * Math.Pow(10, timemulti);
+
+                        //bianliang.Sls_time = Convert.ToDouble(words.Substring(words.IndexOf("30232") + 15, 10));
+
+                        string[] JDstr = words.Substring(words.IndexOf("30231") + 15, 14).Split(new string[] { "e" }, StringSplitOptions.RemoveEmptyEntries);
+                        int jdmulti = Convert.ToInt32(JDstr[1]);
+                        double jd = Convert.ToDouble(JDstr[0]);
+                        //AtlasScrew.JD_MEAN = jd * Math.Pow(10, jdmulti);
+                        //AppLog.Record("我的角度" + jd * Math.Pow(10, jdmulti));
+                        string[] NLstr = words.Substring(words.IndexOf("30237") + 15, 14).Split(new string[] { "e" }, StringSplitOptions.RemoveEmptyEntries);
+                        int nlmulti = Convert.ToInt32(NLstr[1]);
+                        double nl = Convert.ToDouble(NLstr[0]);
+                        //AtlasScrew.NL_MEAN = nl * Math.Pow(10, nlmulti);
+                        //AppLog.Record("我的扭力" + nl * Math.Pow(10, nlmulti));
+                        //bianliang.PLCWriteData(66, "Real", bianliang.NL_MEAN.ToString("f3"));
+                        //bianliang.PLCWriteData(70, "Real", bianliang.JD_MEAN.ToString("f3"));
+                        //bianliang.PLCWriteData(74, "Real", bianliang.Sls_time.ToString("f3"));
+                        TightingResult.PearkTorque1 = Math.Round(nl * Math.Pow(10, nlmulti),2).ToString();
+                        TightingResult.TotalAngle1 = Math.Round(jd * Math.Pow(10, jdmulti), 0).ToString();
+
+                    }
+                    else if (MID == "0900")
+                    {
+                        CurveResult.TraceType = words.Substring(81, 2);
+                        if (CurveResult.TraceType == "01")
+                        {
+                            CurveResult.SampleCount = Convert.ToInt16(words.Substring(124, 5));
+                            CurveResult.angCoef = words.Substring(69, 12);
+                            //CurveResult.angB = words.Substring(130);//数据;
+                            CurveResult.angBByte = new byte[CurveResult.SampleCount * 2];
+                            Buffer.BlockCopy(bytes, 130, CurveResult.angBByte, 0, CurveResult.SampleCount * 2);
+                        }
+
+                        if (CurveResult.TraceType == "02")
+                        {
+                            CurveResult.SampleCount = Convert.ToInt16(words.Substring(124, 5));
+                            CurveResult.torCoef = words.Substring(69, 12);
+                            // CurveResult.torB = words.Substring(130);//数据;
+                            CurveResult.torBByte = new byte[CurveResult.SampleCount * 2];
+                            Buffer.BlockCopy(bytes, 130, CurveResult.torBByte, 0, CurveResult.SampleCount * 2);
+                            isDataRecvFinish = true;
+                        }
+                    }
+                }
+                catch (Exception e)
+                {
+
+                }
+            }
+            else
+            {
+                if (words.Length == 24)
+                {
+                    try
+                    {
+                        MID = words.Substring(4, 4);
+                        //keywords.LengthStr = words.Substring(0, 4);
+                        //keywords.MID = int.Parse(words.Substring(4, 4));
+                        //keywords.Version = int.Parse(words.Substring(8, 3));
+                        otherData = words.Substring(20, 4);
+                    }
+                    catch
+                    {
+                        MID = "Error";
+                    }
+                }
+                else
+                {
+                    try
+                    {
+                        MID = words.Substring(4, 4);
+                    }
+                    catch
+                    {
+                        MID = "Error";
+                    }
+                }
+            }
+        }
+
+        /// <summary>
+        /// 对接收到的数据进行解析
+        /// </summary>
+        /// <param name="keywords"></param>
+        /// <returns></returns>
+        public static void ParseKerwords2(string words)
+        {
+            if (words.Length>8)
+            {
+                try
+                {
+                    MID = words.Substring(4, 4);
+                    Length = int.Parse(words.Substring(0, 4));
+                }
+                catch (Exception e)
+                {
+
+                }
+            }
+            else
+            {
+                
+                    try
+                    {
+                        MID = "Error";
+                    }
+                    catch
+                    {
+                        MID = "Error";
+                    }
+                
+            }
+        }
+    }
+}

+ 142 - 4
MainForm/ClassFile/Inovance_EIP.cs

@@ -11,6 +11,7 @@ using System.Runtime.Serialization;
 using System.Security.Policy;
 using System.Text;
 using System.Text.RegularExpressions;
+using System.Threading.Tasks;
 using System.Windows.Forms;
 using System.Xml.Linq;
 using static System.Net.Mime.MediaTypeNames;
@@ -393,7 +394,7 @@ namespace EIP_Protocol
 
     public class Inovance_EIP
     {
-        private string strTagPrefix = "Application.GVL.";  //标签前缀
+        private string strTagPrefix = "Application.GVL.";  //标签前缀,80站是Application.GVL_HMI.,不知道为什么反正就是这样
         private object m_objLock = new object();
         bool isStart = false;
         string strClaimedComputerIP = "";   //PC的IP地址 - private实际IP
@@ -2850,13 +2851,149 @@ namespace EIP_Protocol
         /// <param name="nCount">读取标签的个数</param>
         /// <param name="outObj">返回相应标签值对象</param>
         /// <returns></returns>
+
+        public (int, string) Read_SingleTag<T>(string strTagName, int nCount, out T outObj, Control uiControl)
+        {
+            // 初始化输出参数
+            outObj = default(T);
+            byte[] pBuf = null;
+            int nRet = 0;
+            string strRet = "";
+
+            try
+            {
+                // 创建一个标志变量,用于判断是否需要显示提示框
+                bool isProcessingDialogShown = false;
+
+                // 启动一个后台任务执行核心逻辑
+                Task<(int, string)> readTask = Task.Run(() =>
+                {
+                    return Read_Tag(strTagPrefix + strTagName, nCount, out pBuf);
+                });
+
+                // 启动一个计时器任务,用于检测是否超过 5 秒
+                Task delayTask = Task.Delay(5000);
+
+                // 等待两个任务中的任意一个完成
+                Task completedTask = Task.WhenAny(readTask, delayTask).Result;
+
+                if (completedTask == delayTask)
+                {
+                    // 如果超时,则显示提示框
+                    ShowProcessingDialog(uiControl);
+                    isProcessingDialogShown = true;
+
+                    // 继续等待读取任务完成
+                    readTask.Wait();
+                }
+
+                // 获取读取结果
+                (nRet, strRet) = readTask.Result;
+
+                // 检查类型并处理数据
+                string str = typeof(T).Name;
+                string[] substrings = { "Boolean", "SByte", "Byte", "Int16", "UInt16", "Int32", "UInt32", "Int64", "UInt64", "Single", "Double", "String" };
+
+                bool containsAny = substrings.Any(substring => str.Contains(substring));
+                if (containsAny)
+                {
+                    if (str != strRet) return (120, "变量类型不一致");
+                }
+
+                if (str == "String")
+                {
+                    outObj = (T)(object)System.Text.Encoding.UTF8.GetString(pBuf);
+                }
+                else
+                {
+                    outObj = (T)ByteToStruct(pBuf, typeof(T));
+                }
+
+                // 如果显示了提示框,则关闭它
+                if (isProcessingDialogShown)
+                {
+                    CloseProcessingDialog(uiControl);
+                }
+            }
+            catch (Exception ex)
+            {
+                // 异常处理
+                return (110, ex.ToString());
+            }
+
+            return (nRet, "OK");
+        }
+
+        private Form _processingForm;
+
+        private void ShowProcessingDialog(Control uiControl)
+        {
+            if (uiControl == null)
+            {
+                throw new ArgumentNullException(nameof(uiControl), "UI 控件不能为空。");
+            }
+
+            // 确保在主线程上更新 UI
+            if (uiControl.InvokeRequired)
+            {
+                uiControl.Invoke(new Action(() => ShowProcessingDialog(uiControl)));
+                return;
+            }
+
+            // 创建并显示提示框
+            Form processingForm = new Form
+            {
+                Text = "请稍候",
+                Size = new Size(300, 100),
+                StartPosition = FormStartPosition.CenterScreen,
+                FormBorderStyle = FormBorderStyle.FixedDialog,
+                ControlBox = false,
+                TopMost = true
+            };
+
+            Label label = new Label
+            {
+                Text = "正在读取中,请稍后...",
+                Dock = DockStyle.Fill,
+                TextAlign = ContentAlignment.MiddleCenter
+            };
+
+            processingForm.Controls.Add(label);
+            processingForm.Show();
+
+            // 保存提示框引用以便后续关闭
+            _processingForm = processingForm;
+        }
+
+        private void CloseProcessingDialog(Control uiControl)
+        {
+            if (uiControl == null)
+            {
+                return;
+            }
+
+            // 确保在主线程上更新 UI
+            if (uiControl.InvokeRequired)
+            {
+                uiControl.Invoke(new Action(() => CloseProcessingDialog(uiControl)));
+                return;
+            }
+
+            // 关闭提示框
+            _processingForm?.Close();
+            _processingForm = null;
+        }
+
+
+
+        /*
         public (int, string) Read_SingleTag<T>(string strTagName, int nCount, out T outObj)
         {
             outObj = default(T);
             byte[] pBuf = null;
             int nRet = 0;
             string strRet = "";
-            try 
+            try
             {
                 (nRet, strRet) = Read_Tag(strTagPrefix + strTagName, nCount, out pBuf);
                 if (nRet != 0) return (nRet, strRet);
@@ -2877,12 +3014,13 @@ namespace EIP_Protocol
                 }
                 outObj = (T)ByteToStruct(pBuf, typeof(T));
             }
-            catch(Exception ex)
+            catch (Exception ex)
             {
                 return (110, ex.ToString());
             }
             return (0, "OK");
-        }
+        }*/
+
 
         public (int, string) Write_SingleTag<T>(string strTagName, int nCount, T inObj)
         {

+ 8 - 0
MainForm/ClassFile/ProjectClass/GlobalContext.cs

@@ -107,6 +107,9 @@ namespace MainForm
         public static string PC8Address;
         public static string PC9Address;
         public static int MachinePort;
+        public static string AtlasAddressLeft;
+        public static string AtlasAddressRight;
+        public static int AtlasAddressPort;
 
         // TCP
         public static string QrCodeTCPAddress1;
@@ -320,6 +323,11 @@ namespace MainForm
                 PC8Address = IniFile.INIGetStringValue(FilePath, "Machine", "Pc8Address", ConstPc8Address);
                 PC9Address = IniFile.INIGetStringValue(FilePath, "Machine", "Pc9Address", ConstPc9Address);
                 MachinePort = int.Parse(IniFile.INIGetStringValue(FilePath, "Machine", "MachinePort", ConstMachinePort));
+                AtlasAddressLeft = IniFile.INIGetStringValue(FilePath, "Machine", "AtlasAddressLeft", "");
+                AtlasAddressRight = IniFile.INIGetStringValue(FilePath, "Machine", "AtlasAddressRight", "");
+                AtlasAddressPort = int.Parse(IniFile.INIGetStringValue(FilePath, "Machine", "AtlasAddressPort", ""));
+
+
 
                 QrCodeTCPAddress1 = IniFile.INIGetStringValue(FilePath, "TCP", "TCPAddress1", "127.0.0.1");
                 QrCodeTCPPort1 = int.Parse(IniFile.INIGetStringValue(FilePath, "TCP", "TCPPort1", "0"));

+ 1 - 1
MainForm/Config.ini

@@ -149,6 +149,6 @@ TCPAddress5=127.0.0.1
 TCPPort5=0
 
 [LocalDB]  ; 数据库配置
-Server=192.168.2.73
+Server=localhost
 User=sa
 PassWord=Aa123456

File diff suppressed because it is too large
+ 692 - 295
MainForm/FaForm/Form_Home.cs


+ 53 - 58
MainForm/FaForm/Form_Main.Designer.cs

@@ -23,8 +23,8 @@
         #region Windows 窗体设计器生成的代码
 
         /// <summary>
-        /// Required method for Designer support - do not modify
-        /// the contents of this method with the code editor.
+        /// 设计器支持所需的方法 - 不要修改
+        /// 使用代码编辑器修改此方法的内容。
         /// </summary>
         private void InitializeComponent()
         {
@@ -38,6 +38,8 @@
             this.toolStripStatusLabel_user = new System.Windows.Forms.ToolStripStatusLabel();
             this.imageList1 = new System.Windows.Forms.ImageList(this.components);
             this.panel2 = new System.Windows.Forms.Panel();
+            this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
+            this.timer1 = new System.Windows.Forms.Timer(this.components);
             this.btnMES = new System.Windows.Forms.Button();
             this.Btn_DevAlarm = new System.Windows.Forms.Button();
             this.btnOrder = new System.Windows.Forms.Button();
@@ -48,31 +50,34 @@
             this.button_Login = new System.Windows.Forms.Button();
             this.button_SystemSet = new System.Windows.Forms.Button();
             this.button_Alarm = new System.Windows.Forms.Button();
-            this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
-            this.timer1 = new System.Windows.Forms.Timer(this.components);
             this.statusStrip1.SuspendLayout();
             this.panel2.SuspendLayout();
             this.SuspendLayout();
             // 
             // panelMain
             // 
-            this.panelMain.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right)));
+            this.panelMain.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
+            | System.Windows.Forms.AnchorStyles.Left) 
+            | System.Windows.Forms.AnchorStyles.Right)));
             this.panelMain.BackColor = System.Drawing.Color.WhiteSmoke;
-            this.panelMain.Location = new System.Drawing.Point(2, 98);
-            this.panelMain.Margin = new System.Windows.Forms.Padding(4);
+            this.panelMain.Location = new System.Drawing.Point(1, 65);
             this.panelMain.Name = "panelMain";
-            this.panelMain.Size = new System.Drawing.Size(1610, 916);
+            this.panelMain.Size = new System.Drawing.Size(1073, 611);
             this.panelMain.TabIndex = 1;
             // 
             // statusStrip1
             // 
             this.statusStrip1.ImageScalingSize = new System.Drawing.Size(20, 20);
-            this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.toolStripStatusLabel1, this.toolStripStatusLabel_Time, this.toolStripStatusLabel2, this.toolStripStatusLabel_user });
+            this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
+            this.toolStripStatusLabel1,
+            this.toolStripStatusLabel_Time,
+            this.toolStripStatusLabel2,
+            this.toolStripStatusLabel_user});
             this.statusStrip1.LayoutStyle = System.Windows.Forms.ToolStripLayoutStyle.HorizontalStackWithOverflow;
-            this.statusStrip1.Location = new System.Drawing.Point(0, 1022);
+            this.statusStrip1.Location = new System.Drawing.Point(0, 679);
             this.statusStrip1.Name = "statusStrip1";
-            this.statusStrip1.Padding = new System.Windows.Forms.Padding(3, 0, 34, 0);
-            this.statusStrip1.Size = new System.Drawing.Size(1626, 30);
+            this.statusStrip1.Padding = new System.Windows.Forms.Padding(2, 0, 23, 0);
+            this.statusStrip1.Size = new System.Drawing.Size(1084, 22);
             this.statusStrip1.TabIndex = 2;
             this.statusStrip1.Text = "statusStrip1";
             // 
@@ -80,19 +85,19 @@
             // 
             this.toolStripStatusLabel1.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;
             this.toolStripStatusLabel1.Name = "toolStripStatusLabel1";
-            this.toolStripStatusLabel1.Size = new System.Drawing.Size(82, 25);
+            this.toolStripStatusLabel1.Size = new System.Drawing.Size(56, 17);
             this.toolStripStatusLabel1.Text = "小米汽车";
             // 
             // toolStripStatusLabel_Time
             // 
             this.toolStripStatusLabel_Time.Alignment = System.Windows.Forms.ToolStripItemAlignment.Right;
             this.toolStripStatusLabel_Time.Name = "toolStripStatusLabel_Time";
-            this.toolStripStatusLabel_Time.Size = new System.Drawing.Size(0, 25);
+            this.toolStripStatusLabel_Time.Size = new System.Drawing.Size(0, 17);
             // 
             // toolStripStatusLabel2
             // 
             this.toolStripStatusLabel2.Name = "toolStripStatusLabel2";
-            this.toolStripStatusLabel2.Size = new System.Drawing.Size(100, 25);
+            this.toolStripStatusLabel2.Size = new System.Drawing.Size(68, 17);
             this.toolStripStatusLabel2.Text = "当前用户:";
             // 
             // toolStripStatusLabel_user
@@ -100,7 +105,7 @@
             this.toolStripStatusLabel_user.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
             this.toolStripStatusLabel_user.ForeColor = System.Drawing.SystemColors.MenuHighlight;
             this.toolStripStatusLabel_user.Name = "toolStripStatusLabel_user";
-            this.toolStripStatusLabel_user.Size = new System.Drawing.Size(66, 25);
+            this.toolStripStatusLabel_user.Size = new System.Drawing.Size(44, 17);
             this.toolStripStatusLabel_user.Text = "操作员";
             // 
             // imageList1
@@ -163,7 +168,8 @@
             // 
             // panel2
             // 
-            this.panel2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right)));
+            this.panel2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
+            | System.Windows.Forms.AnchorStyles.Right)));
             this.panel2.BackColor = System.Drawing.Color.WhiteSmoke;
             this.panel2.Controls.Add(this.btnMES);
             this.panel2.Controls.Add(this.Btn_DevAlarm);
@@ -175,12 +181,16 @@
             this.panel2.Controls.Add(this.button_Login);
             this.panel2.Controls.Add(this.button_SystemSet);
             this.panel2.Controls.Add(this.button_Alarm);
-            this.panel2.Location = new System.Drawing.Point(2, 6);
-            this.panel2.Margin = new System.Windows.Forms.Padding(4);
+            this.panel2.Location = new System.Drawing.Point(1, 4);
             this.panel2.Name = "panel2";
-            this.panel2.Size = new System.Drawing.Size(1610, 82);
+            this.panel2.Size = new System.Drawing.Size(1073, 55);
             this.panel2.TabIndex = 3;
             // 
+            // timer1
+            // 
+            this.timer1.Interval = 1800000;
+            this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
+            // 
             // btnMES
             // 
             this.btnMES.BackColor = System.Drawing.Color.WhiteSmoke;
@@ -188,10 +198,9 @@
             this.btnMES.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
             this.btnMES.ImageIndex = 51;
             this.btnMES.ImageList = this.imageList1;
-            this.btnMES.Location = new System.Drawing.Point(522, 6);
-            this.btnMES.Margin = new System.Windows.Forms.Padding(4);
+            this.btnMES.Location = new System.Drawing.Point(348, 4);
             this.btnMES.Name = "btnMES";
-            this.btnMES.Size = new System.Drawing.Size(75, 72);
+            this.btnMES.Size = new System.Drawing.Size(50, 48);
             this.btnMES.TabIndex = 7;
             this.toolTip1.SetToolTip(this.btnMES, "MES手动交互");
             this.btnMES.UseVisualStyleBackColor = false;
@@ -203,10 +212,9 @@
             this.Btn_DevAlarm.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
             this.Btn_DevAlarm.ImageIndex = 0;
             this.Btn_DevAlarm.ImageList = this.imageList1;
-            this.Btn_DevAlarm.Location = new System.Drawing.Point(351, 4);
-            this.Btn_DevAlarm.Margin = new System.Windows.Forms.Padding(4);
+            this.Btn_DevAlarm.Location = new System.Drawing.Point(234, 3);
             this.Btn_DevAlarm.Name = "Btn_DevAlarm";
-            this.Btn_DevAlarm.Size = new System.Drawing.Size(75, 72);
+            this.Btn_DevAlarm.Size = new System.Drawing.Size(50, 48);
             this.Btn_DevAlarm.TabIndex = 6;
             this.toolTip1.SetToolTip(this.Btn_DevAlarm, "设备报警统计面板");
             this.Btn_DevAlarm.UseVisualStyleBackColor = false;
@@ -218,10 +226,9 @@
             this.btnOrder.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
             this.btnOrder.ImageIndex = 47;
             this.btnOrder.ImageList = this.imageList1;
-            this.btnOrder.Location = new System.Drawing.Point(183, 4);
-            this.btnOrder.Margin = new System.Windows.Forms.Padding(4);
+            this.btnOrder.Location = new System.Drawing.Point(122, 3);
             this.btnOrder.Name = "btnOrder";
-            this.btnOrder.Size = new System.Drawing.Size(75, 72);
+            this.btnOrder.Size = new System.Drawing.Size(50, 48);
             this.btnOrder.TabIndex = 5;
             this.toolTip1.SetToolTip(this.btnOrder, "订单维护");
             this.btnOrder.UseVisualStyleBackColor = false;
@@ -234,10 +241,9 @@
             this.btnPLCDB.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
             this.btnPLCDB.ImageIndex = 49;
             this.btnPLCDB.ImageList = this.imageList1;
-            this.btnPLCDB.Location = new System.Drawing.Point(436, 6);
-            this.btnPLCDB.Margin = new System.Windows.Forms.Padding(4);
+            this.btnPLCDB.Location = new System.Drawing.Point(291, 4);
             this.btnPLCDB.Name = "btnPLCDB";
-            this.btnPLCDB.Size = new System.Drawing.Size(75, 72);
+            this.btnPLCDB.Size = new System.Drawing.Size(50, 48);
             this.btnPLCDB.TabIndex = 4;
             this.toolTip1.SetToolTip(this.btnPLCDB, "PLC交互");
             this.btnPLCDB.UseVisualStyleBackColor = false;
@@ -251,10 +257,9 @@
             this.button_Home.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
             this.button_Home.ImageIndex = 8;
             this.button_Home.ImageList = this.imageList1;
-            this.button_Home.Location = new System.Drawing.Point(96, 3);
-            this.button_Home.Margin = new System.Windows.Forms.Padding(4);
+            this.button_Home.Location = new System.Drawing.Point(64, 2);
             this.button_Home.Name = "button_Home";
-            this.button_Home.Size = new System.Drawing.Size(75, 72);
+            this.button_Home.Size = new System.Drawing.Size(50, 48);
             this.button_Home.TabIndex = 3;
             this.toolTip1.SetToolTip(this.button_Home, "首页");
             this.button_Home.UseVisualStyleBackColor = false;
@@ -266,10 +271,9 @@
             this.Openfile.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
             this.Openfile.ImageIndex = 46;
             this.Openfile.ImageList = this.imageList1;
-            this.Openfile.Location = new System.Drawing.Point(606, 6);
-            this.Openfile.Margin = new System.Windows.Forms.Padding(4);
+            this.Openfile.Location = new System.Drawing.Point(404, 4);
             this.Openfile.Name = "Openfile";
-            this.Openfile.Size = new System.Drawing.Size(75, 72);
+            this.Openfile.Size = new System.Drawing.Size(50, 48);
             this.Openfile.TabIndex = 2;
             this.toolTip1.SetToolTip(this.Openfile, "日志文件");
             this.Openfile.UseVisualStyleBackColor = false;
@@ -282,10 +286,9 @@
             this.button_Other.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
             this.button_Other.ImageIndex = 41;
             this.button_Other.ImageList = this.imageList1;
-            this.button_Other.Location = new System.Drawing.Point(1508, 9);
-            this.button_Other.Margin = new System.Windows.Forms.Padding(4);
+            this.button_Other.Location = new System.Drawing.Point(1005, 6);
             this.button_Other.Name = "button_Other";
-            this.button_Other.Size = new System.Drawing.Size(75, 72);
+            this.button_Other.Size = new System.Drawing.Size(50, 48);
             this.button_Other.TabIndex = 2;
             this.button_Other.UseVisualStyleBackColor = true;
             this.button_Other.Click += new System.EventHandler(this.button_vision_Click);
@@ -298,10 +301,9 @@
             this.button_Login.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
             this.button_Login.ImageIndex = 15;
             this.button_Login.ImageList = this.imageList1;
-            this.button_Login.Location = new System.Drawing.Point(12, 3);
-            this.button_Login.Margin = new System.Windows.Forms.Padding(4);
+            this.button_Login.Location = new System.Drawing.Point(8, 2);
             this.button_Login.Name = "button_Login";
-            this.button_Login.Size = new System.Drawing.Size(75, 72);
+            this.button_Login.Size = new System.Drawing.Size(50, 48);
             this.button_Login.TabIndex = 0;
             this.toolTip1.SetToolTip(this.button_Login, "用户登录");
             this.button_Login.UseVisualStyleBackColor = false;
@@ -314,10 +316,9 @@
             this.button_SystemSet.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
             this.button_SystemSet.ImageIndex = 17;
             this.button_SystemSet.ImageList = this.imageList1;
-            this.button_SystemSet.Location = new System.Drawing.Point(690, 6);
-            this.button_SystemSet.Margin = new System.Windows.Forms.Padding(4);
+            this.button_SystemSet.Location = new System.Drawing.Point(460, 4);
             this.button_SystemSet.Name = "button_SystemSet";
-            this.button_SystemSet.Size = new System.Drawing.Size(75, 72);
+            this.button_SystemSet.Size = new System.Drawing.Size(50, 48);
             this.button_SystemSet.TabIndex = 0;
             this.toolTip1.SetToolTip(this.button_SystemSet, "软件设置");
             this.button_SystemSet.UseVisualStyleBackColor = false;
@@ -329,32 +330,25 @@
             this.button_Alarm.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
             this.button_Alarm.ImageIndex = 3;
             this.button_Alarm.ImageList = this.imageList1;
-            this.button_Alarm.Location = new System.Drawing.Point(267, 4);
-            this.button_Alarm.Margin = new System.Windows.Forms.Padding(4);
+            this.button_Alarm.Location = new System.Drawing.Point(178, 3);
             this.button_Alarm.Name = "button_Alarm";
-            this.button_Alarm.Size = new System.Drawing.Size(75, 72);
+            this.button_Alarm.Size = new System.Drawing.Size(50, 48);
             this.button_Alarm.TabIndex = 0;
             this.toolTip1.SetToolTip(this.button_Alarm, "加工与点检数据");
             this.button_Alarm.UseVisualStyleBackColor = false;
             this.button_Alarm.Click += new System.EventHandler(this.button_Alarm_Click);
             // 
-            // timer1
-            // 
-            this.timer1.Interval = 1800000;
-            this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
-            // 
             // Form_Main
             // 
-            this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 18F);
+            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
             this.BackColor = System.Drawing.Color.WhiteSmoke;
-            this.ClientSize = new System.Drawing.Size(1626, 1052);
+            this.ClientSize = new System.Drawing.Size(1084, 701);
             this.Controls.Add(this.panel2);
             this.Controls.Add(this.statusStrip1);
             this.Controls.Add(this.panelMain);
             this.HelpButton = true;
             this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
-            this.Margin = new System.Windows.Forms.Padding(4);
             this.Name = "Form_Main";
             this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
             this.Text = "N801A上位机-Xiaomi";
@@ -365,6 +359,7 @@
             this.panel2.ResumeLayout(false);
             this.ResumeLayout(false);
             this.PerformLayout();
+
         }
 
         #endregion

+ 0 - 1
MainForm/FaForm/Form_Main.cs

@@ -457,7 +457,6 @@ namespace MainForm
                     break;
             }
         }
-
     }
 
     public enum LogType

+ 1 - 1
MainForm/FaForm/Form_Main.resx

@@ -128,7 +128,7 @@
         AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w
         LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0
         ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAADO
-        eAUAAk1TRnQBSQFMAgEBNQEAAdgBAgHYAQIBMgEAATIBAAT/ARkBAAj/AUIBTQE2BwABNgMAASgDAAHI
+        eAUAAk1TRnQBSQFMAgEBNQEAAbgBAgG4AQIBMgEAATIBAAT/ARkBAAj/AUIBTQE2BwABNgMAASgDAAHI
         AwABvAECAgABAQEAARgFAAGgAWgBBhEAAecB8AHqAbwB4gHJAbwB4QHIAbwB4QHIAbwB4QHIAbwB4QHI
         AbwB4QHIAbwB4QHIAbwB4QHIAbwB4QHIAbwB4QHIAbwB4QHIAbwB4QHIAbwB4QHIAbwB4QHIAbwB4QHI
         AbwB4QHIAbwB4QHIAbwB4QHIAbwB4QHIAbwB4QHIAbwB4QHIAbwB4QHIAbwB4QHIAbwB4QHIAbwB4QHI

+ 4 - 0
MainForm/MainForm.csproj

@@ -230,6 +230,10 @@
     </Reference>
   </ItemGroup>
   <ItemGroup>
+    <Compile Include="Atlas\AtlasScrew.cs" />
+    <Compile Include="Atlas\BaseScrew.cs" />
+    <Compile Include="Atlas\Communicate.cs" />
+    <Compile Include="Atlas\MTF6K.cs" />
     <Compile Include="ClassFile\DbHelper\JsonFileHelper.cs" />
     <Compile Include="ClassFile\DbHelper\PracticeContext.cs" />
     <Compile Include="ClassFile\DbHelper\SqlHelper.cs" />