Exemple #1
0
        public static void StartServer(DataHeader header, int port, out Parser parser)
        {
            NetworkDataSource dataSource = new NetworkDataSource(port, header);

            parser = new Parser(dataSource);
            parser.start();
        }
        public void GenerateHeader(string sheetName, string[] names, Unit[] units, string delimeter = ";")
        {
            DateTime start       = DateTime.Now;
            string   sampleInput = readLine();

            readLine();
            readLine();
            DateTime end       = DateTime.Now;
            float    deltaTime = (float)(end - start).TotalSeconds / 3;

            int        channelCount = sampleInput.Split(new[] { delimeter }, StringSplitOptions.None).Length;
            DataHeader header       = new DataHeader();

            header.Delimeter      = delimeter;
            header.DeltaTime      = deltaTime;
            header.Name           = sheetName;
            header.SourceLocation = port.PortName;
            header.SourceType     = DataSourceType.SERIAL;
            header.DataPoints     = new DataPointDefinition[channelCount];
            for (int i = 0; i < channelCount; i++)
            {
                header.DataPoints[i] = new DataPointDefinition();
                if (names != null && names.Length < i)
                {
                    header.DataPoints[i].Name = names[i];
                }
                if (units != null && units.Length < i)
                {
                    header.DataPoints[i].Units = new Unit?(units[i]);
                }
            }
        }
 public NetworkDataSource(int port, DataHeader header)
 {
     this.port   = port;
     this.header = header;
     CreateSocket();
     listenThread.Start();
     recieveThread.Start();
 }
        public void DiffrentDelimeter()
        {
            Parser     parser;
            DataHeader header = new DataHeader();

            header.Delimeter      = "&";
            header.DeltaTime      = .0f;
            header.Name           = "testHeader";
            header.SourceLocation = "127.0.0.1";
            header.SourceType     = DataSourceType.NETWORK;
            header.DataPoints     = new DataPointDefinition[2]
            {
                new DataPointDefinition()
                {
                    Index = 0,
                    Name  = "test data point",
                    Min   = new FloatRange(0, true),
                    Max   = new FloatRange(10, true),
                    Units = Lib.RandomEnumValue <Unit>(),
                    X     = 0,
                    Y     = 0,
                    Z     = 0
                },
                new DataPointDefinition()
                {
                    Index = 1,
                    Name  = "test data point",
                    Min   = new FloatRange(0, true),
                    Max   = new FloatRange(10, true),
                    Units = Lib.RandomEnumValue <Unit>(),
                    X     = 0,
                    Y     = 0,
                    Z     = 0
                }
            };

            Lib.StartServer(header, 3000, out parser);
            var connection = Lib.CreateConnectionSocket(3000);

            connection.Send(ASCIIEncoding.ASCII.GetBytes($"{5}&{7}\n"));
            Thread.Sleep(25);
            parser.UpdateBeforeDraw();
            Assert.IsNotNull(parser.currentInfo);
            Assert.IsNotNull(parser.currentInfo.values);
            Assert.AreEqual(2, parser.currentInfo.values.Length);
            Assert.AreEqual(0, parser.currentInfo.values[0].minValue);
            Assert.AreEqual(10, parser.currentInfo.values[0].maxValue);
            Assert.That(5, Is.EqualTo(parser.currentInfo.values[0].value).Within(.0001));

            Assert.AreEqual(0, parser.currentInfo.values[1].minValue);
            Assert.AreEqual(10, parser.currentInfo.values[1].maxValue);
            Assert.That(7, Is.EqualTo(parser.currentInfo.values[1].value).Within(.0001));
            parser.Dispose();
            connection.Dispose();
        }
Exemple #5
0
 public InternalDataHeader(DataHeader header)
 {
     this.DataPoints = new InternalDataPointDefinition[header.DataPoints.Length];
     for (int i = 0; i < this.DataPoints.Length; i++)
     {
         this.DataPoints[i] = new InternalDataPointDefinition(header.DataPoints[i], (uint)i);
     }
     this.DataPoints     = this.DataPoints.OrderBy(item => item.index).ToArray();
     this.Name           = header.Name;
     this.DeltaTime      = header.DeltaTime ?? .2f;
     this.SourceType     = header.SourceType;
     this.SourceLocation = header.SourceLocation;
     this.delimeter      = String.IsNullOrEmpty(header.Delimeter) ? ";" : header.Delimeter;
 }
 public FakeDataSource(string filename, DataHeader header) : base()
 {
     this.filename  = filename;
     this.latency   = (int)((header.DeltaTime ?? .2f) * 1000);
     this.header    = header;
     TestFileReader = new Thread(new ThreadStart(BackgroundEnumlateFileRead));
     TestFileReader.Start();
     readLine();
     readLine();
     readLine();
     readLine();
     readLine();
     readLine();
     readLine();
 }
        public void MultiSend()
        {
            Parser     parser;
            DataHeader header = new DataHeader();

            header.Delimeter      = ",";
            header.DeltaTime      = .0f;
            header.Name           = "testHeader";
            header.SourceLocation = "127.0.0.1";
            header.SourceType     = DataSourceType.NETWORK;
            header.DataPoints     = new DataPointDefinition[50];
            float[] values      = new float[50];
            Random  rand        = new Random();
            string  valueString = "";

            for (int i = 0; i < 50; i++)
            {
                header.DataPoints[i]       = new DataPointDefinition();
                header.DataPoints[i].Index = (uint?)i;
                header.DataPoints[i].Max   = new FloatRange((float)rand.NextDouble(), true);
                header.DataPoints[i].Min   = new FloatRange((float)rand.NextDouble(), true);
                header.DataPoints[i].Units = Lib.RandomEnumValue <Unit>();
                values[i]    = (float)rand.NextDouble();
                valueString += $"{values[i]},";
            }


            Lib.StartServer(header, 3000, out parser);
            var connection = Lib.CreateConnectionSocket(3000);

            connection.Send(ASCIIEncoding.ASCII.GetBytes($"{valueString}\n"));
            Thread.Sleep(50);
            parser.UpdateBeforeDraw();
            Assert.IsNotNull(parser.currentInfo);
            Assert.IsNotNull(parser.currentInfo.values);
            Assert.AreEqual(50, parser.currentInfo.values.Length);
            for (int i = 0; i < 50; i++)
            {
                Assert.That(header.DataPoints[i].Min.Value.value, Is.EqualTo(parser.currentInfo.values[i].minValue).Within(.0001));
                Assert.That(header.DataPoints[i].Max.Value.value, Is.EqualTo(parser.currentInfo.values[i].maxValue).Within(.0001));
                Assert.That(values[i], Is.EqualTo(parser.currentInfo.values[i].value).Within(.0001));
                Assert.AreEqual(header.DataPoints[i].Units, parser.currentInfo.values[i].unit);
            }

            parser.Dispose();
            connection.Dispose();
        }
Exemple #8
0
        public static bool ReadEmbeddedHeader(string resourceName, out DataHeader dataHeader)
        {
            var assembly = Assembly.GetExecutingAssembly();

            using (Stream stream = assembly.GetManifestResourceStream(resourceName))
                using (StreamReader reader = new StreamReader(stream))
                {
                    string result = reader.ReadToEnd();
                    File.WriteAllText("temp.xml", result);
                }

            dataHeader = new DataHeader();
            bool couldRead = DataHeader.TryReadHeader("temp.xml", out dataHeader);

            File.Delete("temp.xml");
            return(couldRead);
        }
Exemple #9
0
 public static bool TryReadHeader(string filename, out DataHeader header)
 {
     try
     {
         XmlSerializer serializer = new XmlSerializer(typeof(DataHeader));
         if (!File.Exists(filename))
         {
             Console.WriteLine($"Unable to open file {filename}");
             header = null;
             return(false);
         }
         using (var fp = File.OpenRead(filename))
         {
             header = (DataHeader)serializer.Deserialize(fp);
         }
         return(true);
     }
     catch (InvalidProgramException e)
     {
         Console.WriteLine($"Unable to parse header file:{e.InnerException}");
         header = null;
         return(false);
     }
 }
        public DataHeader GenerateHeaderFromData()
        {
            DataHeader newHeader = new DataHeader();

            newHeader.Name           = header.Name;
            newHeader.SourceLocation = header.SourceLocation;
            newHeader.SourceType     = header.SourceType;
            newHeader.DeltaTime      = header.DeltaTime;
            newHeader.Delimeter      = header.delimeter;
            newHeader.DataPoints     = new DataPointDefinition[mapping.Length];
            for (int i = 0; i < mapping.Length; i++)
            {
                newHeader.DataPoints[i]       = new DataPointDefinition();
                newHeader.DataPoints[i].Index = header.DataPoints[i].index;
                newHeader.DataPoints[i].Max   = new FloatRange(mapping[i].max, mapping[i].isMaxFixed);
                newHeader.DataPoints[i].Min   = new FloatRange(mapping[i].min, mapping[i].isMinFixed);
                newHeader.DataPoints[i].Name  = header.DataPoints[i].name;
                newHeader.DataPoints[i].Units = header.DataPoints[i].Units;
                newHeader.DataPoints[i].X     = mapping[i].position.x;
                newHeader.DataPoints[i].Y     = mapping[i].position.y;
                newHeader.DataPoints[i].Z     = mapping[i].position.z;
            }
            return(newHeader);
        }
 public SerialDataSource(string portName)
 {
     this.header = null;
     port        = new SerialPort(portName, 9600, Parity.None, 8, StopBits.One);
     port.Open();
 }
        public FakeDataSource(string filename) : base()
        {
            this.filename  = filename;
            TestFileReader = new Thread(new ThreadStart(BackgroundEnumlateFileRead));
            TestFileReader.Start();
            this.header                = new DataHeader();
            this.header.SourceType     = DataSourceType.FILE;
            this.header.SourceLocation = filename;
            readLine();                 //DASYLab - V 11.00.00
            string lineIn = readLine(); //Worksheet name: 6by10beamlayout

            string[] splits = lineIn.Split(':');
            if (splits.Length > 1)
            {
                this.header.Name = splits[1];
            }

            readLine();          //Recording date     : 7/1/2016,  4:52:39 PM

            readLine();          //Block length       : 2

            lineIn = readLine(); //Delta              : 0.2 sec.
            splits = lineIn.Split(':');
            if (splits.Length > 1)
            {
                this.header.DeltaTime = Convert.ToSingle(splits[1].Trim().Split(' ')[0]);
            }


            lineIn = readLine(); //Number of channels : 16
            splits = lineIn.Split(':');
            int numChanels = 0;

            if (splits.Length > 1)
            {
                numChanels = Convert.ToInt32(splits[1]);
            }

            // read the channel information
            lineIn = readLine();
            Regex           inputMappingRegex = new Regex("(?<Name>.*?)(?<Unit>\\[.*?\\])?;");
            MatchCollection inputMatches      = inputMappingRegex.Matches(lineIn);

            numChanels             = Math.Max(inputMatches.Count, numChanels);
            this.header.DataPoints = new DataPointDefinition[numChanels];
            for (int i = 0; i < numChanels; i++)
            {
                this.header.DataPoints[i] = new DataPointDefinition();
            }

            int j = 0;

            foreach (Match match in inputMatches)
            {
                this.header.DataPoints[j].Name = match.Groups["Name"].Value;
                if (Parser.UnitTypeParseMap.ContainsKey(match.Groups["Unit"].Value))
                {
                    this.header.DataPoints[j].Units = Parser.UnitTypeParseMap[match.Groups["Unit"].Value];
                }
                j++;
            }
        }