示例#1
0
        //曲线另存为按钮
        private void svCurBtn_Click(object sender, RoutedEventArgs e)
        {
            int          i = 0, n = 0;
            FileOperator fOptor = new FileOperator();
            string       s      = null;

            n = speedCurve.Count;

            if (n > 0)
            {
                s = fOptor.getSavePath(); //获取曲线保存路径
                if (s != null)
                {
                    StreamWriter sw = new StreamWriter(s, false);
                    sw.WriteLine("电机转速曲线\t" + DateTime.Now.ToString());
                    sw.WriteLine("编号\t分钟\t秒\t起始转速\t末端转速");

                    for (i = 0; i < n; i++)
                    {
                        sw.WriteLine(speedCurve[i].Number.ToString() + "\t" +
                                     speedCurve[i].Minute.ToString() + "\t" +
                                     speedCurve[i].Second.ToString() + "\t" +
                                     speedCurve[i].StaSpeed.ToString() + "\t" +
                                     speedCurve[i].EndSpeed.ToString());
                    }
                    sw.Close();
                }
            }
            else
            {
                ModernDialog.ShowMessage("未设置曲线,无法保存!", "Message:", MessageBoxButton.OK);
            }
        }
示例#2
0
        //导出绘图数据按钮
        private void expPlotDataBtn_Click(object sender, RoutedEventArgs e)
        {
            int          i = 0, n = 0;
            FileOperator fOptor = new FileOperator();
            string       s      = null;

            n = filePtCollection.Count;
            if (n > 0)
            {
                s = fOptor.getSavePath(); //获取曲线保存路径
                if (s != null)
                {
                    StreamWriter sw = new StreamWriter(s, false);
                    sw.WriteLine("Time(s)\t" + curTypeCombox.Text);
                    for (i = 0; i < n; i++)
                    {
                        sw.WriteLine(filePtCollection[i].xLabel.ToString() + '\t' + filePtCollection[i].yValue.ToString());
                    }
                    sw.Close();
                }
            }
            else
            {
                ModernDialog.ShowMessage("当前不存在绘图数据……", "Message:", MessageBoxButton.OK);
            }
        }
        //关闭窗口
        private void ClosingWin(object sender, System.ComponentModel.CancelEventArgs e)
        {
            MessageBoxResult result = new MessageBoxResult();

            result = ModernDialog.ShowMessage("关闭窗口并退出程序?", "请确认", MessageBoxButton.OKCancel);
            if (result == MessageBoxResult.OK)
            {
                timer.Stop(); //停止计时
                if (MotoData.StartMoto == true)
                {
                    SetParam.dataFile.Close();
                }
                if (serPort.IsOpen == true)
                {
                    sendData.setMotoSpeed(0, serPort);
                    serPort.Close(); //关闭串口
                }
                if (Flag.RecData == true)
                {
                    //关闭文件
                    try
                    {
                        RTDatas.mydataFile.Close();
                    }
                    catch (Exception ex)
                    { ModernDialog.ShowMessage(ex.ToString(), "Message:", MessageBoxButton.OK); return; }

                    FileOperator fOptor = new FileOperator();
                    //获取文件保存路径
                    string s = fOptor.getSavePath();
                    File.Move("D:\\Program Files\\TRIBOLOGY\\temp.txt", s);
                }
                //写出系统状态参数
                try
                {
                    StreamWriter paramFile = new StreamWriter("D:\\Program Files\\TRIBOLOGY\\SysParam.txt");
                    paramFile.WriteLine("串口号:\t" + SysParam.PortName.ToString());
                    paramFile.WriteLine("波特率:\t" + SysParam.BaudRate.ToString());
                    paramFile.WriteLine("校验位:\t" + SysParam.Parity);
                    paramFile.WriteLine("停止位:\t" + SysParam.StopBit);
                    paramFile.WriteLine("力臂-1:\t" + SysParam.Arm_1.ToString());
                    paramFile.WriteLine("力臂-2:\t" + SysParam.Arm_2.ToString());
                    paramFile.WriteLine("力臂比值:\t" + SysParam.ArmRatio.ToString());
                    paramFile.WriteLine("压力-1零点附加值:\t" + SysParam.ExtraPress_1.ToString());
                    paramFile.WriteLine("压力-2零点附加值:\t" + SysParam.ExtraPress_2.ToString());
                    paramFile.Close();
                }
                catch (Exception ex)
                {
                    ModernDialog.ShowMessage(ex.ToString(), "Message:", MessageBoxButton.OK);
                }
            }
            else
            {
                e.Cancel = true;
            }
        }
示例#4
0
        //另存为按钮
        private void SaveAsBtn_Click(object sender, RoutedEventArgs e)
        {
            FileOperator fOptor = new FileOperator();
            string       str    = fOptor.getSavePath(); //获取曲线保存路径

            if (str != null)
            {
                StreamWriter sw = new StreamWriter(s, false);
                sw.Write(s);
                sw.Close();
            }
        }
示例#5
0
        //导入曲线按钮
        private void impCurBtn_Click(object sender, RoutedEventArgs e)
        {
            FileOperator fOptor = new FileOperator();
            string       s      = null;
            string       line   = null;

            string[]     strs = null;
            MotoDataItem motoDataItem;

            //打开曲线文件路径
            s = fOptor.getOpenPath();
            if (s != null)
            {
                StreamReader sr = new StreamReader(s);
                //清空原有数据曲线,准备添加新的数据曲线
                speedCurve.Clear();

                line = sr.ReadLine();//读取文件头
                line = sr.ReadLine();
                while ((line = sr.ReadLine()) != null)
                {
                    //解析数据
                    strs         = line.Split('\t');
                    motoDataItem = new MotoDataItem();
                    try
                    {
                        motoDataItem.Number   = int.Parse(strs[0]);    //编号
                        motoDataItem.Minute   = double.Parse(strs[1]); //分钟
                        motoDataItem.Second   = double.Parse(strs[2]); //秒
                        motoDataItem.StaSpeed = double.Parse(strs[3]); //起始转速
                        motoDataItem.EndSpeed = double.Parse(strs[4]); //末端转速
                    }
                    catch (Exception ex)
                    {
                        ModernDialog.ShowMessage(ex.ToString(), "Message:", MessageBoxButton.OK);
                        break;
                    }
                    speedCurve.Add(motoDataItem);//添加数据曲线
                }
                sr.Close();
            }
        }
        //停止记录后保存文件
        void SaveFile(object sender, EventArgs e)
        {
            Flag.RecData = false;
            //关闭文件
            try
            {
                mydataFile.Close();
            }
            catch (Exception ex)
            { ModernDialog.ShowMessage(ex.ToString(), "Message:", MessageBoxButton.OK); return; }

            FileOperator fOptor = new FileOperator();
            //获取文件保存路径
            string s = fOptor.getSavePath();

            if (s != null)
            {
                File.Move("D:\\Program Files\\TRIBOLOGY\\temp.txt", s);
            }

            recDataBtn.Content   = "记录数据";
            recDataBtn.IsEnabled = true;
        }
示例#7
0
        //打开文件按钮(绘图)
        private void opFileBtn_Click(object sender, RoutedEventArgs e)
        {
            FileOperator fOptor = new FileOperator();
            string       s      = null; //文件路径
            string       line   = null; //一条记录

            string[] strs      = null;
            string[] titleItem = null;

            int          i = 0;
            FileDataItem fileDataItem;

            s = fOptor.getOpenPath(); //打开曲线文件路径
            avrDataLabel.Visibility = Visibility.Hidden;

            if (s != null)
            {
                filePathLabel.Content = "文件:" + s;
                StreamReader sr = new StreamReader(s);
                filePtCollection.Clear();

                line      = sr.ReadLine();//文件头(包含各项说明)
                titleItem = line.Split('\t');
                for (i = 3; i < titleItem.Length; i++)
                {
                    ComboBoxItem item = new ComboBoxItem();
                    item.Content = titleItem[i];
                    curTypeCombox.Items.Add(item);
                }

                fileData.Clear();//清空数据以便存入新的文件数据
                while ((line = sr.ReadLine()) != null)
                {
                    //解析数据记录
                    strs         = line.Split('\t');
                    fileDataItem = new FileDataItem();

                    try
                    {
                        fileDataItem.Time = double.Parse(strs[0]);
                        for (i = 3; i < strs.Length; i++)
                        {
                            switch (titleItem[i])
                            {
                            case "压力":
                                fileDataItem.Pressure = double.Parse(strs[i]); break;

                            case "温度":
                                fileDataItem.Temperature = double.Parse(strs[i]); break;

                            case "相对湿度":
                                fileDataItem.Humidity = double.Parse(strs[i]); break;

                            case "平台转速":
                                fileDataItem.PlatSpeed = double.Parse(strs[i]); break;

                            case "电机转速":
                                fileDataItem.MotoSpeed = double.Parse(strs[i]); break;

                            case "电机扭矩":
                                fileDataItem.MotoTorque = double.Parse(strs[i]); break;

                            case "摩擦力":
                                fileDataItem.FricForce = double.Parse(strs[i]); break;

                            case "摩擦速度":
                                fileDataItem.FricSpeed = double.Parse(strs[i]); break;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        ModernDialog.ShowMessage(ex.ToString(), "Message:", MessageBoxButton.OK);
                        break;
                    }

                    fileData.Add(fileDataItem); //添加一条数据记录
                }
                sr.Close();
            }
        }