PropWare
C++ objects and CMake build system for Parallax Propeller
Home
Download
Getting Started
Documentation
Reference
About
Related Links
Namespace List
Class List
File List
Examples
Build System
File List
File Members
propsideworkspace
Learn
Examples
Protocols
XBee UART Command Mode Example.c
1
/*
2
XBee UART Loopback.c
3
4
Demonstrates using full duplex serial communication to configure an
5
XBee Series 1 radio.
6
7
http://learn.parallax.com/propeller-c-simple-protocols/full-duplex-serial
8
*/
9
10
#include "simpletools.h"
11
#include "fdserial.h"
12
13
fdserial
*xbee;
14
char
response[10];
15
16
int
xbcmd(
char
*cmd,
char
*reply,
int
bytesMax,
int
msMax);
17
18
int
main
()
19
{
20
xbee = fdserial_open(9, 8, 0, 9600);
21
pause(1000);
22
print(
"cmd = +++\n"
);
23
int
bytes = xbcmd(
"+++"
, response, 10, 2000);
24
if
(bytes == 0)
25
print(
"Timeout error.\n"
);
26
else
27
{
28
print(
"reply = %s"
, response);
29
print(
"cmd = ATBD\n"
);
30
xbcmd(
"ATBD\r"
, response, 10, 20);
31
print(
"reply = %s"
, response);
32
print(
"cmd = ATCN\n"
);
33
xbcmd(
"ATCN\r"
, response, 10, 20);
34
print(
"reply = %s"
, response);
35
}
36
}
37
38
int
xbcmd(
char
*cmd,
char
*reply,
int
bytesMax,
int
msMax)
39
{
40
int
c = -1, n = 0;
41
writeStr(xbee, cmd);
42
memset(reply, 0, bytesMax);
43
44
int
tmax = (CLKFREQ/1000) * msMax;
45
int
tmark = CNT;
46
47
while
(1)
48
{
49
c = fdserial_rxCheck(xbee);
50
if
(c != -1)
51
reply[n++] = c;
52
if
(CNT - tmark > tmax)
53
return
0;
54
if
(c ==
'\r'
)
55
return
n;
56
}
57
}
main
int main(void)
Definition:
GraphicsTest.c:20
text_struct
Structure that contains data used by simple text device libraries.
Definition:
simpletext.h:70
Generated on Sat Aug 27 2016 00:58:03 for PropWare by
1.8.12