Exemplo n.º 1
0
        //static void WriteOutput( ScriptViewModel viewModel )
        //{
        //	//!!!!
        //	foreach( var result in viewModel.Results )
        //		Log.Info( result.ToString() );

        //	//var outputWindow = EditorForm.Instance.WorkspaceController.FindWindow<OutputWindow>();
        //	//if (outputWindow == null)
        //	//	return;

        //	//foreach (var result in script.Results)
        //	//	outputWindow.Print(result.ToString());
        //	//outputWindow.Print("");
        //}

        protected override void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            if (propertyName == nameof(ScriptEditorEngine.HasError))
            {
                Log.Error(LastError.ToString());
            }
        }
Exemplo n.º 2
0
        //Button to send OFF command to DAC
        private void BDACOFF_Click(object sender, RoutedEventArgs e)
        {
            int  size          = 2;                       //Size of transmit and receive
            int  DeviceNumber  = DacDevice.SelectedIndex; //Device chosen by user on GUI
            uint baudRate      = 1000000;                 //Baud rate of device
            uint idleCsVal     = 0x1ff;                   //Bit is 1 for clock idle low
            uint activeCsVal   = 0x1ef;                   //Bit is 0 for CS active low, GP4 set as active low CS
            uint csToDataDly   = 0;                       //Time delay from CS to data
            uint dataToDataDly = 0;                       //Time delay from data to data
            uint dataToCsDly   = 0;                       //Time delay from data to CS
            uint txferSize     = (uint)(size);            //tXfer size set to size bytes
            byte spiMd         = 0;                       //SPI mode from connected devices datasheet
            uint csmask        = 0x10;                    //1 represents CS, set GP4 as CS

            //Setup transfer and receive bytes
            byte[] txData1 = new byte[size], rxData1 = new byte[size];
            txData1[0] = 0x70;
            txData1[1] = 0x00;

            //Start communication with DAC
            error = MCP2210.M_Mcp2210_xferSpiDataEx(deviceHandle[DeviceNumber], txData1, rxData1, ref baudRate, ref txferSize, csmask, ref idleCsVal, ref activeCsVal,
                                                    ref csToDataDly, ref dataToCsDly, ref dataToDataDly, ref spiMd);
            //Check for error and update status if required
            if (error != MCP2210.M_E_SUCCESS)
            {
                LastError.Items.Add(error.ToString());
                LastError.Items.Add("Device Disconnected!");
                LastError.SelectedIndex = LastError.Items.Count - 1;
                LastError.ScrollIntoView(LastError.SelectedItem);
            }
        }
Exemplo n.º 3
0
        private void TesseractErrorReceived(object sender, DataReceivedEventArgs e)
        {
            var msg = e.Data;

            if (string.IsNullOrEmpty(msg) ||
                msg.StartsWith("Tesseract Open Source OCR Engine", StringComparison.OrdinalIgnoreCase) ||
                msg.Contains("Too few characters", StringComparison.OrdinalIgnoreCase) ||
                msg.Contains("Empty page", StringComparison.OrdinalIgnoreCase) ||
                msg.Contains(" diacritics", StringComparison.OrdinalIgnoreCase) ||
                msg.Contains("Weak margin", StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            if (TesseractErrors.Count <= 100)
            {
                if (string.IsNullOrEmpty(LastError))
                {
                    LastError = msg;
                }
                else if (!LastError.Contains(msg))
                {
                    LastError = LastError + Environment.NewLine + msg;
                }
                TesseractErrors.Add(msg);
            }
        }
Exemplo n.º 4
0
 public void NotFoundErrorIsExpected()
 {
     // Make sure we're returning the native error as expected (and not the PAL error on Unix)
     using (LastError le = new LastError(Path.GetRandomFileName()))
     {
         // Conveniently ERROR_FILE_NOT_FOUND and ENOENT are both 0x2
         Assert.Equal(2, le.Error);
     }
 }
Exemplo n.º 5
0
        public string GetLastError()
        {
            lock (Lock)
            {
                var code = fpdf_view.FPDF_GetLastError();

                return(LastError.ErrorCodePhrase(code));
            }
        }
Exemplo n.º 6
0
        //private static string serviceName;

        static void Main(string[] args)
        {
            Init();

            var common = new Common();

            common.SetCredential(Login, ApiKey, UserName, Password);
            common.SetEndpoint("ApplicationManagementService", "https://api2.vetrf.ru:8002/platform/services/2.0/ApplicationManagementService");

            var res = new MercuryMainService();

            //if (false)
            //{
            //    bool request = false;

            //    if (request)
            //        res.ModifyEnterpriseOperation(guidEx, "20180421_1", "ent name", "Реализация пищевых продуктов", "создание площадки");
            //    else
            //    {
            //        var ApplicationId = "42ae0fc2-efcc-4158-a260-9cdcd3dcf607";
            //        var issuerId = guidEx;

            //        res.AppResponse(ApplicationId, issuerId);
            //    }
            //}

            bool request = false;
            //if (request)
            //{
            //    var requestRes = res.GetVetDocumentListOperation(guidEx, guidEx_Pa, "00001", 3, 1);
            //    //var obj = res.Merc_getResponse<MercuryClassLibrary.ApplicationManagementService.GetVetDocumentListResponse>(guidEx, ApplicationId);
            //}
            //else
            //{
            //    var ApplicationId = "ac4e8437-bc49-4361-bb84-b7512104c629";

            //    var obj = res.Merc_getResponse<MercuryClassLibrary.ApplicationManagementService.GetVetDocumentListResponse>(guidEx, ApplicationId);

            //}

            var requestRes = res.GetVetDocumentListOperation(guidEx, guidEx_Pa, "00001", 3, 1);

            var obj = res.Merc_getResponse <Cs_Mercury.ApplicationManagementService.GetVetDocumentListResponse>(guidEx, requestRes.application.applicationId);

            var err = LastError.GetError();

            if (!err.Success)
            {
                Console.WriteLine(err.Message);
                Console.ReadKey();
            }
            else
            {
                Console.WriteLine("Success");
            }
        }
Exemplo n.º 7
0
        //Timer setup and communication for ADC
        private void dispatcherTimerADC_Tick(object sender, EventArgs e)
        {
            double Vref          = 5.00;              //Reference voltage provided to ADC from circuit
            int    size          = 2;                 //Size of txfers
            int    DeviceNumber  = ADC.SelectedIndex; //Device chosen by user on GUI
            uint   baudRate      = 1000000;           //Baud rate
            uint   idleCsVal     = 0x1ff;             //Bit is 1 for clock idle low
            uint   activeCsVal   = 0x1df;             //Bit is 0 for CS active low, GP5 set as active low CS
            uint   csToDataDly   = 0;                 //Time delay from CS to data
            uint   dataToDataDly = 0;                 //Time delay from data to data
            uint   dataToCsDly   = 0;                 //Time delay from data to CS
            uint   txferSize     = (uint)(size);      //Xfer size set to size bytes
            byte   spiMd         = 0;                 //SPI mode from connected devices datasheet
            uint   csmask        = 0x20;              //1 represents CS, set GP5 as CS

            //Setup transfer and receive bytes
            byte[] txData1 = new byte[size], rxData1 = new byte[size];
            //ADC does not take input, tx is don't care
            txData1[0] = 0x00;
            txData1[1] = 0x00;

            //Start communication with ADC
            error = MCP2210.M_Mcp2210_xferSpiDataEx(deviceHandle[DeviceNumber], txData1, rxData1, ref baudRate, ref txferSize, csmask, ref idleCsVal, ref activeCsVal,
                                                    ref csToDataDly, ref dataToCsDly, ref dataToDataDly, ref spiMd);

            //Convert 16 bit receive to 10 bit unsigned value
            byte[] tempADC = new byte[1];
            tempADC[0] = rxData1[1];
            rxData1[1] = rxData1[0];
            rxData1[0] = tempADC[0];
            UInt16 value = (UInt16)(BitConverter.ToInt16(rxData1, 0));

            value = (UInt16)((value & 0x1FF8) >> 3);
            //Convert 10 bit unsigned to 0-Vref double
            double Volt = value * Vref / 1023;

            //Check for error and update status
            if (error != MCP2210.M_E_SUCCESS)
            {
                LastError.Items.Add(error.ToString());
                LastError.Items.Add("Device Disconnected!");
                LastError.SelectedIndex = LastError.Items.Count - 1;
                LastError.ScrollIntoView(LastError.SelectedItem);
            }
            else
            {
                ADCV.Text    = Volt.ToString("0.00");
                ADCBar.Value = Volt * 20;
            }

            //Forcing the CommandManager to raise the RequerySuggested event
            CommandManager.InvalidateRequerySuggested();
        }
Exemplo n.º 8
0
 public override void Update(Vector3 error)
 {
     if (error.IsNaN())
     {
         return;
     }
     if (LastError.IsZero())
     {
         LastError = error;
     }
     Update(error, (error - LastError) / TimeWarp.fixedDeltaTime);
 }
Exemplo n.º 9
0
 public override void Update(float error)
 {
     if (float.IsNaN(error))
     {
         return;
     }
     if (LastError.Equals(0))
     {
         LastError = error;
     }
     Update(error, (error - LastError) / TimeWarp.fixedDeltaTime);
 }
Exemplo n.º 10
0
 public void NotFoundErrorIsExpected()
 {
     // Make sure we're returning the native error as expected (and not the PAL error on Unix)
     using (LastError le = new LastError(Path.GetRandomFileName()))
     {
         // while ERROR_FILE_NOT_FOUND/ENOENT have predictable values on Windows, Linux and Mac,
         //  we can't rely on ENOENT having the same value on other platforms. Instead, assert
         //  that we didn't get the PAL error because we know its value.
         const int PAL_Error_ENOENT = 0x1002D;
         Assert.NotEqual(PAL_Error_ENOENT, le.Error);
     }
 }
Exemplo n.º 11
0
        //Timer setup and communication for Motor control using ADC voltage
        private void dispatcherTimerMotor_Tick(object sender, EventArgs e)
        {
            int    DeviceNumber  = Motor.SelectedIndex; //Device chosen by user on GUI
            double Vref          = 5.00;                //Reference voltage provided to Motor DAC by circuit
            int    size          = 2;                   //Size of txfers
            uint   baudRate      = 1000000;             //Baud rate
            uint   idleCsVal     = 0x1ff;               //Bit is 1 for clock idle low
            uint   activeCsVal   = 0x1ef;               //Bit is 0 for CS active low, GP4 set as active low CS
            uint   csToDataDly   = 0;                   //Time delay from CS to data
            uint   dataToDataDly = 0;                   //Time delay from data to data
            uint   dataToCsDly   = 0;                   //Time delay from data to CS
            uint   txferSize     = (uint)(size);        //tXfer size set to size bytes
            byte   spiMd         = 0;                   //SPI mode from connected devices datasheet
            uint   csmask        = 0x10;                //1 represents CS, set GP4 as CS

            //Setup transfer and receive bytes
            byte[] txData1 = new byte[size], rxData1 = new byte[size];
            //Read value from ADC textbox and parse it
            double value = Double.Parse(ADCV.Text);

            //Set boundaries for DAC input
            if (value > Vref)
            {
                value = Vref;
            }
            else if (value < 0)
            {
                value = 0;
            }
            //Make 0-5V input into 10 bit transfer for DAC
            int DAC = (int)(value * 1023.0 / Vref);

            txData1[0] = (byte)((DAC & 0x03C0) >> 6);
            txData1[0] = (byte)(txData1[0] | 0x70);
            txData1[1] = (byte)((DAC & 0x3F) << 2);

            //Start communication with Motor
            error = MCP2210.M_Mcp2210_xferSpiDataEx(deviceHandle[DeviceNumber], txData1, rxData1, ref baudRate, ref txferSize, csmask, ref idleCsVal, ref activeCsVal,
                                                    ref csToDataDly, ref dataToCsDly, ref dataToDataDly, ref spiMd);
            //Check for error and update status if required
            if (error != MCP2210.M_E_SUCCESS)
            {
                LastError.Items.Add(error.ToString());
                LastError.Items.Add("Device Disconnected!");
                LastError.SelectedIndex = LastError.Items.Count - 1;
                LastError.ScrollIntoView(LastError.SelectedItem);
            }

            //Forcing the CommandManager to raise the RequerySuggested event
            CommandManager.InvalidateRequerySuggested();
        }
Exemplo n.º 12
0
        public override DataTable Query(string query, params object[] args)
        {
            DataTable result = base.Query(query, args);

            if (LastError != null)
            {
                ServerConsole.ErrorLine(LastError.ToString());
#if !DEBUG
                Core.Kill(false);
#endif
            }

            return(result);
        }
Exemplo n.º 13
0
        public DataTable Query(string query)
        {
            DataTable result = base.Query(query);

            if (LastError != null)
            {
                ServerConsole.ErrorLine(LastError.ToString());
#if !DEBUG
                Core.Kill(false);
#endif
            }

            return(result);
        }
Exemplo n.º 14
0
        //Button sends command to DAC, representing 0-VREF voltage output
        private void BDACON_Click(object sender, RoutedEventArgs e)
        {
            double Vref          = 5.00;                    //Reference voltage provided to DAC from circuit
            int    DeviceNumber  = DacDevice.SelectedIndex; //Device chosen by user on GUI
            int    size          = 2;                       //Size of transmit and receive
            uint   baudRate      = 1000000;                 //Baud rate of device
            uint   idleCsVal     = 0x1ff;                   //Bit is 1 for clock idle low
            uint   activeCsVal   = 0x1ef;                   //Bit is 0 for CS active low, GP4 set as active low CS
            uint   csToDataDly   = 0;                       //Time delay from CS to data
            uint   dataToDataDly = 0;                       //Time delay from data to data
            uint   dataToCsDly   = 0;                       //Time delay from data to CS
            uint   txferSize     = (uint)(size);            //tXfer size set to size bytes
            byte   spiMd         = 0;                       //SPI mode from connected devices datasheet
            uint   csmask        = 0x10;                    //1 represents CS, set GP4 as CS

            //Setup transfer and receive bytes
            byte[] txData1 = new byte[size], rxData1 = new byte[size];
            //Read value from DAC textbox and parse it
            double value = Double.Parse(TextBoxDAC.Text);

            //Set boundaries for DAC input
            if (value > Vref)
            {
                value = Vref;
            }
            else if (value < 0)
            {
                value = 0;
            }
            //Make 0-5V input into 12 bit transfer for DAC
            int DAC = (int)(value * 4095.0 / Vref);

            txData1[0] = (byte)((DAC & 0x0F00) >> 8);
            txData1[0] = (byte)(txData1[0] | 0x70);
            txData1[1] = (byte)(DAC & 0xFF);

            //Start communication with DAC
            error = MCP2210.M_Mcp2210_xferSpiDataEx(deviceHandle[DeviceNumber], txData1, rxData1, ref baudRate, ref txferSize, csmask, ref idleCsVal, ref activeCsVal,
                                                    ref csToDataDly, ref dataToCsDly, ref dataToDataDly, ref spiMd);
            //Check for error and update status if required
            if (error != MCP2210.M_E_SUCCESS)
            {
                LastError.Items.Add(error.ToString());
                LastError.Items.Add("Device Disconnected!");
                LastError.SelectedIndex = LastError.Items.Count - 1;
                LastError.ScrollIntoView(LastError.SelectedItem);
            }
        }
Exemplo n.º 15
0
        private void RecordException(SequencedEvent @event, Exception e)
        {
            var error = new EventHandlerError(@event.EventType, @event.Sequence, e);

            if (LastError != null && LastError == error)
            {
                LastError.Increment();
                _errorRepository.UpdateError(LastError);
                Logger.Error(String.Format("Error on event {0} {1} (count : {2})", @event.EventType, @event.Sequence, LastError.Count));
            }
            else
            {
                _errorRepository.AddError(error);
                LastError = error;
                Logger.Error(String.Format("Error on event {0} {1} {2}", @event.EventType, @event.Sequence, e));
            }
        }
Exemplo n.º 16
0
        //Disconnect function
        private void Disconnect(string Device)
        {
            int DeviceNumber; //Device number used to select which device will be disconnected

            //Use input string to select Device number
            if (Device == "SevenSeg")
            {
                DeviceNumber = SevenSeg.SelectedIndex;
            }
            else if (Device == "ADC")
            {
                DeviceNumber = ADC.SelectedIndex;
            }
            else if (Device == "Temp")
            {
                DeviceNumber = Temp.SelectedIndex;
            }
            else if (Device == "Motor")
            {
                DeviceNumber = Motor.SelectedIndex;
            }
            else
            {
                DeviceNumber = DacDevice.SelectedIndex;
            }

            //Disconnect command
            MCP2210.M_Mcp2210_Close(deviceHandle[DeviceNumber]);
            //Get error
            error = MCP2210.M_Mcp2210_GetLastError();
            //Update error and connection status
            if (error != MCP2210.M_E_SUCCESS)
            {
                LastError.Items.Add(error.ToString());
                LastError.Items.Add("Device Error!");
                LastError.SelectedIndex = LastError.Items.Count - 1;
                LastError.ScrollIntoView(LastError.SelectedItem);
            }
            else
            {
                LastError.Items.Add(error.ToString());
                LastError.Items.Add("Device Disconnected!");
                LastError.SelectedIndex = LastError.Items.Count - 1;
                LastError.ScrollIntoView(LastError.SelectedItem);
            }
        }
Exemplo n.º 17
0
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = Id;
         hashCode = (hashCode * 397) ^ Priority;
         hashCode = (hashCode * 397) ^ Attempts;
         hashCode = (hashCode * 397) ^ (LastError != null ? LastError.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ RunAt.GetHashCode();
         hashCode = (hashCode * 397) ^ SucceededAt.GetHashCode();
         hashCode = (hashCode * 397) ^ FailedAt.GetHashCode();
         hashCode = (hashCode * 397) ^ LockedAt.GetHashCode();
         hashCode = (hashCode * 397) ^ (LockedBy != null ? LockedBy.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ CreatedAt.GetHashCode();
         hashCode = (hashCode * 397) ^ UpdatedAt.GetHashCode();
         return(hashCode);
     }
 }
Exemplo n.º 18
0
        // The user sets all the parameters and calls this which outputs values until error is zero.
        public override void GenerateTestOutput(float timeStep)
        {
            // maximum number of outputs to generate.
            int maxOutput = 50;

            MDetailLog("{0},BSVMotor.Test,{1},===================================== BEGIN Test Output", BSScene.DetailLogZero, UseName);
            MDetailLog("{0},BSVMotor.Test,{1},timeScale={2},targDlyTS={3},frictTS={4},eff={5},curr={6},tgt={7}",
                       BSScene.DetailLogZero, UseName,
                       TimeScale, TargetValueDecayTimeScale, FrictionTimescale, Efficiency,
                       CurrentValue, TargetValue);

            LastError = BSMotor.InfiniteVector;
            while (maxOutput-- > 0 && !LastError.ApproxEquals(Vector3.Zero, ErrorZeroThreshold))
            {
                Vector3 lastStep = Step(timeStep);
                MDetailLog("{0},BSVMotor.Test,{1},cur={2},tgt={3},lastError={4},lastStep={5}",
                           BSScene.DetailLogZero, UseName, CurrentValue, TargetValue, LastError, lastStep);
            }
            MDetailLog("{0},BSVMotor.Test,{1},===================================== END Test Output", BSScene.DetailLogZero, UseName);
        }
 private static RecipientTrackingEvent.FormatterMethod FailedGeneralDelegate()
 {
     return(delegate(RecipientTrackingEvent.FormatterSource source, string[] args)
     {
         if (args != null && args.Length > 0)
         {
             string text;
             if (!LastError.TryParseSmtpResponseString(args[0], out text))
             {
                 text = args[0];
             }
             SmtpResponse key;
             if (SmtpResponse.TryParse(text, out key))
             {
                 if (key.SmtpResponseType == SmtpResponseType.PermanentError && args.Length >= 2 && string.Equals(args[1], "Content Filter Agent"))
                 {
                     return CoreStrings.RejectedExplanationContentFiltering;
                 }
                 LocalizedString result;
                 if (AckReason.EnhancedTextGetter.TryGetValue(key, out result))
                 {
                     return result;
                 }
                 if (!string.IsNullOrEmpty(key.EnhancedStatusCode))
                 {
                     if (DsnShortMessages.TryGetResourceRecipientExplanation(key.EnhancedStatusCode, out result))
                     {
                         return result;
                     }
                     LocalizedString?customDsnCode = RecipientTrackingEvent.GetCustomDsnCode(key.EnhancedStatusCode, source.ConfigSession, source.UserLanguages);
                     if (customDsnCode != null)
                     {
                         return customDsnCode.Value;
                     }
                 }
             }
         }
         return CoreStrings.EventFailedGeneral;
     });
 }
Exemplo n.º 20
0
        /// <summary>
        /// показать форму выбора калибруемого канала
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void listOfChannels_Click(object sender, EventArgs e)
        {
            if (currentState.CalibrationTableHandles == null)
            {
                MessageBox.Show(this, "Не загруженна таблица калибровочных параметров",
                                "Информация", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            ChannelsForm cha = new ChannelsForm();

            int i = 1;

            foreach (CalibrationTableHandle handle in currentState.CalibrationTableHandles)
            {
                ListViewItem item = new ListViewItem(i.ToString());

                ListViewItem.ListViewSubItem id     = new ListViewItem.ListViewSubItem(item, string.Format("{0:X2}", handle.Name));
                ListViewItem.ListViewSubItem offset = new ListViewItem.ListViewSubItem(item, string.Format("{0:X2}", handle.Offset));
                ListViewItem.ListViewSubItem name   = new ListViewItem.ListViewSubItem(item, "");

                item.Tag = handle;

                item.SubItems.Add(id);
                item.SubItems.Add(offset);
                item.SubItems.Add(name);

                cha.listViewChannels.Items.Add(item);
                i = i + 1;
            }

            if (cha.ShowDialog(this) == DialogResult.OK)
            {
                if (cha.listViewChannels.SelectedItems != null)
                {
                    if (cha.listViewChannels.SelectedItems[0].Tag is CalibrationTableHandle)
                    {
                        currentState.SelectedCalibrationTable = (CalibrationTableHandle)cha.listViewChannels.SelectedItems[0].Tag;
                        LastError lastError = bios.GetCalibrationTable(currentState.Eprom, currentState.SelectedCalibrationTable);

                        switch (lastError)
                        {
                        case LastError.Success:

                            ShowCalibrationTableInGraphics(currentState.SelectedCalibrationTable.CalibrationTable);
                            ShowCalibrationTableInDataGrid(currentState.SelectedCalibrationTable.CalibrationTable);

                            if (currentState.SelectedCalibrationTable.CalibrationTable.IsExtremCalculated)
                            {
                                if (currentState.SelectedCalibrationTable.CalibrationTable.IsValidExtremPoints == false)
                                {
                                    checkBoxCaculateSide.Checked = false;
                                    if (MessageBox.Show(this, "Крайние точки расчитаны не корректно" + Constants.vbCrLf +
                                                        "Сбросить крайние точки в значение по умолчанию?", "Ошибка", MessageBoxButtons.YesNo,
                                                        MessageBoxIcon.Exclamation) == DialogResult.Yes)
                                    {
                                        currentState.SelectedCalibrationTable.CalibrationTable.ClearExtremPoints();
                                    }
                                }
                                else
                                {
                                    checkBoxCaculateSide.Checked = true;
                                }
                            }
                            else
                            {
                                checkBoxCaculateSide.Checked = false;
                            }

                            checkBoxCaculateSide_CheckedChanged(checkBoxCaculateSide, new EventArgs());
                            checkBoxDoScale_CheckedChanged(checkBoxDoScale, new EventArgs());

                            onShown(null, null);

                            if (packetSyncMutex.WaitOne(defaultTimeWaitOnPacketMutex))
                            {
                                currentState.SelectedCalibrationTable.CalibrationTable.CalculateKoef();
                                currentState.SelectedCalibrationTable.CalibrationTable.SaveTable();

                                biosTranslated = false;
                                if (!currentState.PacketsTurnOn)
                                {
                                    currentState.PacketsTurnOn = true;
                                }
                                TurnOnPackets(null, null);

                                packetSyncMutex.ReleaseMutex();
                            }
                            else
                            {
                                MessageBox.Show(this, "Не настроить таблицу калибровки для работы." +
                                                Constants.vbCrLf + "Перезагрузите таблицу калибровки", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }

                            break;

                        case LastError.Error:

                            MessageBox.Show(this, "Не удалось загрузить таблицу калибровки." +
                                            Constants.vbCrLf + "Возможно данные не корректы в таблице калибровки", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            break;

                        case LastError.Default:

                            break;

                        default:

                            break;
                        }
                    }
                }
            }
        }
Exemplo n.º 21
0
        /// <summary>Generates a string containing a description of a license error.</summary>
        /// <remarks><para>This method is called from <see cref="GenerateLicenseStatusEntry"/>.</para></remarks>
        /// <returns>Returns a string containing the description of a license error.</returns>
        internal string GenerateLicenseErrorString()
        {
            StringBuilder status = new StringBuilder();

            switch (LastError.ErrorNumber)
            {
            case LicenseError.ERROR_COULD_NOT_LOAD_LICENSE:
                status.Append(LastError.ErrorNumber);
                status.Append(": ");
                status.Append("License not found - activation is required.");
                break;

            case LicenseError.ERROR_COULD_NOT_LOAD_VOLUME_DOWNLOADABLE_LICENSE:
                status.Append(LastError.ErrorNumber);
                status.Append(": ");
                status.Append((ProductOption.OptionType == LicenseProductOption.ProductOptionType.VolumeLicense) ? "Volume" : "Downloadable");
                status.Append(" license not found.");
                break;

            case LicenseError.ERROR_LICENSE_NOT_EFFECTIVE_YET:
                status.Append(LastError.ErrorNumber);
                status.Append(": ");
                if (ProductOption.OptionType == LicenseProductOption.ProductOptionType.DownloadableLicenseWithTriggerCodeValidation)
                {
                    status.Append("Activation required.");
                    break;
                }
                status.Append("License not effective until ");
                DateTime local = EffectiveStartDate.ToLocalTime();

                int daysUntilEffective = (int)local.Subtract(DateTime.Now.Date).TotalDays;
                if (1 < daysUntilEffective)
                {
                    status.Append(local.ToLongDateString());
                    status.Append(" (");
                    status.Append(daysUntilEffective);
                    status.Append(" days).");
                }
                else if (1 == daysUntilEffective)
                {
                    status.Append("tomorrow.");
                }
                else
                {
                    status.Append(local.ToShortTimeString() + " today.");
                }
                break;

            case LicenseError.ERROR_LICENSE_EXPIRED:
                status.Append(LastError.ErrorNumber);
                status.Append(": ");
                status.Append("License invalid or expired.");
                break;

            case LicenseError.ERROR_WEBSERVICE_RETURNED_FAILURE:
                //Web service error message.
                status.Append(LastError.ExtendedErrorNumber);
                status.Append(": ");
                status.Append(LicenseError.GetWebServiceErrorMessage(LastError.ExtendedErrorNumber));
                break;

            default:
                //Show a standard error message.
                status.Append(LastError.ErrorNumber);
                status.Append(": ");
                status.Append(LastError.ToString());
                break;
            }

            return(status.ToString());
        }
Exemplo n.º 22
0
 void SetLastError(LastError newError)
 {
     lastError = newError;
     OnError?.Invoke(this, newError);
 }
Exemplo n.º 23
0
        public MainWindow()
        {
            InitializeComponent();

            //Setup dictionary of known devices
            var fs = File.Open("SerialNumber.txt", FileMode.OpenOrCreate, FileAccess.ReadWrite);
            var SR = new StreamReader(fs);

            using (SR)
            {
                string line;
                while ((line = SR.ReadLine()) != null)
                {
                    string[] parts = line.Split(',');
                    if (parts.Length > 1)
                    {
                        SerialtoName.Add(parts[0], parts[1]);
                        NametoSerial.Add(parts[1], parts[0]);
                    }
                }
            }
            SR.Close();

            //check for connected devices
            int count = MCP2210.M_Mcp2210_GetConnectedDevCount(DEFAULT_VID, DEFAULT_PID);

            if (count > 0)
            {
                deviceHandle = new IntPtr[count];
            }
            //Display devices available
            DeviceCount.Text = count.ToString();
            //Check that atleast one device is avalaible, then check if they are stored in memory with a given name
            //If they are not stored, label them with SPI#
            //Connect to all available devices
            if (count > 0)
            {
                for (uint i = 0; i < count; i++)
                {
                    deviceHandle[i] = MCP2210.M_Mcp2210_OpenByIndex(DEFAULT_VID, DEFAULT_PID, i, path);
                    MCP2210.M_Mcp2210_GetSerialNumber(deviceHandle[i], SN);
                    //Check for any errors
                    error = MCP2210.M_Mcp2210_GetLastError();
                    //Display any error and connection status
                    if (error != MCP2210.M_E_SUCCESS)
                    {
                        LastError.Items.Add(error.ToString());
                        LastError.Items.Add("Device cannot be opened!");
                        LastError.SelectedIndex = LastError.Items.Count - 1;
                        LastError.ScrollIntoView(LastError.SelectedItem);
                    }
                    else
                    {
                        LastError.Items.Add(error.ToString());
                        LastError.Items.Add("Device(s) Found!");
                        LastError.SelectedIndex = LastError.Items.Count - 1;
                        LastError.ScrollIntoView(LastError.SelectedItem);
                    }
                    //Check for stored device name
                    if (SerialtoName.ContainsKey(SN.ToString()))
                    {
                        Temp.Items.Add(SerialtoName[SN.ToString()]);
                        SevenSeg.Items.Add(SerialtoName[SN.ToString()]);
                        ADC.Items.Add(SerialtoName[SN.ToString()]);
                        DacDevice.Items.Add(SerialtoName[SN.ToString()]);
                        Motor.Items.Add(SerialtoName[SN.ToString()]);
                    }
                    //assign temperary device name
                    else
                    {
                        bool check = true;
                        int  spi   = 0;
                        while (check)
                        {
                            spi++;
                            if (!NametoSerial.ContainsKey("SPI" + spi.ToString()))
                            {
                                check = false;
                                SerialtoName.Add(SN.ToString(), ("SPI" + spi.ToString()));
                                NametoSerial.Add(("SPI" + spi.ToString()), SN.ToString());
                            }
                        }
                        Temp.Items.Add("SPI" + spi.ToString());
                        SevenSeg.Items.Add("SPI" + spi.ToString());
                        ADC.Items.Add("SPI" + spi.ToString());
                        DacDevice.Items.Add("SPI" + spi.ToString());
                        Motor.Items.Add("SPI" + spi.ToString());
                    }
                }
            }
            else
            {
                LastError.Items.Add(error.ToString());
                LastError.Items.Add("No Devices Found!");
                LastError.SelectedIndex = LastError.Items.Count - 1;
                LastError.ScrollIntoView(LastError.SelectedItem);
            }

            //Setup GPIO array
            for (int i = 0; i < 9; i++)
            {
                GpioPinDes[i] = 0;
            }
        }
Exemplo n.º 24
0
        //Timer setup and communication for Temperature sensor
        private void dispatcherTimerTemp_Tick(object sender, EventArgs e)
        {
            int  DeviceNumber     = Temp.SelectedIndex; //Device chosen by user on GUI
            uint pbaudRate77      = 1000000;            //baud rate
            uint pidleCsVal77     = 0x1ff;              //Bit is 1 for clock idle low
            uint pactiveCsVal77   = 0x1ef;              //GP4 set as active low CS
            uint pcsToDataDly77   = 0;                  //time delay from CS to data, quanta of 100us
            uint pdataToDataDly77 = 0;                  //time delay from data to data, quanta of 100us
            uint pdataToCsDly77   = 0;                  //time delay from data to CS, quanta of 100us
            uint ptxferSize77     = 2;                  //TC77 txfer size set to 2 bytes
            byte pspiMd77         = 0;                  //SPI mode from connected devices datasheet
            uint csmask77         = 0x10;               //1 represents CS, set GP4 as CS

            //Setup transfer and receive bytes
            byte[] txData77 = new byte[2], rxData77 = new byte[2];
            txData77[0] = 0x00;
            txData77[1] = 0x00;
            rxData77[0] = 0x00;
            rxData77[1] = 0x00;

            //Tx and Rx data from TC77
            error = MCP2210.M_Mcp2210_xferSpiDataEx(deviceHandle[DeviceNumber], txData77, rxData77, ref pbaudRate77, ref ptxferSize77, csmask77, ref pidleCsVal77, ref pactiveCsVal77,
                                                    ref pcsToDataDly77, ref pdataToCsDly77, ref pdataToDataDly77, ref pspiMd77);
            if (error != MCP2210.M_E_SUCCESS)
            {
                MCP2210.M_Mcp2210_Close(deviceHandle[DeviceNumber]);
                LastError.Items.Add(" Transfer error: " + error);
                LastError.SelectedIndex = LastError.Items.Count - 1;
                LastError.ScrollIntoView(LastError.SelectedItem);
            }

            //Setting last three bits to zero as they are don't cares from datasheet
            rxData77[1] = (byte)(rxData77[1] & 0xF8);

            byte[] temper = new byte[1];
            temper[0]   = rxData77[1];
            rxData77[1] = rxData77[0];
            rxData77[0] = temper[0];

            //Calculations and display
            temp  = BitConverter.ToInt16(rxData77, 0);
            temp /= 128;
            //GUI string display
            Temperature.Text = temp.ToString("0.00");
            //7-Seg display setup
            temp1     = (int)temp;
            DigitTemp = temp1.ToString().ToCharArray();
            if (DigitTemp.Length > 1)
            {
                DigitOneTemp = DigitTemp[0];
                DigitTwoTemp = DigitTemp[1];
            }
            else if (DigitTemp.Length > 0)
            {
                DigitOneTemp = '0';
                DigitTwoTemp = Digit[0];
            }

            if (CharToSeg.ContainsKey(DigitOneTemp) && CharToSeg.ContainsKey(DigitTwoTemp))
            {
                digitOneTemp = (uint)(0x100 | CharToSeg[DigitOneTemp]);
                digitTwoTemp = (uint)(0x080 | CharToSeg[DigitTwoTemp]);
            }
            else
            {
                digitOneTemp = (uint)(0x100 | CharToSeg['0']);
                digitTwoTemp = (uint)(0x080 | CharToSeg['0']);
            }

            //GUI bar display
            if (temp < 15)
            {
                temp = 15;
            }
            else if (temp > 40)
            {
                temp = 40;
            }
            temp          = (temp - 15) * 100 / 25;
            TempBar.Value = temp;

            //Forcing the CommandManager to raise the RequerySuggested event
            CommandManager.InvalidateRequerySuggested();
        }
Exemplo n.º 25
0
        //Connect function
        private void Connect(string Device)
        {
            int    DeviceNumber; //Device number used to select which device will be connected
            string Serial;       //Selected device Serial Number

            //Use input string to select Device number and selected device Serial Number
            if (Device == "SevenSeg")
            {
                DeviceNumber = SevenSeg.SelectedIndex;
                Serial       = SevenSeg.SelectedItem.ToString();
            }
            else if (Device == "ADC")
            {
                DeviceNumber = ADC.SelectedIndex;
                Serial       = ADC.SelectedItem.ToString();
            }
            else if (Device == "Temp")
            {
                DeviceNumber = Temp.SelectedIndex;
                Serial       = Temp.SelectedItem.ToString();
            }
            else if (Device == "Motor")
            {
                DeviceNumber = Motor.SelectedIndex;
                Serial       = Motor.SelectedItem.ToString();
            }
            else
            {
                DeviceNumber = DacDevice.SelectedIndex;
                Serial       = DacDevice.SelectedItem.ToString();
            }

            //Check if selected device serial number is in our stored list
            if (NametoSerial.ContainsKey(Serial))
            {
                //open device
                deviceHandle[DeviceNumber] = MCP2210.M_Mcp2210_OpenBySN(DEFAULT_VID, DEFAULT_PID, NametoSerial[Serial], path);
                //check for any errors
                error = MCP2210.M_Mcp2210_GetLastError();
            }
            //////////////////////////////
            else
            {
                //open device
                deviceHandle[DeviceNumber] = MCP2210.M_Mcp2210_OpenBySN(DEFAULT_VID, DEFAULT_PID, Serial, path);
                //check for any errors
                error = MCP2210.M_Mcp2210_GetLastError();
            }
            //Update error and connection status
            if (error != MCP2210.M_E_SUCCESS)
            {
                LastError.Items.Add(error.ToString());
                LastError.Items.Add("Device cannot be opened!");
                LastError.SelectedIndex = LastError.Items.Count - 1;
                LastError.ScrollIntoView(LastError.SelectedItem);
            }
            else
            {
                LastError.Items.Add(error.ToString());
                LastError.Items.Add("Device Connected!");
                LastError.SelectedIndex = LastError.Items.Count - 1;
                LastError.ScrollIntoView(LastError.SelectedItem);
            }
        }