static void Main(string[] args) { var bee = new XBee {ApiType = ApiTypeValue.Enabled}; bee.SetConnection(new SerialConnection("COM4", 9600)); var request = new ATCommand(AT.ApiEnable) { FrameId = 1 }; var frame = bee.ExecuteQuery(request, 1000); var value = ((ATCommandResponse) frame).Value; Console.WriteLine(String.Format("API type: {0}", ((ATLongValue) value).Value)); request = new ATCommand(AT.BaudRate) { FrameId = 1 }; frame = bee.ExecuteQuery(request, 1000); value = ((ATCommandResponse) frame).Value; Console.WriteLine(String.Format("Baud rate: {0}", ((ATLongValue) value).Value)); request = new ATCommand(AT.MaximumPayloadLenght) { FrameId = 1 }; frame = bee.ExecuteQuery(request, 1000); value = ((ATCommandResponse) frame).Value; Console.WriteLine(String.Format("Maximum Payload is: {0}", ((ATLongValue) value).Value)); request = new ATCommand(AT.FirmwareVersion) { FrameId = 1 }; frame = bee.ExecuteQuery(request, 1000); value = ((ATCommandResponse) frame).Value; Console.WriteLine(String.Format("Firmware Version: {0:X4}", ((ATLongValue) value).Value)); request = new ATCommand(AT.NodeDiscover) { FrameId = 1 }; bee.Execute(request); while (true) { Thread.Sleep(100); } }
static void RunModule1() { using (XBee xbee = new XBee("COM3", 9600, ApiType.Enabled)) { xbee.FrameReceived += new FrameReceivedEventHandler(xbee_FrameReceived); xbee.Open(); // discovering the network AtCommand at = new NodeDiscoverCommand(); xbee.Execute(at); Thread.Sleep(10 * 1000); xbee.Execute(at); Thread.Sleep(10 * 1000); xbee.StopReceiveData(); Console.WriteLine("stopped master"); } }
static void Main(string[] args) { var bee = new XBee { ApiType = ApiTypeValue.Enabled }; bee.SetConnection(new SerialConnection("COM4", 9600)); var request = new ATCommand(AT.ApiEnable) { FrameId = 1 }; var frame = bee.ExecuteQuery(request, 1000); var value = ((ATCommandResponse)frame).Value; Console.WriteLine(String.Format("API type: {0}", ((ATLongValue)value).Value)); request = new ATCommand(AT.BaudRate) { FrameId = 1 }; frame = bee.ExecuteQuery(request, 1000); value = ((ATCommandResponse)frame).Value; Console.WriteLine(String.Format("Baud rate: {0}", ((ATLongValue)value).Value)); request = new ATCommand(AT.MaximumPayloadLenght) { FrameId = 1 }; frame = bee.ExecuteQuery(request, 1000); value = ((ATCommandResponse)frame).Value; Console.WriteLine(String.Format("Maximum Payload is: {0}", ((ATLongValue)value).Value)); request = new ATCommand(AT.FirmwareVersion) { FrameId = 1 }; frame = bee.ExecuteQuery(request, 1000); value = ((ATCommandResponse)frame).Value; Console.WriteLine(String.Format("Firmware Version: {0:X4}", ((ATLongValue)value).Value)); request = new ATCommand(AT.NodeDiscover) { FrameId = 1 }; bee.Execute(request); while (true) { Thread.Sleep(100); } }
public static void Main() { using (XBee xbee = new XBee("COM1", 9600)) { xbee.FrameReceived += new FrameReceivedEventHandler(xbee_OnPacketReceived); xbee.Open(); // read power supply xbee.Execute(new SupplyVoltageCommand()); Thread.Sleep(10 * 60 * 1000); } }
public bool SpoolMessage(MailMessage message, out string reply) { reply = null; string subject = message.Subject; if (String.IsNullOrEmpty(subject)) { reply = "Missing subject"; return(false); } string[] parts = subject.Split('|'); if (parts.Length == 0) { reply = "Missing command arguments seperator"; return(false); } if (parts[0] == "NI") { using (XBee xbee = new XBee("COM4", ApiType.Enabled)) { xbee.Open(); XBeeResponse res = xbee.Execute(new NodeIdentifierCommand()); if (res == null) { reply = "Could not execute NI command"; return(false); } AtCommandResponse atr = res as AtCommandResponse; if (atr != null) { NodeIdentifier ni = NodeIdentifier.Parse(atr); if (ni != null) { reply = "XBee module response: " + ni.GetType() + " = " + ni.Identifier; return(false); } } } } return(true); }
public void TestXBeeConnectionExecute() { var conn = new Mock<IXBeeConnection>(); byte[] result = null; conn.Setup(connection => connection.Write(It.IsAny<byte[]>())).Callback((byte[] b) => result = b); var xbee = new XBee(); xbee.SetConnection(conn.Object); xbee.Execute(new ATCommand(AT.BaudRate) { FrameId = 1 }); conn.Verify(connection => connection.SetPacketReader(It.IsAny<IPacketReader>())); Assert.That(result, Is.EqualTo(new byte[] { 0x7E, 0x00, 0x04, 0x08, 0x01, 0x42, 0x44, 0x70 })); }
public void TestXBeeConnectionExecute() { var conn = new Mock <IXBeeConnection>(); byte[] result = null; conn.Setup(connection => connection.Write(It.IsAny <byte[]>())).Callback((byte[] b) => result = b); var xbee = new XBee(); xbee.SetConnection(conn.Object); xbee.Execute(new ATCommand(AT.BaudRate) { FrameId = 1 }); conn.Verify(connection => connection.SetPacketReader(It.IsAny <IPacketReader>())); Assert.That(result, Is.EqualTo(new byte[] { 0x7E, 0x00, 0x04, 0x08, 0x01, 0x42, 0x44, 0x70 })); }