Пример #1
0
 public int closeInstrument()
 {
     MagnetDriveDriver.CloseChannel(channelHandle);
     MagnetDriveDriver.Power(0);
     SerializeData.SerializeObject <MagnetDriveSettings>(magSettings, settingsFile);
     return(0);
 }
Пример #2
0
        private void handleData(ReadingsUpdateEventArgs e)
        {
            updateStatus();
            int index1 = cmbHallProbe1.SelectedIndex;
            int index2 = cmbHallProbe2.SelectedIndex;

            if (index1 >= 0 && index2 >= 0)
            {
                double val1 = e.readings[index1, 1];
                if (Double.IsInfinity(val1) || Double.IsNaN(val1))
                {
                    val1 = 0;
                }

                double val2 = e.readings[index2, 1];
                if (Double.IsInfinity(val2) || Double.IsNaN(val2))
                {
                    val2 = 0;
                }
                try
                {
                    nudHallProbe1.Value = (decimal)val1;
                    nudHallProbe2.Value = (decimal)val2;
                }
                catch (Exception ex)
                {
                }
            }

            if (calibrationOngoing)
            {
                if (calibrationCnt >= calibration.GetLength(0))
                {
                    calibrationOngoing = false;
                    //done with the calibration. Save to disk. Work-around since XMLserializer does not support serializing multi-dimensional arrays
                    double[] calibX = new double[calibration.GetLength(0)];
                    double[] calibY = new double[calibration.GetLength(0)];
                    for (int i = 0; i < calibX.Length; i++)
                    {
                        calibX[i] = calibration[i, 0];
                        calibY[i] = calibration[i, 1];
                    }
                    SerializeData.SerializeObject <double[]>(calibX, calibrationFile + "_xvals.xml");
                    SerializeData.SerializeObject <double[]>(calibY, calibrationFile + "_yvals.xml");
                }
                else
                {
                    //position on the y-axis
                    calibration[calibrationCnt, 1] = (double)nudCurrentPos.Value;
                    double HP1 = (double)nudHallProbe1.Value;
                    double HP2 = (double)nudHallProbe2.Value;
                    //field value on the x-axis
                    calibration[calibrationCnt, 0] = Math.Sqrt(HP1 * HP1 + HP2 * HP2);
                    nudSetPos.Value = (decimal)(calibration[calibrationCnt, 1] + dtheta_calibration);
                    moveMagnet();
                    calibrationCnt++;
                    Thread.Sleep(500);
                }
            }
        }
Пример #3
0
 private void settingsComponentUpdate(object sender, EventArgs e)
 {
     magSettings.setupFile = txtSetupFile.Text;
     magSettings.comPort   = txtComPort.Text;
     magSettings.baudRate  = (uint)nudBaudRate.Value;
     magSettings.axisID    = (byte)nudAxisID.Value;
     magSettings.rampRate  = (double)nudRampRate.Value;
     magSettings.indexHP1  = cmbHallProbe1.SelectedIndex;
     magSettings.indexHP2  = cmbHallProbe2.SelectedIndex;
     SerializeData.SerializeObject <MagnetDriveSettings>(magSettings, settingsFile);
 }
Пример #4
0
        private void cmdUpdate_Click(object sender, EventArgs e)
        {
            int index = cmbChannelID.SelectedIndex;

            settings.channelA[index]       = cmbChannelA.SelectedIndex;
            settings.channelB[index]       = cmbChannelB.SelectedIndex;
            settings.K1_vals[index]        = (double)nudK1.Value;
            settings.K2_vals[index]        = (double)nudK2.Value;
            settings.K3_vals[index]        = (double)nudK3.Value;
            settings.transformation[index] = cmbTransformation.SelectedIndex;
            settings.names[index]          = txtName.Text;

            SerializeData.SerializeObject <DataFilterSettings>(settings, settingsFile);

            if (cmbTransformation.SelectedIndex == (int)EFMExperimentFilters.PeltierStability)
            {
                if (nudK1.Value >= 1 && nudK1.Value <= nStabilityMax)
                {
                    //copy the old data
                    double[] tmp = new double[stabilityDataBuffer.Length];
                    for (int i = 0; i < stabilityDataBuffer.Length; i++)
                    {
                        tmp[i] = stabilityDataBuffer[i];
                    }

                    int nDataPoints = Convert.ToInt32(nudK1.Value);

                    stabilityDataBuffer = new double[nDataPoints];
                    int cntStart = tmp.Length - Math.Min(tmp.Length, nDataPoints);
                    int cntEnd   = Math.Min(tmp.Length, nDataPoints);

                    for (int i = cntStart; i < cntEnd; i++)
                    {
                        stabilityDataBuffer[i - cntStart] = tmp[i];
                    }

                    curStabilityPos = cntEnd;
                }
            }


            fireUpdateEvent();
        }