Exemplo n.º 1
0
        public ClassSys DeSerializeNow(string filename)
        {
            ClassSys c = new ClassSys();

            try
            {
                using (FileStream fileStream =
                           new FileStream(filename,
                                          FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    BinaryFormatter b = new BinaryFormatter();

                    c = b.Deserialize(fileStream) as ClassSys;



                    if (c.ChannelSamplemode == null)
                    {
                        c.ChannelSamplemode = new int[20];
                    }

                    if (c.ChannelRange == null)
                    {
                        c.ChannelRange     = new double[20];
                        c.ChannelControl   = new bool[20];
                        c.ChannelDimension = new int[20];

                        c.ChannelCount = 8;
                        for (int i = 0; i < c.ChannelCount; i++)
                        {
                            c.ChannelRange[i]   = 10;
                            c.ChannelControl[i] = false;
                        }
                    }



                    fileStream.Close();
                }
            }
            catch (Exception e1)
            {
                c = new ClassSys();

                MessageBox.Show(e1.Message, "读取文件");
            }
            finally
            {
            }
            return(c);
        }
Exemplo n.º 2
0
        public ClassSys DeSerializeNow(string filename)
        {
            ClassSys c = new ClassSys();

            try
            {
                using (FileStream fileStream =
                           new FileStream(filename,
                                          FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    BinaryFormatter b = new BinaryFormatter();

                    c = b.Deserialize(fileStream) as ClassSys;
                    if (c.Lapptile == null)
                    {
                        c.Lapptile = new string[10];
                    }
                    if (c.Lshorttitle == null)
                    {
                        c.Lshorttitle = new string[10];
                    }

                    if (c.RecentFilename == null)
                    {
                        c.RecentFilename = new string[20];
                    }
                    if (c.RecentFilenameKind == null)
                    {
                        c.RecentFilenameKind = new string[20];
                    }

                    if (c.SampleFile == null)
                    {
                        c.SampleFile = "TestSample";
                    }

                    if (c.SamplePath == null)
                    {
                        c.SamplePath = "";
                    }

                    if (c.demotxt == null)
                    {
                        c.demotxt = "";
                    }
                    if (c.RecentSampleFilename == null)
                    {
                        c.RecentSampleFilename = new string[20];
                    }

                    if (c.RecentSampleFilenameKind == null)
                    {
                        c.RecentSampleFilenameKind = new string[20];
                    }
                    if (c.RecentSampleFilePath == null)
                    {
                        c.RecentSampleFilePath = new string[20];
                    }

                    if (c.ControllerName == null)
                    {
                        c.ControllerName = new string[20];
                    }

                    c.ControllerName[0] = "ARM控制器";
                    c.ControllerName[1] = "DOLI控制器";
                    c.ControllerName[2] = "DSP控制器";
                    c.ControllerName[3] = "直线电机";
                    c.ControllerCount   = 4;

                    if (c.MachineName == null)
                    {
                        c.MachineName = new string[20];
                    }


                    c.MachineName[0] = "电子(液压)万能试验机";
                    c.MachineName[1] = "扭转试验机";
                    c.MachineName[2] = "岩石三轴试验台";
                    c.MachineName[3] = "换挡意图传感器试验机";
                    c.MachineName[4] = "金属恒应变控制试验机";
                    c.MachineName[5] = "车身刚度试验台";
                    c.MachineName[6] = "单台双通道控制器试验台";


                    c.MachineCount = 7;

                    if (c.ChannelSamplemode == null)
                    {
                        c.ChannelSamplemode = new int[20];
                    }

                    if (c.ChannelControlChannel == null)
                    {
                        c.ChannelControlChannel = new int[20];
                    }

                    if (c.ChannelName == null)
                    {
                        c.ChannelName = new string[20];
                    }

                    if (c.ChannelRange == null)
                    {
                        c.ChannelRange     = new double[20];
                        c.ChannelControl   = new bool[20];
                        c.ChannelDimension = new int[20];

                        c.ChannelCount = 8;
                        for (int i = 0; i < c.ChannelCount; i++)
                        {
                            c.ChannelRange[i]   = 10;
                            c.ChannelControl[i] = false;
                        }
                    }


                    fileStream.Close();
                }
            }
            catch (Exception e1)
            {
                c = new ClassSys();

                MessageBox.Show(e1.Message, "读取文件");
            }
            finally
            {
            }
            return(c);
        }