ClearCore Library
Loading...
Searching...
No Matches
WriteXBeeOutput.cpp

Return to SDK Examples for Microchip Studio

1/*
2 * Title: WriteXBeeOutput
3 *
4 * Objective:
5 * This example demonstrates how to write data to an XBee device connected to
6 * the ClearCore's XBee port.
7 *
8 * Description:
9 * This example sets up the XBee connector and writes data to the XBee
10 * device. Any data received is then read-in and written to the USB serial
11 * port.
12 *
13 * Requirements:
14 * ** An XBee device connected to ClearCore's XBee connector. Use the XBee in
15 * Transparent Mode to simply send and receive data without packet structuring.
16 * ** Another remote XBee, also in transparent mode and configured to communicate
17 * with the first.
18 *
19 * Links:
20 * ** ClearCore Documentation: https://teknic-inc.github.io/ClearCore-library/
21 * ** ClearCore Manual: https://www.teknic.com/files/downloads/clearcore_user_manual.pdf
22 *
23 * Last Modified: 1/21/2020
24 * Copyright (c) 2020 Teknic Inc. This work is free to use, copy and distribute under the terms of
25 * the standard MIT permissive software license which can be found at https://opensource.org/licenses/MIT
26 */
27
28#include "ClearCore.h"
29
30// ClearCore provides three separate serial interfaces to send communications.
31// The three options are ConnectorUsb, ConnectorCOM0, or ConnectorCOM1
32#define SerialPort ConnectorUsb
33
34// Select the baud rate to match the target device.
35#define serialBaudRate 9600
36
37int main() {
38 // Put your setup code here, it will run once:
39
40 // Set up serial communication to print.
41 // A port must be open to continue and view incoming data.
42 // Set up serial communication to print.
43 SerialPort.Mode(Connector::USB_CDC);
44 SerialPort.Speed(serialBaudRate);
45 SerialPort.PortOpen();
46 while (!SerialPort) {
47 continue;
48 }
49
50 //Uncomment the line below if you have turned RTS flow control on in the XBee's parameters
51 //XBee.FlowControl(true);
52
53 // Set the XBee communication speed and open the XBee port
54 XBee.Speed(115200);
55 XBee.PortOpen();
56
57 // Send a message to the XBee.
58 XBee.Send("Hello XBee");
59
60 while (true) {
61 // As long as there are characters to be read-in, print the character at the
62 // top of the receive buffer.
63 if (XBee.AvailableForRead()) {
64 SerialPort.SendLine(XBee.CharGet());
65 }
66 }
67}
bool Send(const char *buffer, size_t bufferSize)
Send the array of characters out the port.
Definition ISerial.h:173
int16_t CharGet() override
Attempt to read the next character from serial channel.
virtual void PortOpen() override
int32_t AvailableForRead() override
virtual bool Speed(uint32_t bitsPerSecond) override
Change the baud rate for the port.