Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: serial.cpp
- Revision:
- 2:4fb5a8d15f9c
- Child:
- 3:655f4fed48d7
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/serial.cpp Fri Dec 02 19:15:25 2016 +0000
@@ -0,0 +1,78 @@
+#include "mbed.h"
+#include "rtos.h"
+#include <string>
+#include <sstream>
+
+DigitalOut led1(LED1);
+DigitalOut led2(LED2);
+Serial pc(USBTX, USBRX);
+Thread *RX_THREAD_POINTER;
+string test;
+string* paramArray = new string[25];
+int index=0;
+
+// Rx Interupt routine
+void Rx_interrupt(void){
+ pc.attach(NULL); // Disable Rx interrupt
+ (*RX_THREAD_POINTER).signal_set(0x1); // dereference of RX_THREAD_POINTER
+}
+
+
+// Read received chars from UART
+void rx_thread(void const *argument){
+ while (true) {
+ // Signal flags that are reported as event are automatically cleared.
+ Thread::signal_wait(0x1);
+ while (pc.readable()) {
+ //pc.putc(pc.getc()); // read data from UART
+ //pc.printf("\r\nInput: \r\n");
+
+ stringstream ss;
+ char temp;
+ temp = pc.getc();
+ //pc.putc(temp);
+ while (temp != '*'){
+ ss << temp;
+ temp = pc.getc();
+ //pc.putc(temp);
+ }
+ ss >> test;
+ if(index<24){
+ //in_Array[i] = temp;
+ //pc.printf("%s\r\n", test);
+ //pc.printf("\r\n");
+ led2=!led2;
+ paramArray[index++] = test;
+ } else {
+ //i = 0;
+ pc.attach(&Rx_interrupt);
+ //return;
+ }
+ }
+ pc.attach(&Rx_interrupt); // Enable Rx interrupt
+ }
+}
+
+
+string* recieve(){
+ paramArray = new string[24];
+ index=0;
+ Thread t_rx(rx_thread);
+ RX_THREAD_POINTER = &t_rx; // Set thread pointer as globally-accessible
+ t_rx.set_priority(osPriorityHigh);
+ pc.attach(Rx_interrupt);
+ //pc.printf("\r\nStart\r\n");
+ while(test != "DONE"){
+ led1=!led1;
+ //pc.printf("%s\r\n",test);
+ Thread::wait(1000);
+ }
+
+ return paramArray;
+}
+
+void send(string input){
+ while(pc.writeable()){
+ pc.printf("%s\r\n", input);
+ }
+}
\ No newline at end of file