| 99 | } |
| 100 | |
| 101 | void Can232::loopFunc() { |
| 102 | if (stringComplete) { |
| 103 | unsigned len = inputString.length(); |
| 104 | if (len > 0 && len < LW232_FRAME_MAX_SIZE) { |
| 105 | // maybe not single commands |
| 106 | int cr_pos; |
| 107 | for (; (cr_pos = inputString.indexOf(LW232_CR)) >= 0;) { |
| 108 | strncpy((char*)lw232Message, inputString.c_str(), cr_pos + 1); |
| 109 | lw232Message[cr_pos] = '\0'; |
| 110 | exec(); |
| 111 | inputString = inputString.substring(cr_pos + 1); |
| 112 | } |
| 113 | } |
| 114 | // clear the string: |
| 115 | stringComplete = false; |
| 116 | } |
| 117 | if (lw232CanChannelMode != LW232_STATUS_CAN_CLOSED) { |
| 118 | int recv = 0; |
| 119 | while (CAN_MSGAVAIL == checkReceive() && recv++<5) { |
| 120 | dbg0('+'); |
| 121 | if (CAN_OK == receiveSingleFrame()) { |
| 122 | Serial.write(LW232_CR); |
| 123 | } |
| 124 | } |
| 125 | Serial.flush(); |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | void Can232::serialEventFunc() { |
| 130 | while (Serial.available()) { |