Пример #1
0
        //
        private void UpdateTestData(Object Watch)
        {
            Double Elapsed = DB.GetTimeMs();
            Double Angle   = (Double)(2 * 3.1415 * 0.1 * Elapsed / 1000);

            Single TimeSec     = (Single)(Elapsed / 1000);
            Single SineValue   = (Single)Math.Sin(Angle);
            Single CosineVAlue = (Single)Math.Cos(Angle);

            int lck = DB.requestLock();

            if (lck >= 0)
            {
                //Write buffer Data
                if (Buffer[Buffer.Keys.First()].Count > 0)
                {
                    foreach (String key in Buffer.Keys)
                    {
                        DB.Write(key, Buffer[key]);
                        Buffer[key].Clear();
                    }
                }

                //Now write new data
                DB.Write("TEST_sin", TimeSec, SineValue);
                DB.Write("TEST_cos", TimeSec, CosineVAlue);
                DB.returnLock(lck);
            }
            else
            {
                //Write data to buffer couldnt get a lock
                Buffer["TEST_sin"].Add(new Tuple <Single, Single>(TimeSec, SineValue));
                Buffer["TEST_cos"].Add(new Tuple <Single, Single>(TimeSec, CosineVAlue));
            }
        }
Пример #2
0
        public void ProcessMessage(List <byte> inData)
        {
            byte msgkey = inData[5];
            uint msgid  = inData[7];

            int start = 9;

            switch (msgkey)
            {
            case 0xB0:
                //Recieved a new Symbol List
                start = 9;
                while (inData.Count() > (start + 2 + 2))
                {
                    Int32 SignalKey = BitConverter.ToInt16(inData.Skip(start).Take(2).ToArray(), 0);

                    ASCIIEncoding encoding = new ASCIIEncoding();

                    //Get Name, read to null charcater
                    string SignalName  = "";
                    int    NameCharCnt = 0;
                    bool   done        = false;
                    while (!done)
                    {
                        if (inData[start + 2 + NameCharCnt] == (byte)'\0')
                        {
                            SignalName = encoding.GetString(inData.Skip(start + 2).Take(NameCharCnt).ToArray());
                            break;
                        }

                        if (NameCharCnt > 25)
                        {
                            done = true;
                            break;
                        }
                        NameCharCnt = NameCharCnt + 1;
                    }

                    byte SignalType = inData[start + 2 + NameCharCnt + 1];
                    start = start + 2 + NameCharCnt + 2;
                    if (ASI_Signals.Keys.Contains(SignalKey))
                    {
                        ASI_Signals[SignalKey].Name = SignalName;
                        ASI_Signals[SignalKey].Type = (asi_dtypes)SignalType;
                        Buffer[SignalKey].Clear();
                    }
                    else
                    {
                        ASI_Signal Signal = new ASI_Signal();
                        Signal.Name = SignalName;
                        Signal.Type = (asi_dtypes)SignalType;

                        ASI_Signals.Add(SignalKey, Signal);
                        Buffer[SignalKey] = new List <Tuple <Single, Single> >();
                    }
                }
                break;

            case 0xB1:
                //Recieved Symbol Data
                start = 9;
                while (inData.Count() > (start + 1))
                {
                    Int32 SignalKey = BitConverter.ToInt16(inData.Skip(start).Take(2).ToArray(), 0);
                    if (ASI_Signals.Keys.Contains(SignalKey))
                    {
                        asi_dtypes Type    = ASI_Signals[SignalKey].Type;
                        String     Name    = ASI_Signals[SignalKey].Name;
                        Double     TimeMS  = DB.GetTimeMs();
                        Single     TimeSec = (Single)(TimeMS / 1000);

                        switch (Type)
                        {
                        case (asi_dtypes.asi_bool): {
                            bool Value = BitConverter.ToBoolean(inData.Skip(start + 2).Take(1).ToArray(), 0);
                            int  lck   = DB.requestLock();
                            if (lck >= 0)
                            {
                                //Flush the buffer
                                DB.Write(Name, Buffer[SignalKey]);
                                Buffer[SignalKey].Clear();

                                //Write new data
                                DB.Write(Name, TimeSec, Convert.ToSingle(Value));
                                DB.returnLock(lck);
                            }
                            else
                            {
                                Buffer[SignalKey].Add(new Tuple <Single, Single>(TimeSec, Convert.ToSingle(Value)));
                            }
                            start = start + 3;
                            break;
                        }

                        case (asi_dtypes.asi_byte): {
                            byte Value = inData[start + 2];
                            int  lck   = DB.requestLock();
                            if (lck >= 0)
                            {
                                //Flush the buffer
                                DB.Write(Name, Buffer[SignalKey]);
                                Buffer[SignalKey].Clear();

                                //Write new data
                                DB.Write(Name, TimeSec, Convert.ToSingle(Value));
                                DB.returnLock(lck);
                            }
                            else
                            {
                                Buffer[SignalKey].Add(new Tuple <Single, Single>(TimeSec, Convert.ToSingle(Value)));
                            }
                            start = start + 3;
                            break;
                        }

                        case (asi_dtypes.asi_double): {
                            double Value = BitConverter.ToDouble(inData.Skip(start + 2).Take(8).ToArray(), 0);
                            int    lck   = DB.requestLock();
                            if (lck >= 0)
                            {
                                //Flush the buffer
                                DB.Write(Name, Buffer[SignalKey]);
                                Buffer[SignalKey].Clear();

                                //Write new data
                                DB.Write(Name, TimeSec, Convert.ToSingle(Value));
                                DB.returnLock(lck);
                            }
                            else
                            {
                                Buffer[SignalKey].Add(new Tuple <Single, Single>(TimeSec, Convert.ToSingle(Value)));
                            }
                            start = start + 10;
                            break;
                        }

                        case (asi_dtypes.asi_float): {
                            float Value = BitConverter.ToSingle(inData.Skip(start + 2).Take(4).ToArray(), 0);
                            int   lck   = DB.requestLock();
                            if (lck >= 0)
                            {
                                //Flush the buffer
                                DB.Write(Name, Buffer[SignalKey]);
                                Buffer[SignalKey].Clear();

                                //Write new data
                                DB.Write(Name, TimeSec, Convert.ToSingle(Value));
                                DB.returnLock(lck);
                            }
                            else
                            {
                                Buffer[SignalKey].Add(new Tuple <Single, Single>(TimeSec, Convert.ToSingle(Value)));
                            }
                            start = start + 6;
                            break;
                        }

                        case (asi_dtypes.asi_int): {
                            Int16 Value = BitConverter.ToInt16(inData.Skip(start + 2).Take(2).ToArray(), 0);
                            int   lck   = DB.requestLock();
                            if (lck >= 0)
                            {
                                //Flush the buffer
                                DB.Write(Name, Buffer[SignalKey]);
                                Buffer[SignalKey].Clear();

                                //Write new data
                                DB.Write(Name, TimeSec, Convert.ToSingle(Value));
                                DB.returnLock(lck);
                            }
                            else
                            {
                                Buffer[SignalKey].Add(new Tuple <Single, Single>(TimeSec, Convert.ToSingle(Value)));
                            }
                            start = start + 4;
                            break;
                        }

                        case (asi_dtypes.asi_long): {
                            Int32 Value = BitConverter.ToInt32(inData.Skip(start + 2).Take(4).ToArray(), 0);
                            int   lck   = DB.requestLock();
                            if (lck >= 0)
                            {
                                //Flush the buffer
                                DB.Write(Name, Buffer[SignalKey]);
                                Buffer[SignalKey].Clear();

                                //Write new data
                                DB.Write(Name, TimeSec, Convert.ToSingle(Value));
                                DB.returnLock(lck);
                            }
                            else
                            {
                                Buffer[SignalKey].Add(new Tuple <Single, Single>(TimeSec, Convert.ToSingle(Value)));
                            }
                            start = start + 6;
                            break;
                        }

                        case (asi_dtypes.asi_short): {
                            Int16 Value = BitConverter.ToInt16(inData.Skip(start + 2).Take(2).ToArray(), 0);
                            int   lck   = DB.requestLock();
                            if (lck >= 0)
                            {
                                //Flush the buffer
                                DB.Write(Name, Buffer[SignalKey]);
                                Buffer[SignalKey].Clear();

                                //Write new data
                                DB.Write(Name, TimeSec, Convert.ToSingle(Value));
                                DB.returnLock(lck);
                            }
                            else
                            {
                                Buffer[SignalKey].Add(new Tuple <Single, Single>(TimeSec, Convert.ToSingle(Value)));
                            }
                            start = start + 4;
                            break;
                        }

                        case (asi_dtypes.asi_uint): {
                            UInt16 Value = BitConverter.ToUInt16(inData.Skip(start + 2).Take(2).ToArray(), 0);
                            int    lck   = DB.requestLock();
                            if (lck >= 0)
                            {
                                //Flush the buffer
                                DB.Write(Name, Buffer[SignalKey]);
                                Buffer[SignalKey].Clear();

                                //Write new data
                                DB.Write(Name, TimeSec, Convert.ToSingle(Value));
                                DB.returnLock(lck);
                            }
                            else
                            {
                                Buffer[SignalKey].Add(new Tuple <Single, Single>(TimeSec, Convert.ToSingle(Value)));
                            }
                            start = start + 4;
                            break;
                        }

                        case (asi_dtypes.asi_ulong): {
                            UInt32 Value = BitConverter.ToUInt32(inData.Skip(start + 2).Take(4).ToArray(), 0);
                            int    lck   = DB.requestLock();
                            if (lck >= 0)
                            {
                                //Flush the buffer
                                DB.Write(Name, Buffer[SignalKey]);
                                Buffer[SignalKey].Clear();

                                //Write new data
                                DB.Write(Name, TimeSec, Convert.ToSingle(Value));
                                DB.returnLock(lck);
                            }
                            else
                            {
                                Buffer[SignalKey].Add(new Tuple <Single, Single>(TimeSec, Convert.ToSingle(Value)));
                            }
                            start = start + 6;
                            break;
                        }

                        default: {
                            start = start + 1;
                            break;
                        }
                        }
                    }
                    else
                    {
                        break;
                    }
                }
                break;
            }
        }