![](/media/cache/group/HIMBED0.jpg.50x50_q85.jpg)
Ich habe bei der EventKlasse das EOT auf " " geändert, damit das Beenden der Kommunikation mit dem "." funktioniert. Im großen und ganzem müsste es funktionieren.
Dependencies: mbed
SerialEvent.h@0:a321a9d74411, 2016-06-23 (annotated)
- Committer:
- KagerJ
- Date:
- Thu Jun 23 07:35:38 2016 +0000
- Revision:
- 0:a321a9d74411
Dieses Programm m?sste im gro?en und ganzem funktionieren.; Wichtig: Das EOT der EventKlasse habe ich den "." mit einem " " ersetzt, damit es funktioniert.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
KagerJ | 0:a321a9d74411 | 1 | #include "mbed.h" |
KagerJ | 0:a321a9d74411 | 2 | #ifndef SERIALEVENT_H |
KagerJ | 0:a321a9d74411 | 3 | #define SERIALEVENT_H |
KagerJ | 0:a321a9d74411 | 4 | |
KagerJ | 0:a321a9d74411 | 5 | const uint8_t STRMAX = 20; |
KagerJ | 0:a321a9d74411 | 6 | const char EOT = ' '; |
KagerJ | 0:a321a9d74411 | 7 | const char CRLF = '\n'; |
KagerJ | 0:a321a9d74411 | 8 | // ---------------- Serial RS232 Event Class -------------------------- |
KagerJ | 0:a321a9d74411 | 9 | class SerialEvent { |
KagerJ | 0:a321a9d74411 | 10 | Serial _pc; |
KagerJ | 0:a321a9d74411 | 11 | void _risingISR(); |
KagerJ | 0:a321a9d74411 | 12 | char _str[STRMAX]; |
KagerJ | 0:a321a9d74411 | 13 | volatile bool _strOkFlag; |
KagerJ | 0:a321a9d74411 | 14 | int _index; |
KagerJ | 0:a321a9d74411 | 15 | |
KagerJ | 0:a321a9d74411 | 16 | |
KagerJ | 0:a321a9d74411 | 17 | public: |
KagerJ | 0:a321a9d74411 | 18 | SerialEvent(PinName tx, PinName rx) : _pc(tx, rx) { // create the Serial on the pin specified to SwEvent |
KagerJ | 0:a321a9d74411 | 19 | _pc.attach(this, &SerialEvent::pc_recv); // attach DataReceive-function of this SerialEvent instance |
KagerJ | 0:a321a9d74411 | 20 | _strOkFlag = false; |
KagerJ | 0:a321a9d74411 | 21 | _index=0; |
KagerJ | 0:a321a9d74411 | 22 | |
KagerJ | 0:a321a9d74411 | 23 | } |
KagerJ | 0:a321a9d74411 | 24 | void pc_recv(); |
KagerJ | 0:a321a9d74411 | 25 | void getString(char st[]); |
KagerJ | 0:a321a9d74411 | 26 | int checkFlag(); // must in do-condition (while(true)-loop) continuously interrogated |
KagerJ | 0:a321a9d74411 | 27 | }; |
KagerJ | 0:a321a9d74411 | 28 | // ---------------- Serial Event Class Methodes -------------------------- |
KagerJ | 0:a321a9d74411 | 29 | void SerialEvent::getString(char st[]) { |
KagerJ | 0:a321a9d74411 | 30 | for( int i=0; i <= _index; i++) |
KagerJ | 0:a321a9d74411 | 31 | st[i] = _str[i]; |
KagerJ | 0:a321a9d74411 | 32 | _index=0; |
KagerJ | 0:a321a9d74411 | 33 | } |
KagerJ | 0:a321a9d74411 | 34 | |
KagerJ | 0:a321a9d74411 | 35 | void SerialEvent::pc_recv() { |
KagerJ | 0:a321a9d74411 | 36 | char c; |
KagerJ | 0:a321a9d74411 | 37 | while(_pc.readable()){ |
KagerJ | 0:a321a9d74411 | 38 | c = _pc.getc(); |
KagerJ | 0:a321a9d74411 | 39 | if((c != CRLF) && (_index < STRMAX)) { |
KagerJ | 0:a321a9d74411 | 40 | _str[_index++] = c; |
KagerJ | 0:a321a9d74411 | 41 | } |
KagerJ | 0:a321a9d74411 | 42 | } |
KagerJ | 0:a321a9d74411 | 43 | if(( c == EOT)) { // end: . string not empty |
KagerJ | 0:a321a9d74411 | 44 | if(_index >= 1) { |
KagerJ | 0:a321a9d74411 | 45 | _strOkFlag = true; |
KagerJ | 0:a321a9d74411 | 46 | _str[--_index] = 0; |
KagerJ | 0:a321a9d74411 | 47 | } |
KagerJ | 0:a321a9d74411 | 48 | } |
KagerJ | 0:a321a9d74411 | 49 | } |
KagerJ | 0:a321a9d74411 | 50 | |
KagerJ | 0:a321a9d74411 | 51 | int SerialEvent::checkFlag() { |
KagerJ | 0:a321a9d74411 | 52 | if( _strOkFlag ) { |
KagerJ | 0:a321a9d74411 | 53 | _strOkFlag = false; |
KagerJ | 0:a321a9d74411 | 54 | return 1; |
KagerJ | 0:a321a9d74411 | 55 | } |
KagerJ | 0:a321a9d74411 | 56 | return 0; |
KagerJ | 0:a321a9d74411 | 57 | } |
KagerJ | 0:a321a9d74411 | 58 | #endif |