public void SimpleRoundTripTest()
        {
            TouchstoneOptions options = new TouchstoneOptions
            {
                Format        = FormatType.DecibelAngle,
                FrequencyUnit = FrequencyUnit.GHz,
                Parameter     = ParameterType.Scattering,
                Resistance    = 50
            };

            string filePath = Path.GetTempFileName();

            var ts      = new Touchstone(2, options);
            int gain_dB = 0;

            for (double f = 1e9; f <= 2e9; f += 0.1e9)
            {
                var gain = NetworkParameter.FromPolarDecibelDegree(gain_dB, 0);
                ts.NetworkParameters[f, 2, 1] = gain;
            }

            ts.Write(filePath);

            var result = Touchstone.ReadAllData(filePath);

            result.Count.Should().Be(ts.NetworkParameters.Count);

            foreach (var freq in result.Frequencies)
            {
                ts.NetworkParameters[freq, 2, 1].Should().Be(result[freq, 2, 1]);
            }
        }
        public void ConversionTests()
        {
            NetworkParameter s = NetworkParameter.FromPolarDegree(100, 180);

            s.Magnitude_dB.Should().Be(20);
            s.Phase_deg.Should().Be(180);

            NetworkParameter s2 = NetworkParameter.FromPolarDecibelDegree(20, 180);

            s2.Magnitude.Should().Be(100);
            s.Phase_deg.Should().Be(180);

            NetworkParameter s3 = new NetworkParameter(10, 10);

            s3.Phase_deg.Should().Be(45);

            NetworkParameter s4 = new NetworkParameter(10, -10);

            s4.Phase_deg.Should().Be(-45);

            NetworkParameter s5 = NetworkParameter.FromPolarDegree(100 * Math.Sqrt(2), 45);

            s5.Real.Should().BeApproximately(100, .001);
            s5.Imaginary.Should().BeApproximately(100, .001);
        }
        public void SimpleCascade()
        {
            NetworkParameter infiniteReturnLoss = NetworkParameter.FromPolarDecibelDegree(double.NegativeInfinity, 0);
            NetworkParameter three_dBLoss       = NetworkParameter.FromPolarDecibelDegree(3, 0);
            NetworkParameter five_dBLoss        = NetworkParameter.FromPolarDecibelDegree(5, 0);

            ScatteringParametersMatrix s1 = new ScatteringParametersMatrix(2)
            {
        public void ComparisonTests()
        {
            NetworkParameter s  = NetworkParameter.FromPolarDecibelDegree(20, 0);
            NetworkParameter s2 = NetworkParameter.FromPolarDecibelDegree(10, 180);

            //(s > s2).Should().BeTrue("magnitude is prioritized");

            NetworkParameter s_0 = NetworkParameter.FromPolarDecibelDegree(20, 10);
            //(s < s_0).Should().BeTrue("greater angle");

            NetworkParameter s3 = NetworkParameter.FromPolarDecibelDegree(20, 100);
            NetworkParameter s4 = NetworkParameter.FromPolarDegree(100, 100);

            (s3 == s4).Should().BeTrue();
        }
        private List <NetworkParameter> ComboBoxSelectionChanged(ModelTabelParameter item, List <int> DataSensors, DataGrid dataGrid)
        {
            var ListNetworkParameter    = db.GetItems <ModelTabelNetworkParameter>().Where(w => w.Id_Parameter == item.Id).Select(s => s.Array_coordinates).ToList();
            var ListConstantCoordinates = GetConstantCoordinatesNetwork(ListNetworkParameter, dataGrid);
            var array_gaps = JsonConvert.DeserializeObject <List <int> >(db.GetItem <ModelGaps>(item.Id_gaps).Array_gaps);

            var CurrentStateSystem = new NetworkParameter()
            {
                Name = "P-" + item.Name_parameter,
                Array_coordinates = CurrentCoordinates.GetCurrentStateSystemCoordinatess(GetConstantCoordinatesNetwork(ListNetworkParameter, dataGrid), GetArray(DataSensors, array_gaps))
            };

            ListConstantCoordinates.Insert(0, CurrentStateSystem);

            return(ListConstantCoordinates);
        }
        private void applyParameters()
        {
            NetworkParameter        networkParameter        = this.parameters.GetNetworkParameter();
            CameraParameter         cameraParameter         = this.parameters.GetCameraParameter();
            BarcodeImagingParameter barcodeImagingParameter = this.parameters.GetBarcodeImagingParameter();
            PersistencyParameter    persistencyParameter    = this.parameters.GetPersistencyParameter();

            MES.Processor.ModuleConfiguration.Default_BarCodeScanningTimes    = barcodeImagingParameter.ScanTimes;
            MES.Processor.ModuleConfiguration.Default_FailureRetryTimes       = barcodeImagingParameter.FailureRetryTimes;
            MES.Processor.ModuleConfiguration.IsExtractingBarCodes            = barcodeImagingParameter.IsExtractingBarCode;
            MES.Processor.ModuleConfiguration.IsCheckingSkewAngle             = barcodeImagingParameter.IsCheckingSkewAngle;
            MES.Processor.ModuleConfiguration.Default_ImageRotationDegree     = barcodeImagingParameter.ImageRotationDegree;
            MES.Processor.ModuleConfiguration.Default_ImageRotationParameters = new Dictionary <string, object>()
            {
                { "RotationAtPercentageOfImageWidth", barcodeImagingParameter.RotationAtPercentageOfImageWidth },
                { "RotationAtPercentageOfImageHeight", barcodeImagingParameter.RotationAtPercentageOfImageHeight },
                { "IsNoClip", barcodeImagingParameter.IsNoClip }
            };

            MES.Acquirer.ModuleConfiguration.Default_Timeout          = cameraParameter.DeviceTimeout;
            MES.Acquirer.ModuleConfiguration.Default_CameraParameters = new Dictionary <string, object>()
            {
                { "exposure", cameraParameter.Exposure },
                { "gain", cameraParameter.Gain },
                { "imgdataformat", cameraParameter.ImageDataFormat },
                { "downsampling_type", cameraParameter.DownSamplingType },
                { "downsampling", cameraParameter.DownSampling },
                { "height", cameraParameter.OutputImageHeight },
                { "width", cameraParameter.OuputImageWidth },
                { "sharpness", cameraParameter.Sharpness },
                { "gammaY", cameraParameter.GammaY },
                { "gammaC", cameraParameter.GammaC },
                { "exp_priority", cameraParameter.ExposurePriority },
                { "bpc", cameraParameter.EnableBPC ? 1 : 0 },
                { "auto_bandwidth_calculation", cameraParameter.EnableAutoBandWidthCalculation ? 1 : 0 },
                { "buffer_policy", cameraParameter.BufferPolicy },
                //{"limit_bandwidth", cameraParameter.LimitBandWidth}
                { "aeag", cameraParameter.EnableAEAG ? 1 : 0 },
                { "offsetX", cameraParameter.OuputImageOffsetX },
                { "offsetY", cameraParameter.OutputImageOffsetY }
            };

            MES.Acquirer.ModuleConfiguration.Default_ImageOuputFormat = cameraParameter.ImageOutputFormat;
        }
Beispiel #7
0
        private void applyParameters()
        {
            NetworkParameter     networkParameter     = this.parameters.GetNetworkParameter();
            SerialPortParameter  serialPortParameter  = this.parameters.GetSerialPortParameter();
            TimerParameter       timerParameter       = this.parameters.GetTimerParameter();
            PersistencyParameter persistencyParameter = this.parameters.GetPersistencyParameter();

            ModuleConfiguration.Default_LocalAddress      = networkParameter.LocalAddress;
            ModuleConfiguration.Default_LocalPort         = networkParameter.LocalPort;
            ModuleConfiguration.Default_MulticastAddress  = networkParameter.RemoteAddress; //networkParameter.MulticastAddress;
            ModuleConfiguration.Default_MulticastPort     = networkParameter.RemotePort;    //networkParameter.MulticastPort;
            ModuleConfiguration.Default_TimeToLive        = networkParameter.TimeToLive;
            ModuleConfiguration.Default_CommunicationType = networkParameter.CommunicationType;
            ModuleConfiguration.Default_PipeName          = networkParameter.PipeName;

            ModuleConfiguration.Default_TimerInterval = timerParameter.TimerInterval;

            ModuleConfiguration.Default_SerialPortBaudRate          = serialPortParameter.SerialPortBaudRate;
            ModuleConfiguration.Default_SerialPortDataBits          = serialPortParameter.SerialPortDataBits;
            ModuleConfiguration.Default_SerialPortEncodingCodePage  = serialPortParameter.SerialPortEncodingCodePage;
            ModuleConfiguration.Default_SerialPortHandShake         = serialPortParameter.SerialPortHandShake;
            ModuleConfiguration.Default_SerialPortName              = serialPortParameter.SerialPortName;
            ModuleConfiguration.Default_SerialPortParity            = serialPortParameter.SerialPortParity;
            ModuleConfiguration.Default_SerialPortReadBufferSize    = serialPortParameter.SerialPortReadBufferSize;
            ModuleConfiguration.Default_SerialPortReadTimeout       = serialPortParameter.SerialPortReadTimeout;
            ModuleConfiguration.Default_SerialPortRtsEnable         = serialPortParameter.SerialPortRtsEnable;
            ModuleConfiguration.Default_SerialPortStopBits          = serialPortParameter.SerialPortStopBits;
            ModuleConfiguration.Default_SerialPortWriteBufferSize   = serialPortParameter.SerialPortWriteBufferSize;
            ModuleConfiguration.Default_SerialPortWriteTimeout      = serialPortParameter.SerialPortWriteTimeout;
            ModuleConfiguration.Default_SerialPortDtrEnable         = serialPortParameter.SerialPortDtrEnable;
            ModuleConfiguration.Default_SerialPortMode              = serialPortParameter.SerialPortMode;
            ModuleConfiguration.Default_SerialPortExpectedDataValue = serialPortParameter.SerialPortExpectedDataValue;

            ModuleConfiguration.Default_SequenceMask      = serialPortParameter.SequenceMask;
            ModuleConfiguration.Default_SequenceSeparator = serialPortParameter.SequenceSeparator;

            ModuleConfiguration.Default_SerialPortIsReadingByLine = serialPortParameter.IsReadingByLine;
            ModuleConfiguration.Default_SerialPortIsBroadcasting  = serialPortParameter.IsBroadcasting;
        }
Beispiel #8
0
        public void TestNearest()
        {
            var collection = new NetworkParametersCollection <ScatteringParametersMatrix>(2);

            for (int i = 1; i <= 20; i++)
            {
                collection[i * 1.0e9, 2, 1] = NetworkParameter.FromPolarDecibelDegree(i, 0);
            }

            collection.Nearest(0)[2, 1].Should().Be(NetworkParameter.FromPolarDecibelDegree(1, 0),
                                                    "0 is out of bounds but closest to 1e9");

            collection.Nearest(1.0e9)[2, 1].Should().Be(NetworkParameter.FromPolarDecibelDegree(1, 0),
                                                        "1e9 is equal to 1e9");

            collection.Nearest(1.51e9)[2, 1].Should().Be(NetworkParameter.FromPolarDecibelDegree(2, 0),
                                                         "1.51e9 is closer to 2e9");

            collection.Nearest(19.9e9)[2, 1].Should().Be(NetworkParameter.FromPolarDecibelDegree(20, 0),
                                                         "19.9e9 is nearest to 20e9");

            collection.Nearest(21e9)[2, 1].Should().Be(NetworkParameter.FromPolarDecibelDegree(20, 0),
                                                       "21e9 is outside of bounds but nearest to 20e9");
        }
        private List <NetworkParameter> ParseParameters(List <string> data)
        {
            List <NetworkParameter> parameters = new List <NetworkParameter>();


            for (int j = 0; j < data.Count; j += 2)
            {
                double val1 = 0, val2 = 0;
                try
                {
                    val1 = double.Parse(data[j]);
                    val2 = double.Parse(data[j + 1]);
                }
                catch (FormatException)
                {
                    ThrowHelper("Data", "Invalid data format");
                }
                NetworkParameter param = new NetworkParameter();
                switch (Options.Format)
                {
                case FormatType.DecibelAngle:
                    param = NetworkParameter.FromPolarDecibelDegree(val1, val2);
                    break;

                case FormatType.MagnitudeAngle:
                    param = NetworkParameter.FromPolarDegree(val1, val2);
                    break;

                case FormatType.RealImaginary:
                    param = new NetworkParameter(val1, val2);
                    break;
                }
                parameters.Add(param);
            }
            return(parameters);
        }
Beispiel #10
0
 public NetworkParameterElement(NetworkParameter param) => parameter = param;
        private void startListener()
        {
            NetworkParameter networkParameter = this.parameters.GetNetworkParameter();

            this.communicationManager = new CommunicationManager()
            {
                LocalAddress  = networkParameter.LocalAddress,  //ConfigurationManager.AppSettings.Get("LocalAddress"),
                RemoteAddress = networkParameter.RemoteAddress, //networkParameter.MulticastAddress, //ConfigurationManager.AppSettings.Get("RemoteAddress"),
                LocalPort     = networkParameter.LocalPort,     //int.Parse(ConfigurationManager.AppSettings.Get("LocalPort")),
                RemotePort    = networkParameter.RemotePort,    //networkParameter.MulticastPort, //int.Parse(ConfigurationManager.AppSettings.Get("RemotePort")),
                TimeToLive    = networkParameter.TimeToLive,    //int.Parse(ConfigurationManager.AppSettings.Get("TimeToLive"))
                PipeName      = networkParameter.PipeName
            };

            //this.communicationManager.Start();

            this.communicationManager.Start((int)(networkParameter.CommunicationType));

            byte[] bytesReceived = null;

            int bytesCount = -1;

            while (true)
            {
                bytesReceived = this.communicationManager.Receive(out bytesCount);

                if ((bytesCount > 0) && (bytesReceived != null) && (bytesReceived.Length > 0))
                {
                    DataIdentifier identifier = CommonUtility.BinaryDeserialize(bytesReceived) as DataIdentifier; //JsonUtility.JsonDeserialize(bytesReceived, typeof(DataIdentifier), null, null) as DataIdentifier;

                    DataPair pair = this.doAcquisition(identifier);

                    pair = this.doComputation(pair);

                    pair = this.doCorrelation(pair.Identifier, pair.Items[0]);

                    this.saveDataPair(pair);

                    this.Invoke(new Action(() =>
                    {
                        using (MemoryStream stream = new MemoryStream(pair.Items[1].DataBytes))
                        {
                            this.bitmap = Bitmap.FromStream(stream) as Bitmap;
                            this.pictureBoxAcquiredImage.Image = this.bitmap;
                            this.pictureBoxAcquiredImage.Refresh();
                        }

                        if ((pair.Items[0].DataParameters != null) && (pair.Items[1].DataParameters.Count > 0))
                        {
                            //this.listBoxBarcodes.DataSource = pair.Items[0].DataParameters[0].Value.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);

                            string barcodes = pair.Items[1].GetParameterValue("BarCodes");

                            this.listBoxBarcodes.DataSource = !String.IsNullOrEmpty(barcodes) ? barcodes.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries) : null;
                        }
                        else
                        {
                            this.listBoxBarcodes.DataSource = null;
                        }

                        this.listBoxBarcodes.Refresh();

                        this.tabControlMain.SelectedTab = this.tabPageBarcodes;

                        this.toolStripStatusLabelCurrentStatus.Text = this.currentImageFile;

                        if (this.bindingSource.Count == 20)
                        {
                            string imageUrlMappingKey = this.bindingSource[0].ToString();

                            if (this.imageUrlMappings.ContainsKey(imageUrlMappingKey))
                            {
                                this.imageUrlMappings.Remove(imageUrlMappingKey);
                            }

                            this.bindingSource.RemoveAt(0);
                        }

                        this.bindingSource.Add(new DataParameter()
                        {
                            Name = this.currentImageFile, Value = this.currentImageFile
                        });

                        this.dataGridViewRecentImages.Refresh();
                    }));
                }
            }
        }