Пример #1
0
 /// <summary>
 /// 异步操作文件夹复制
 /// </summary>
 /// <param name="index"></param>
 /// <returns></returns>
 private async Task Copy(ManagerMessage row)
 {
     await Task.Run(() => {
         PublicClassTools.Copy(row.SourceModelPath, row.CopyModel_To_TargetPath);
         row.Status = ShiYanStatus.FilesCopyCompleted;
     });
 }
Пример #2
0
        /// <summary>
        /// 删除文件夹
        /// </summary>
        /// <param name="motherPathName"></param>
        /// <returns></returns>
        public string DeleteFolder(string motherPathName)
        {
            string r = "无效操作";

            try
            {
                string iniPath  = System.AppDomain.CurrentDomain.BaseDirectory + "/HR_Models.ini";
                Ini    ini      = new Ini(iniPath);
                string tempPath = ini.ReadValue("root", "UserRootPath") + PublicClassRule.JieXiMuLu(motherPathName);//解析目录
                //已经有路径了,再查一下该文件夹是否正在使用中
                bool isUsing = false;
                for (int i = 0; i < YingHeXinList.Count; i++)
                {
                    if (YingHeXinList[i].CopyModel_To_TargetPath == tempPath)
                    {
                        isUsing = true;
                        break;
                    }
                }
                if (isUsing)
                {
                    r = "该模型正在被使用,请停止试验后再试。";
                }
                else
                {
                    r = PublicClassTools.Delete(tempPath);
                }
            }
            catch (Exception)
            {
                r = "文件夹名称解析异常";
            }

            return(r);
        }
Пример #3
0
        /// <summary>
        /// 制作要发送的字节
        /// </summary>
        /// <param name="HR_Make_ID"></param>
        /// <param name="sendData"></param>
        /// <returns></returns>
        internal static byte[] MakeDataToBytes(int HR_Make_ID, string sendData)
        {
            byte[] realByteOut = null;


            string Sstrs = PublicClassRule.GetValues(HR_Make_ID.ToString(), "tcpSendBytes"); //要发送数据类型

            string[] sArray    = Sstrs.Split(',');                                           //这是数据类型数组
            string[] dataArray = sendData.Split(',');                                        //这是要发送的数据数组

            List <byte[]> outBytesList = new List <byte[]>();                                //这里最后要发送出去的byte[]组

            //标注是否翻转,true不翻转  false翻转
            bool isTCP_IEC = IsTCP_IEC(HR_Make_ID);

            if (sArray.Length == dataArray.Length)
            {
                //数据数量相同
                #region 制作byte
                for (int i = 0; i < dataArray.Length; i++)
                {
                    byte[] temp = MakeOneBytes(sArray[i], dataArray[i], isTCP_IEC);
                    if (temp != null)
                    {
                        outBytesList.Add(temp);
                    }
                    else
                    {
                    }
                }
                //制作结束,封装开始。
                realByteOut = PublicClassTools.MergeBytes(outBytesList);

                #endregion
            }
            else
            {
                //数据数量不同,不执行发送指令
            }


            return(realByteOut);
        }
Пример #4
0
        /// <summary>
        /// 数据解析:从byte[]到数据
        /// </summary>
        /// <param name="recvDataBuffer"></param>
        /// <param name="HR_Make_ID"></param>
        /// <returns></returns>
        internal static List <double> MakebytesToData(byte[] recvDataBuffer, int HR_Make_ID)
        {
            List <double> r = new List <double>();
            //int length = PublicClassTools.Read_Setting_Length(HR_Make_ID, "tcpReceiveBytes");//计算长度
            string Rstrs = PublicClassRule.GetValues(HR_Make_ID.ToString(), "tcpReceiveBytes");//接收数据类型

            string[] rArray = Rstrs.Split(',');

            int startIndex = 0;

            for (int i = 0; i < rArray.Length; i++)
            {
                //做数据
                r.Add(MakeOneData(rArray[i], startIndex, recvDataBuffer));

                //重置位置
                startIndex = startIndex + PublicClassTools.GetTypeByteLength(rArray[i].Trim());
            }


            return(r);
        }
Пример #5
0
        private void RecvData(object sender, NetEventArgs e)
        {
            #region 接收数据应对措施

            int id = MakeDataTCP(e);//查询ID
            if (id == -1)
            {
                //不处理
                //【注意】程序中写了。如果返回值是-1说明没查到,此链接会被关闭。所以要处理不等于-1的即可
            }
            else
            {
                //处理收到的数据
                var      row = YingHeXinList.Where(o => o.ID == id).ToList();
                TimeSpan ts  = DateTime.Now - row[0].TCP_OK_Start;
                row[0].TCP_GoOn_Time = string.Format("{0}天{1}小时{2}分{3}秒 {4}", ts.Days, ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds);

                //int length = PublicClassTools.Read_Setting_Length(row[0].HR_Make_ID, "tcpReceiveBytes");
                //根据这个长度处理数据
                List <double> receiveDataList = PublicClassRule.MakebytesToData(e.Client.RecvDataBuffer, row[0].HR_Make_ID);
                //把数据放置在对应的位置上
                string rDataStr = "";
                for (int i = 0; i < receiveDataList.Count; i++)
                {
                    rDataStr = string.Format("{0},{1}", rDataStr, receiveDataList[i]);
                }
                //循环结束,最前方都会去掉
                if (rDataStr.StartsWith(","))
                {
                    rDataStr = rDataStr.Substring(1);
                }
                row[0].ReceivedData = rDataStr;
                row[0].ReceivedTotalCount++;

                #region //补充:为了单一模型
                MakeSingleData(true, id, rDataStr, row[0].TCP_GoOn_Time);


                #endregion

                //下面该回数据了,有来不往非君子。

                //首先验证一下要发送的数据 2019年12月10日11:42:46
                int slength = PublicClassTools.Read_Setting_Length(row[0].HR_Make_ID, "tcpSendBytesNames");//协议中要发送的数据长度
                if (row[0].SendData == null)
                {
                    //如果是空,给一个初始值

                    MakeSendDataStr(row, slength);
                }
                //再验证一下,这个数据的数量是不是正确
                string[] sCount = row[0].SendData.Split(',');
                if (sCount.Length != slength)
                {
                    //长度不正确
                    MakeSendDataStr(row, slength);
                }
                else
                {
                    //长度正确
                }

                //现在有要发送的数据了。开始制作byte[]
                byte[] sendByteDataList = PublicClassRule.MakeDataToBytes(row[0].HR_Make_ID, row[0].SendData);
                if (sendByteDataList == null)
                {
                    //没数据可发
                }
                else
                {
                    //发送数据异常
                    SendData111(sendByteDataList, e.Client);
                    row[0].SendTotalCount++;
                    if (row[0].CreateType == ShiYanCreateType.New || true) //先不管了,不管怎么用,都记录吧
                    {
                        //新建的试验记录日志
                        PublicClassRule.MakeLog(row[0]);//写tcp通讯的命令和返回值日志
                    }
                    else
                    {
                        //复盘自己和别人的试验,不做日志记录
                    }
                }
            }

            /// <summary>
            /// 发送数据
            /// </summary>
            /// <param name="_data"></param>
            /// <param name="sessionClient"></param>
            void SendData111(byte[] _data, Session sessionClient)
            {
                svr.Send(sessionClient, _data);

                string byteStr = "";

                for (int i = 0; i < _data.Length; i++)
                {
                    byteStr = byteStr + " " + _data[i].ToString("X2");
                }

                string info = string.Format("发送数据:\tOmegaS Send data:\t{0} \tTo:{1}.", byteStr, sessionClient);

                Console.WriteLine(info);
                Console.Write(">");
            }

            #endregion
        }