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).
main.cpp
00001 #include "mbed.h" 00002 //--------------------------------------------------------------------------------------------- 00003 // USB serial port setup - debug messages 00004 //--------------------------------------------------------------------------------------------- 00005 Serial pc(USBTX, USBRX); // tx, rx 00006 00007 //--------------------------------------------------------------------------------------------- 00008 00009 DigitalOut myled(LED1); 00010 00011 //--------------------------------------------------------------------------------------------- 00012 int main() { 00013 00014 int serialportdata = 0; 00015 00016 myled = 1; 00017 wait(0.5); 00018 myled = 0; 00019 00020 //set communication speed 00021 pc.baud(115200); 00022 //test to see if comm is working 00023 printf("ok\r\nok\r\n"); 00024 00025 while(1) { 00026 00027 if(pc.readable()) { 00028 serialportdata = pc.getc(); 00029 //printf("-> %c\r\n", serialportdata); 00030 if( serialportdata == '\r' || serialportdata == '\n') { 00031 printf("ok\r\n"); 00032 00033 } 00034 } 00035 } 00036 } 00037 //---------------------------------------------------------------------------------------------
Generated on Sun Jul 24 2022 07:04:23 by 1.7.2