Defines the network that is powered by XBee devices.
Наследование: IDeviceNetwork, IScheduledTask
Пример #1
0
        public void TestDoubleRelaySwitchStates()
        {
            XBeeDeviceNetwork dn = new XBeeDeviceNetwork(new MockSerialPort());

            DoubleRelay device = new DoubleRelay();
            device.DeviceNetwork = dn;
            device.DeviceID = new byte[] { 1 };

            device.SetRelayState(0, 1);
            Assert.IsTrue(device.DeviceState.ComponentStateList[0].Value == "1");

            device.SetRelayState(0, 0);
            Assert.IsTrue(device.DeviceState.ComponentStateList[0].Value == "0");

            device.SetRelayState(0, 2);
            Assert.IsTrue(device.DeviceState.ComponentStateList[0].Value == "1");

            device.SetRelayState(1, 0);
            Assert.IsTrue(device.DeviceState.ComponentStateList[1].Value == "0");

            device.SetRelayState(1, 1);
            Assert.IsTrue(device.DeviceState.ComponentStateList[1].Value == "1");

            device.SetRelayState(2, 0);
            Assert.IsTrue(device.DeviceState.ComponentStateList[1].Value == "0");

            device.SetRelayState(2, 1);
            Assert.IsTrue(device.DeviceState.ComponentStateList[1].Value == "1");
        }
        public IDeviceNetwork CreateDeviceNetwork(Dictionary<string, string> configuration)
        {
            // get serial port configuration from the configuration dictionary
            baudRate = UInt32.Parse(configuration["BaudRate"]);
            parity = (SerialParity)Enum.Parse(typeof(SerialParity), configuration["SerialParity"], true);
            stopBit = (SerialStopBitCount)Enum.Parse(typeof(SerialStopBitCount), configuration["SerialStopBitCount"], true);
            dataBits = UInt16.Parse(configuration["DataBits"]);
            apiVersion = (APIVersion)Enum.Parse(typeof(APIVersion), configuration["APIVersion"], true);

            // create the serial port
            IXBeeSerialPort serialPort = CreateSerialPortWithSavedConfigurationParameters();

            // now create the device network with this serial port
            XBeeDeviceNetwork network = new XBeeDeviceNetwork(serialPort);

            return network;
        }