Changeset 122 in pacpusframework for branches/2.0-beta1/src/PacpusTools
- Timestamp:
- Jul 22, 2013, 11:45:45 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.0-beta1/src/PacpusTools/src/PacpusSerialPort.cpp
r121 r122 40 40 41 41 dataMode = ASCII; 42 sepChar = "\n"; 43 44 startChar = " $";42 sepChar = "\n"; // TODO remove 43 44 startChar = ""; 45 45 stopChar = "\n"; 46 minPacketSize=0; 47 48 log = false; // TODO remove when component ok 46 49 47 50 // Or threaded … … 109 112 if(param.hasProperty("stopChar")) 110 113 stopChar = param.getProperty("stopChar"); 114 115 if(param.hasProperty("minPacketSize")) 116 minPacketSize = (DataMode) param.getProperty("minPacketSize").toInt(); 111 117 112 118 serialPort->setPortName(portName); … … 135 141 { 136 142 143 buffer.clear(); 144 137 145 if(!serialPort->open((QSerialPort::OpenModeFlag)direction)) 138 146 { LOG_FATAL("device "<< serialPort->portName().toStdString() <<" failed to open: " << serialPort->errorString()); } … … 182 190 int n; 183 191 184 buffer.append(serialPort->readAll()); 192 if(dataMode == BINARY & minPacketSize >0) 193 if(serialPort->bytesAvailable() < minPacketSize) 194 return; 195 196 buffer += serialPort->readAll(); 185 197 186 198 while(true) // loop until no data to send … … 189 201 { 190 202 case ASCII : // Split the first line to send 191 192 n = buffer.indexOf(sepChar,1) + 1; 193 if(n<=0) 194 return; // end line char not found 203 { 204 if(startChar.size()>0) 205 { 206 int indexStart = buffer.indexOf(startChar,0); 207 if(indexStart < 0) 208 return; 209 else 210 buffer.remove(0,indexStart); 211 } 212 213 int indexStop = buffer.indexOf(stopChar,1); 214 if(indexStop < 1) 215 return; 216 217 n=indexStop; 195 218 break; 196 219 220 // This work but replace by previous code that need to be test 221 // n = buffer.indexOf(sepChar,1) + 1; 222 // if(n<=0) 223 // return; // end line char not found 224 // break; 225 } 197 226 case BINARY : // Get all data 198 199 227 n = buffer.size();//serialPort->bytesAvailable(); 200 228 if(n<=0) … … 218 246 GET_OUTPUT("pinOutSignal",PacpusSerialPort,quint16)->send(pinout); 219 247 setState(MONITOR_OK); 220 LOG_INFO("Signal Read " << n << " bytes, PinOut : " << pinout); 221 LOG_INFO(QString(data).toStdString()); 222 } 223 //LOG_INFO("Buffer " << buffer.data()); 248 LOG_DEBUG("Signal Read " << n << " bytes, PinOut : " << pinout); 249 LOG_DEBUG(data.data()); 250 251 if(log) 252 { 253 switch(dataMode) 254 { 255 case ASCII : 256 LOG_INFO("Buffer " << buffer.data()); 257 258 case BINARY : 259 { 260 QByteArray str; 261 for(int i =0;i<22 ;i++) 262 str+= QByteArray::number((uchar)buffer.data()[i],16).toUpper() + " "; 263 LOG_INFO("Value " << str.data()); 264 } 265 } 266 } 267 } 224 268 } 225 269
Note:
See TracChangeset
for help on using the changeset viewer.