示例#1
0
        //Untested
        public void SetDeviceName(string newName)
        {
            name = newName;

            byte[] namePart = GetNamePart(newName, 1);
            if (namePart == null)
            {
                return;
            }
            CANInterface.SendMessage(this, Commands.CmdSysPName1, namePart);

            namePart = GetNamePart(newName, 2);
            if (namePart == null)
            {
                return;
            }
            CANInterface.SendMessage(this, Commands.CmdSysPName2, namePart);

            namePart = GetNamePart(newName, 3);
            if (namePart == null)
            {
                return;
            }
            CANInterface.SendMessage(this, Commands.CmdSysPName3, namePart);
        }
示例#2
0
        /// <summary>
        /// Polls the network with the given command, then fires the PollRecieved event with the results.
        /// </summary>
        /// <param name="sendCommand">The command to send.</param>
        /// <param name="nodes">The Nodes to poll. Leave null for all.</param>
        /// <param name="devices">The Devices to poll on each Node. Leave null for all, set to 0 to poll only Nodes.</param>
        public NewPing(Commands sendCommand, Dictionary <byte, List <byte> > nodeDevices)
        {
            expectedResult = responseCommands[sendCommand];

            //If given an empty list, ping just the nodes
            //Probably better to just throw an exception, actually
            if (nodeDevices.Count == 0)
            {
                for (byte i = 1; i < 127; i++)
                {
                    nodeDevices.Add(i, new List <byte>());
                }
            }

            foreach (byte node in nodeDevices.Keys)
            {
                lastMessage = CANInterface.SendMessage(node, 0, sendCommand);
                foreach (byte device in nodeDevices[node])
                {
                    lastMessage = CANInterface.SendMessage(node, device, sendCommand);
                }
            }

            CANInterface.MessageSent     += CANInterface_MessageSent;
            CANInterface.MessageReceived += CANInterface_MessageReceived;
            waitForResponse.Interval      = 100;
            waitForResponse.Tick         += WaitForResponse_Tick;
        }
示例#3
0
        /// <summary>
        /// Sets the brightness of the light as a percent.
        /// </summary>
        /// <param name="brightness">The brightness, as a value from 0-100.</param>
        private void SetBrightness(byte brightness)
        {
            if (brightness > 100)
            {
                throw new Exception("Cannot set light brightness higher than 100%.");
            }

            CANInterface.SendMessage(this, Commands.CmdConValue, new byte[] { brightness });
        }
示例#4
0
        /// <summary>
        /// Sends the given command to the given device, then fires the PollRecieved event with the result.
        /// </summary>
        /// <param name="sendCommand">The command to send.</param>
        /// <param name="nodeId">The Node to poll.</param>
        /// <param name="deviceId">The Device to poll on that Node.</param>
        public CANPing(Commands sendCommand, byte nodeId, byte deviceId)
        {
            expectedResult = responseCommands[sendCommand];

            lastMessage = CANInterface.SendMessage(nodeId, deviceId, sendCommand);

            CANInterface.MessageSent     += CANInterface_MessageSent;
            CANInterface.MessageReceived += CANInterface_MessageReceived;
            waitForResponse.Interval      = 100;
            waitForResponse.Tick         += WaitForResponse_Tick;
        }
示例#5
0
        /// <summary>
        /// Set brightness value over time.
        /// </summary>
        /// <param name="brightness">The brightness, as a value from 0-100.</param>
        /// <param name="time">The time in seconds to reach the brightness value, as a value between 0 - 65535.</param>
        public void SetFade(byte brightness, int time)
        {
            if (time < 0 || time > 65535)
            {
                throw new Exception("Time value for SetFade must be a value between 0 - 65535.");
            }

            byte time1 = BitConverter.GetBytes(time)[1];
            byte time2 = BitConverter.GetBytes(time)[0];

            CANInterface.SendMessage(this, Commands.CmdConSetFade, new byte[] { brightness, time1, time2 });
        }
示例#6
0
        /// <summary>
        /// Polls the network with the given command, then fires the PollRecieved event with the results.
        /// </summary>
        /// <param name="sendCommand">The command to send.</param>
        /// <param name="nodes">The Nodes to poll.</param>
        /// <param name="devices">The Devices to poll on each Node.</param>
        public CANPing(Commands sendCommand, Dictionary <byte, List <byte> > nodeDevices)
        {
            if (nodeDevices.Count == 0)
            {
                throw new Exception("Cannot ping 0 nodes.");
            }

            expectedResult = responseCommands[sendCommand];

            foreach (byte node in nodeDevices.Keys)
            {
                lastMessage = CANInterface.SendMessage(node, 0, sendCommand);
                foreach (byte device in nodeDevices[node])
                {
                    lastMessage = CANInterface.SendMessage(node, device, sendCommand);
                }
            }

            CANInterface.MessageSent     += CANInterface_MessageSent;
            CANInterface.MessageReceived += CANInterface_MessageReceived;
            waitForResponse.Interval      = 100;
            waitForResponse.Tick         += WaitForResponse_Tick;
        }
示例#7
0
 /// <summary>
 /// Sets the last “On” value to the current value. Used when a switch is
 /// dimming the output and is then released.
 /// </summary>
 public void Release()
 {
     CANInterface.SendMessage(this, Commands.CmdConRelease);
 }
示例#8
0
 public void FullOn()
 {
     CANInterface.SendMessage(this, Commands.CmdConDClk);
 }
示例#9
0
 /// <summary>
 /// Sets whether the light is on (at a preset brightness), or off.
 /// </summary>
 /// <param name="on">if set to <c>true</c>, the light is [on].</param>
 public void SetOnOff(bool on)
 {
     CANInterface.SendMessage(this, on ? Commands.CmdConOn : Commands.CmdConOff);
 }
示例#10
0
 /// <summary>
 /// Toggles the light on and off.
 /// </summary>
 public void ToggleOnOff()
 {
     CANInterface.SendMessage(this, Commands.CmdConOnOff);
 }
示例#11
0
 public void OnDeserializingMethod()
 {
     CANInterface.MessageReceived += CANInterface_MessageReceived;
     CANInterface.SendMessage(this, Commands.CmdSysEStateZZ);
 }
示例#12
0
 /// <summary>
 /// Fade one step up or down and reverse direction when 0 or 100% is reached.
 /// </summary>
 public void FadeContinuous()
 {
     CANInterface.SendMessage(this, Commands.CmdConFadeCont);
 }
示例#13
0
 /// <summary>
 /// Fade down one step and stop when 0% is reached.
 /// </summary>
 public void FadeDown()
 {
     CANInterface.SendMessage(this, Commands.CmdConFadeDwn);
 }
示例#14
0
 /// <summary>
 /// Fade up one step and stop when 100% is reached.
 /// </summary>
 public void FadeUp()
 {
     CANInterface.SendMessage(this, Commands.CmdConFadeUp);
 }