Paul van der Wielen
/
MT382_serial
Reading Utility metering data using MBED
Diff: main.cpp
- Revision:
- 0:bacf1c9b9afc
- Child:
- 2:b386810af678
diff -r 000000000000 -r bacf1c9b9afc main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Sep 24 12:33:58 2012 +0000 @@ -0,0 +1,66 @@ +#if 1 +/* + * Copyright (c) 2012 Paul van der Wielen, Pro-Serv + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to use + * and implement the software for none commercial reason and usage only and + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#include "mbed.h" +#include <stdlib.h> +#include <string> + +#include "mt382.h" + +MT382 mt382 ( p21, p28, p27); + +Serial pc(USBTX, USBRX); +DigitalOut myled(LED1); + +Ticker tx; + +void mt_ticker() { + if (mt382.getReading() != 0) { + printf("\nNo data found or time-out!\n"); + } else { + printf("Val_0 %.3lf, Val_1 %.3lf, Val_2 %.3lf, Val_3 %.3lf, Val_4 %.3lf, Val_5 %.3lf, Val_6 %.3lf\n", mt382.getValue(0), mt382.getValue(1), mt382.getValue(2), mt382.getValue(3), mt382.getValue(4), mt382.getValue(5), mt382.getValue(6)); + } +} + +int main() { + + pc.baud(460800); + // init device driver + mt382.setComm(9600, 7, 2, 1); + mt382.setTime(5.0); + mt382.setMatch("1.8.1","1.8.2","2.8.1","2.8.2","1.7.0","2.7.0","24.2.1"); + // get first pass of MT382 'Smart Meter' data + if (mt382.getReading() != 0) { + printf("\nNo data found or time-out!\n"); + } else { + printf("\nDone, char cnt %d !!\n", mt382.getCount()); + printf("Val_0 %.3lf, Val_1 %.3lf, Val_2 %.3lf, Val_3 %.3lf, Val_4 %.3lf, Val_5 %.3lf, Val_6 %.3lf\n", mt382.getValue(0), mt382.getValue(1), mt382.getValue(2), mt382.getValue(3), mt382.getValue(4), mt382.getValue(5), mt382.getValue(6)); + printf("Raw data was: \n%s\n\n", mt382.getRaw()); + } + // now setup collection interval + tx.attach(&mt_ticker, 10.0); + while(1) { + myled = 1; + wait(0.2); + myled = 0; + wait(0.2); + } +} +#endif \ No newline at end of file