3d Printer Hardware emulation, used to test some of my projects that require a real 3d printer response via USB serialport but without having the hardware available (mbed will reply to gcode commands - or any text+ENTER with an 'ok' ack data).

Committer:
botdream
Date:
Tue Nov 06 22:10:21 2012 +0000
Revision:
0:fc0008071704
Demo prototype of MBED 3d printer hardware emulation

Who changed what in which revision?

UserRevisionLine numberNew contents of line
botdream 0:fc0008071704 1 #include "mbed.h"
botdream 0:fc0008071704 2 //---------------------------------------------------------------------------------------------
botdream 0:fc0008071704 3 // USB serial port setup - debug messages
botdream 0:fc0008071704 4 //---------------------------------------------------------------------------------------------
botdream 0:fc0008071704 5 Serial pc(USBTX, USBRX); // tx, rx
botdream 0:fc0008071704 6
botdream 0:fc0008071704 7 //---------------------------------------------------------------------------------------------
botdream 0:fc0008071704 8
botdream 0:fc0008071704 9 DigitalOut myled(LED1);
botdream 0:fc0008071704 10
botdream 0:fc0008071704 11 //---------------------------------------------------------------------------------------------
botdream 0:fc0008071704 12 int main() {
botdream 0:fc0008071704 13
botdream 0:fc0008071704 14 int serialportdata = 0;
botdream 0:fc0008071704 15
botdream 0:fc0008071704 16 myled = 1;
botdream 0:fc0008071704 17 wait(0.5);
botdream 0:fc0008071704 18 myled = 0;
botdream 0:fc0008071704 19
botdream 0:fc0008071704 20 //set communication speed
botdream 0:fc0008071704 21 pc.baud(115200);
botdream 0:fc0008071704 22 //test to see if comm is working
botdream 0:fc0008071704 23 printf("ok\r\nok\r\n");
botdream 0:fc0008071704 24
botdream 0:fc0008071704 25 while(1) {
botdream 0:fc0008071704 26
botdream 0:fc0008071704 27 if(pc.readable()) {
botdream 0:fc0008071704 28 serialportdata = pc.getc();
botdream 0:fc0008071704 29 //printf("-> %c\r\n", serialportdata);
botdream 0:fc0008071704 30 if( serialportdata == '\r' || serialportdata == '\n') {
botdream 0:fc0008071704 31 printf("ok\r\n");
botdream 0:fc0008071704 32
botdream 0:fc0008071704 33 }
botdream 0:fc0008071704 34 }
botdream 0:fc0008071704 35 }
botdream 0:fc0008071704 36 }
botdream 0:fc0008071704 37 //---------------------------------------------------------------------------------------------