
In the mbed documentation LPC1768 there are many examples of serial communication implemented in a structured and disorganized way. So, I decided to make it very practical and reusable for other users who need to use this feature. For this, I created my own library based on the OO paradigm.
In the mbed documentation LPC1768 there are many examples of serial communication implemented in a structured and disorganized way. So, I decided to make it very practical and reusable for other users who need to use this feature. For this, I created my own library based on the OO paradigm.
Diff: SerialCommunication.cpp
- Revision:
- 0:78c623c147d2
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SerialCommunication.cpp Tue Sep 05 22:36:20 2017 +0000 @@ -0,0 +1,38 @@ +#include "SerialCommunication.h" + +SerialCommunication::SerialCommunication(PinName tx, PinName rx, int baudRate): tx(tx), rx(rx){ + serial = new Serial(tx, rx); // tx, rx + serial->baud(baudRate); + messageLength = 4; // tam palavra + 1 ('\n') + + debug = new DigitalOut(LED1); // debug send info +} + + +int SerialCommunication::ReceiveCommand(){ // RECEIVE INFO + + char commandReceived[messageLength]; + + + if(serial->readable()){ + serial->gets(commandReceived,messageLength); + + if (strcmp(commandReceived, "s0b") == 0){ //s0b : ex de palavra q desejo receber" + return 1; + } + } + return 0; +} + + +void SerialCommunication::SendCommand(string commandSended){ // SEND INFO + + // SEND INFO + //while(1){ + serial->printf("%s",commandSended); + debug->write(1); + wait(DELAY_COMMAND); + debug->write(0); + wait(DELAY_COMMAND); + //} +} \ No newline at end of file