예제 #1
0
        public void UDPListenerEventHandlerMessageReceived(object sender, UDPListenerEventArgs e)
        {
            byte[] busData = new byte[10];
            string message = e.Message;
            ConcurrentDictionary <int, string> offsets = new ConcurrentDictionary <int, string>();

            message = message.TrimEnd(',');
            string[] items = message.Split(',');
            foreach (string item in items)
            {
                string[] offset = item.Split(':');
                offsets.TryAdd(Convert.ToInt32(offset[0]), offset[1]);
            }
            foreach (Output item in outputs)
            {
                item.setState(offsets);
                switch (item.Type)
                {
                case OutputType.ToggleOutput:
                {
                    if (item.State == "ON")
                    {
                        busData[9 - item.BusIndex] = (byte)(busData[9 - item.BusIndex] | (1 << 7 - item.ByteIndex));

                        // MessageBox.Show(busData[9 - item.BusIndex].ToString());
                    }
                    break;
                }
                }
            }
            //  device.AuxilaryBusSetData(1, busData);
            device.AuxilaryBusSetData(1, 1, busData);
        }
예제 #2
0
        public void UDPListenerEventHandlerMessageReceived(object sender, UDPListenerEventArgs e)
        {
            //message format "offset:value,offset:value,"

            byte[] busData = new byte[10];
            string message = e.Message; //copy the received message into our buffer
            ConcurrentDictionary <int, string> offsets = new ConcurrentDictionary <int, string>();

            message = message.TrimEnd(',');      //clean up the trailing , on the message
            string[] items = message.Split(','); //split into individual items tokenized by ,
            foreach (string item in items)       //iterate through the received items
            {
                string[] offset = item.Split(':');
                offsets.TryAdd(Convert.ToInt32(offset[0]), offset[1]); //convert into key[offset],value[value[ into dictionary
            }
            foreach (Output item in outputs)                           //iterate over each item in outputs for this device and attempt to set state
            {
                item.setState(offsets);
                switch (item.Type)
                {
                case OutputType.ToggleOutput:
                {
                    if (item.State == "ON")         //since we create new bus data each time we only need to set the "Ons"
                    {
                        busData[9 - item.BusIndex] = (byte)(busData[9 - item.BusIndex] | (1 << 7 - item.ByteIndex));

                        // MessageBox.Show(busData[9 - item.BusIndex].ToString());
                    }
                    break;
                }
                }
            }
            //  device.AuxilaryBusSetData(1, busData);
            device.AuxilaryBusSetData(1, 1, busData);
        }