Example #1
0
        private void OnTick(object sender, ElapsedEventArgs args)
        {
            foreach (KeyValuePair<WebSocketSession, Client> pair in Client.clients)
            {
                DeviceValue value = new DeviceValue();
                value.unit = "mV";
                value.flow = "DC";
                value.value = (Math.Sin(lastValue % Math.PI*2) * 5.0).ToString(System.Globalization.CultureInfo.InvariantCulture);

                pair.Value.SendValue(value);
            }

            lastValue += 0.1;
        }
Example #2
0
        public void SendValue(DeviceValue value)
        {
            if (RecievesValues && LastSend.AddSeconds(Intervall) <= DateTime.Now)
            {
                Command command = new Command();
                command.command = "update";
                command.parameter = new Dictionary<string, string>() {
                    {"value", value.value},
                    {"unit", value.unit},
                    {"polarity", value.flow},
                    {"timestamp",  (value.timestamp.Ticks / TimeSpan.TicksPerMillisecond).ToString(CultureInfo.InvariantCulture)}
                };

                Session.Send(JsonConvert.SerializeObject(command));
                LastSend = DateTime.Now;
            } 
        }
Example #3
0
        public static DeviceValue FromString(String source)
        {
            DeviceValue value = new DeviceValue();

            String[] values = source.Split(new String[] {" ", "\t"}, StringSplitOptions.RemoveEmptyEntries);
            
            int startsWithComma = values[0] == "." ? 1 : 0;

            // Wert in Einzelteile zerteilen
            if (values.Length == 2 || startsWithComma != 0)
            {
                String tempValue = values[0 + startsWithComma];
                tempValue = tempValue.Replace("O", "0");
                tempValue = tempValue.Replace("L", "0");

                while (tempValue.StartsWith("00"))
                    tempValue = tempValue.Remove(0, 1);

                value.flow = "";
                value.value = tempValue;
                value.unit = values[1 + startsWithComma];
                value.timestamp = DateTime.Now;
            }
            else
            if (values.Length == 3)
            {
                String tempValue = values[1];

                while (tempValue.StartsWith("00"))
                    tempValue = tempValue.Remove(0, 1);

                value.flow = values[0];
                value.value = tempValue;
                value.unit = values[2];
                value.timestamp = DateTime.Now;
            }

            return value;
        }