##// END OF EJS Templates
Improved AHB UART Plugin, now check how many bytes are available on uart...
jeandet -
r33:de3df68ac881 default
parent child
Show More
@@ -111,11 +111,19 bool ahbuartplugin::checkConnection()
111 111 usleep(1000);
112 112 #endif
113 113 timeout.restart();
114 while(read!=4)
114 int avail = 0;
115 do
115 116 {
116 read += rs232read(this->port,test2,4-read);
117 if(timeout.elapsed()>1000) break;
118 }
117 avail = rs232availablebytes(this->port);
118 if(timeout.elapsed()>1000)
119 {
120 if(avail)
121 rs232read(this->port,test2,avail);
122 SocExplorerEngine::message(this,"Connection Error",2);
123 return false;
124 }
125 }while(avail<4);
126 read = rs232read(this->port,test2,avail);
119 127 if(read>0)
120 128 {
121 129 SocExplorerEngine::message(this,"Connection Ok",2);
@@ -126,7 +134,6 bool ahbuartplugin::checkConnection()
126 134 SocExplorerEngine::message(this,"Connection Error",2);
127 135 return false;
128 136 }
129
130 137 }
131 138
132 139 void ahbuartplugin::connectPort(QString PortName, int baudrate)
@@ -256,10 +263,20 unsigned int ahbuartplugin::Read(unsigne
256 263 CMD[3] = (char)((address>>8)&0xFF);
257 264 CMD[4] = (char)((address)&0xFF);
258 265 SAFEWRITE(CMD,5,timeout,1000,return 0);
259 #ifdef WIN32
260 usleep(1000);
261 #endif
262 SAFEREAD(result+((cnt-count)*4),32*4,timeout,1000,return 0);
266 timeout.restart();
267 int avail=0;
268 do{
269 avail=rs232availablebytes(this->port);
270 if(timeout.elapsed()>1000)
271 {
272 rs232close(this->port);
273 this->port = (rs232port_t)NULL;
274 this->Connected = false;
275 emit this->activateSig(false);
276 return 0;
277 }
278 }while(avail<(32*4));
279 rs232read(this->port,result+((cnt-count)*4),32*4);
263 280 count-=32;
264 281 address+=32*4;
265 282 if(cnt>128)
@@ -281,10 +298,20 unsigned int ahbuartplugin::Read(unsigne
281 298 CMD[3] = (char)((address>>8)&0xFF);
282 299 CMD[4] = (char)((address)&0xFF);
283 300 SAFEWRITE(CMD,5,timeout,1000,return 0);
284 #ifdef WIN32
285 usleep(1000);
286 #endif
287 SAFEREAD(result+((cnt-count)*4),(count*4),timeout,1000,return 0);
301 timeout.restart();
302 int avail=0;
303 do{
304 avail=rs232availablebytes(this->port);
305 if(timeout.elapsed()>1000)
306 {
307 rs232close(this->port);
308 this->port = (rs232port_t)NULL;
309 this->Connected = false;
310 emit this->activateSig(false);
311 return 0;
312 }
313 }while(avail<(count*4));
314 rs232read(this->port,result+((cnt-count)*4),count*4);
288 315 }
289 316 if(cnt>128)
290 317 {
@@ -32,42 +32,29
32 32 #include <socexplorerplugin.h>
33 33 #include "ahbuartpluginui.h"
34 34 #include <RS232.h>
35 #include <unistd.h>
35 36
36 37
37 38 #define SAFEWRITE(data,count,timer,timeout,error) \
38 while(1)\
39 while(1)\
39 40 {\
40 41 unsigned int __writen__=0; \
41 42 (timer).restart(); \
42 43 while(__writen__!=(count)) \
43 {\
44 __writen__ += rs232write(this->port,((data)+__writen__),((count)-__writen__)); \
45 if((timer).elapsed()>(timeout)) \
46 {\
47 this->port = (rs232port_t)NULL; \
48 this->Connected = false; \
49 emit this->activateSig(false); \
50 error; \
51 } \
44 {\
45 __writen__ += rs232write(this->port,((data)+__writen__),((count)-__writen__)); \
46 if((timer).elapsed()>(timeout)) \
47 {\
48 this->port = (rs232port_t)NULL; \
49 this->Connected = false; \
50 emit this->activateSig(false); \
51 error; \
52 } \
52 53 } \
53 54 break;\
54 }
55 }
55 56
56 57
57 #define SAFEREAD(data,count,timer,timeout,error) \
58 unsigned int __read__=0; \
59 (timer).restart(); \
60 while(__read__ != (count)) \
61 { \
62 __read__+=rs232read(this->port,((data)+__read__),((count)-__read__)); \
63 if((timer).elapsed()>(timeout)) \
64 { \
65 this->Connected = false; \
66 emit this->activateSig(false); \
67 this->portMutex->unlock(); \
68 error; \
69 } \
70 } \
71 58
72 59
73 60
General Comments 0
You need to be logged in to leave comments. Login now