示例#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();
            }
        }
        //停止记录后保存文件
        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;
        }