示例#1
0
        public static BattMonSettings bDeserAppSettings()
        {
            BattMonSettings cBattMonStgFromStorage=null;
            Debug.WriteLine("++bDeserAppSettings()");

            IFormatter formatter = new BinaryFormatter();
            try
            {
                Stream streamFrom = new FileStream(BattMonSettings.cstrAppSettingsClassFileName, FileMode.Open, FileAccess.Read, FileShare.Read);
                cBattMonStgFromStorage = (BattMonSettings)formatter.Deserialize(streamFrom);
                streamFrom.Close();
                Debug.WriteLine("bDeserAppSettings() Also restored "+ cBattMonStgFromStorage.strCOMPortName.ToString());
            }
            catch(SerializationException serexp)
            {
                Debug.WriteLine("Failed to find saved battmon app settings." + serexp.ToString());
            // if file is not there, just return defaults settings
                cBattMonStgFromStorage=new BattMonSettings();
            }
            catch(IOException ioexp)
            {
                Debug.WriteLine("Failed to find saved battmon app settings." + ioexp.ToString());
            // if file is not there, just return defaults settings
                cBattMonStgFromStorage=new BattMonSettings();
            };

            Debug.WriteLine("--bDeserAppSettings()="+ ((null==cBattMonStgFromStorage)?"null":cBattMonStgFromStorage.ToString()) );
            return cBattMonStgFromStorage;
        }
示例#2
0
        public static BattMonSettings bDeserAppSettings()
        {
            BattMonSettings cBattMonStgFromStorage = null;

            Debug.WriteLine("++bDeserAppSettings()");

            IFormatter formatter = new BinaryFormatter();

            try
            {
                Stream streamFrom = new FileStream(BattMonSettings.cstrAppSettingsClassFileName, FileMode.Open, FileAccess.Read, FileShare.Read);
                cBattMonStgFromStorage = (BattMonSettings)formatter.Deserialize(streamFrom);
                streamFrom.Close();
                Debug.WriteLine("bDeserAppSettings() Also restored " + cBattMonStgFromStorage.strCOMPortName.ToString());
            }
            catch (SerializationException serexp)
            {
                Debug.WriteLine("Failed to find saved battmon app settings." + serexp.ToString());
// if file is not there, just return defaults settings
                cBattMonStgFromStorage = new BattMonSettings();
            }
            catch (IOException ioexp)
            {
                Debug.WriteLine("Failed to find saved battmon app settings." + ioexp.ToString());
// if file is not there, just return defaults settings
                cBattMonStgFromStorage = new BattMonSettings();
            };

            Debug.WriteLine("--bDeserAppSettings()=" + ((null == cBattMonStgFromStorage)?"null":cBattMonStgFromStorage.ToString()));
            return(cBattMonStgFromStorage);
        }
示例#3
0
        public Form1()
        {
            Debug.WriteLine("++Form1() ctor");

// make some time time-span conversions before we start out charts
            tspn6Sec = new TimeSpan(0, 0, ciZoomTimeSpanSize_inSec);
            dtm6sec  = new DateTime().Add(tspn6Sec);

            tspnSmScrl = new TimeSpan(0, 0, ciZoomTimeScrlSize_inSec);
            dtmSmlScrl = new DateTime().Add(tspnSmScrl);

            tspnTickmark = new TimeSpan(0, 0, 0, ciTickMarkTimeSize_in_mSec);
            dtmTickmark  = new DateTime().Add(tspnTickmark);
// perform container init
            InitializeComponent();
            this.Text = "Battery Monitor";

// initialize all our gauge controls in a single call
            bInitalizeGaugeControls();
//
// Creates and initializes a new concurrent Queue.
            cnquBattDataQueue = new ConcurrentQueue <Generic12Vbattery.strctBattMonData>();
// restore application settings
            m_cBattMonSettings = BattMonSettings.bDeserAppSettings();
// assign these restored settings to controls
            SerPortNameTextBox.Text        = m_cBattMonSettings.strCOMPortName;
            ripple_filterCheckBox1.Checked = m_cBattMonSettings.bRippleFilterOn;

            try
            {
// open battery logging file
                m_OutCSVfile   = new System.IO.StreamWriter(szBatMonCSVFileName, true);
                bLoggingToFile = true;
            }
            catch (IOException ioex)
            {
                Debug.WriteLine("Form1() ctor: Error " + ioex.ToString() + "! Cannot open log file");
                m_OutCSVfile   = null;
                bLoggingToFile = false;
            };
//
// now create new battery class instance or restore from saved
            m_batBattery = AutomotiveBattery.bDeserBattCls();
//
            if (null == m_batBattery)
            {
                Debug.WriteLine("Form1() ctor: do not have saved instance of myAutoBattery, create new !");
// if there is no saved instance of myAutoBattery, then create a new instance
// show new battery intro message first

// first open batt info form to fill up
                BatteryInfoForm btinffrmNewbatteryInfo = new  BatteryInfoForm();

// and wait for [Save] button to be pressed before we continue
                Application.Run(btinffrmNewbatteryInfo);

// now take data from form into our member variables

// now construct it anew using supplied parameters
                m_batBattery = new AutomotiveBattery(btinffrmNewbatteryInfo.strGetBatteryName(),
                                                     btinffrmNewbatteryInfo.strGetBatteryMake(), btinffrmNewbatteryInfo.strGetbatteryModel(),
                                                     btinffrmNewbatteryInfo.strGetBatterySerNo(),
                                                     btinffrmNewbatteryInfo.iGetBatteryCA(), btinffrmNewbatteryInfo.iGetbatteryCCA(),
                                                     btinffrmNewbatteryInfo.iGetBatteryCapacityAHrs(),
                                                     btinffrmNewbatteryInfo.dtmGetbattDateOfManufacture());
                Debug.WriteLine("Form1() ctor: created new instance of myAutoBattery(\"" + btinffrmNewbatteryInfo.strGetBatteryName() + "\")");
                m_lstDischrgChrgCycles = new List <DateTime>(0);
            }
            else
            {
                Debug.WriteLine("Form1() ctor: Restored myAutoBattery from saved.");
// print some info about restored class instance
                Debug.WriteLine("Form1() ctor: max charge current=" + m_batBattery.getMaxDischrgCurrentA().ToString() + " A");
                Debug.WriteLine("Form1() ctor: starting cycles=" + m_batBattery.iGetNumStartingCycles().ToString());
//
                int iInitialNumOfDchrgChrgCycles = m_batBattery.iGetNumStartingCycles();
// initialize listbox view - first create a list of items
                m_lstDischrgChrgCycles = new List <DateTime>(iInitialNumOfDchrgChrgCycles);

                bUpdateListBoxAndCntFromMmapDschrgChrgCycles();
            };

// stop monitoring and display stopped state
            bOnStopMonitoring(false);
            LiveDataRadioButton1.Checked = true;           // changing value of checked will call OnRadioBtnChanged()
            FromFileRadioButton1.Checked = false;
// UI update timer function set up
            m_UIRefreshTimer          = new System.Windows.Forms.Timer();
            m_UIRefreshTimer.Interval = 100; // redraw controls every 100 msec, i.e 10 Hz
            m_UIRefreshTimer.Tick    += new EventHandler(UI_slow_upd_timer);

// fast data update timer set up
            m_DataFastRefreshTimer          = new System.Windows.Forms.Timer();
            m_DataFastRefreshTimer.Interval = 10; // redraw controls every 10 msec, i.e 100 Hz
#if USEFASTANDSLOWTIMERS
            m_DataFastRefreshTimer.Tick += new EventHandler(UI_slow_upd_timer_no_dequeue);
#else
            m_DataFastRefreshTimer.Tick += new EventHandler(data_refresh_fast_timer_Funkt);
#endif
            Debug.WriteLine("Form1() ctor: analog meters timer is up; rate=" + (1000 / m_UIRefreshTimer.Interval).ToString() + " Hz");
//
            System.Reflection.Assembly myAssembly = System.Reflection.Assembly.GetExecutingAssembly();
            Stream StarterOff_bmp_Stream          = myAssembly.GetManifestResourceStream("batt_mon_app.starter_motor_off.jpg");
            Stream StarterOn_bmp_Stream           = myAssembly.GetManifestResourceStream("batt_mon_app.starter_motor_on.jpg");
            bmpStarterMtrOff = new Bitmap(StarterOff_bmp_Stream);
            bmpStarterMtrOn  = new Bitmap(StarterOn_bmp_Stream);

            bSetMotorPict(bmpStarterMtrOff);
            m_slMeasIterCnt = 0;
// ctor will perform autostart - it will try to start serial port worker right away
// which may fail so it may display a message
//			bOnStartMonitoring();
// if autostart here fails, then user may reconfigure serial port and start manually
            Debug.WriteLine("--Form1() ctor");
        } // end Form1() ctor