Xiaofei Qiu / Xbee

Xbee.cpp

Committer:
Xiaofei
Date:
2015-11-22
Revision:
6:9f2db7a38f19
Parent:
5:d14636b861ff
Child:
7:922bf2a611b1

File content as of revision 6:9f2db7a38f19:

#pragma once
#include "Xbee.h"

Xbee::Xbee(PinName tx, PinName rx , PinName rst):_xbee(tx,rx),_rst(rst)
{
    _rst = 0;
    wait(0.01);
    _rst = 1;
    wait(0.01);
    
    _xbee.baud(9600);
}


void Xbee::Send(const char* buffer)
{
    while(!_xbee.readable())
    {
        _xbee.puts(buffer);
        wait(0.05);
    }
}

void Xbee::Recv(char* buffer, const size_t& sz)
{
    while(_xbee.readable())
    {
        _xbee.gets(buffer,sz);
        _xbee.putc('.');
    }
    
}