##// 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 usleep(1000);
111 usleep(1000);
112 #endif
112 #endif
113 timeout.restart();
113 timeout.restart();
114 while(read!=4)
114 int avail = 0;
115 do
115 {
116 {
116 read += rs232read(this->port,test2,4-read);
117 avail = rs232availablebytes(this->port);
117 if(timeout.elapsed()>1000) break;
118 if(timeout.elapsed()>1000)
118 }
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 if(read>0)
127 if(read>0)
120 {
128 {
121 SocExplorerEngine::message(this,"Connection Ok",2);
129 SocExplorerEngine::message(this,"Connection Ok",2);
@@ -126,7 +134,6 bool ahbuartplugin::checkConnection()
126 SocExplorerEngine::message(this,"Connection Error",2);
134 SocExplorerEngine::message(this,"Connection Error",2);
127 return false;
135 return false;
128 }
136 }
129
130 }
137 }
131
138
132 void ahbuartplugin::connectPort(QString PortName, int baudrate)
139 void ahbuartplugin::connectPort(QString PortName, int baudrate)
@@ -256,10 +263,20 unsigned int ahbuartplugin::Read(unsigne
256 CMD[3] = (char)((address>>8)&0xFF);
263 CMD[3] = (char)((address>>8)&0xFF);
257 CMD[4] = (char)((address)&0xFF);
264 CMD[4] = (char)((address)&0xFF);
258 SAFEWRITE(CMD,5,timeout,1000,return 0);
265 SAFEWRITE(CMD,5,timeout,1000,return 0);
259 #ifdef WIN32
266 timeout.restart();
260 usleep(1000);
267 int avail=0;
261 #endif
268 do{
262 SAFEREAD(result+((cnt-count)*4),32*4,timeout,1000,return 0);
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 count-=32;
280 count-=32;
264 address+=32*4;
281 address+=32*4;
265 if(cnt>128)
282 if(cnt>128)
@@ -281,10 +298,20 unsigned int ahbuartplugin::Read(unsigne
281 CMD[3] = (char)((address>>8)&0xFF);
298 CMD[3] = (char)((address>>8)&0xFF);
282 CMD[4] = (char)((address)&0xFF);
299 CMD[4] = (char)((address)&0xFF);
283 SAFEWRITE(CMD,5,timeout,1000,return 0);
300 SAFEWRITE(CMD,5,timeout,1000,return 0);
284 #ifdef WIN32
301 timeout.restart();
285 usleep(1000);
302 int avail=0;
286 #endif
303 do{
287 SAFEREAD(result+((cnt-count)*4),(count*4),timeout,1000,return 0);
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 if(cnt>128)
316 if(cnt>128)
290 {
317 {
@@ -32,42 +32,29
32 #include <socexplorerplugin.h>
32 #include <socexplorerplugin.h>
33 #include "ahbuartpluginui.h"
33 #include "ahbuartpluginui.h"
34 #include <RS232.h>
34 #include <RS232.h>
35 #include <unistd.h>
35
36
36
37
37 #define SAFEWRITE(data,count,timer,timeout,error) \
38 #define SAFEWRITE(data,count,timer,timeout,error) \
38 while(1)\
39 while(1)\
39 {\
40 {\
40 unsigned int __writen__=0; \
41 unsigned int __writen__=0; \
41 (timer).restart(); \
42 (timer).restart(); \
42 while(__writen__!=(count)) \
43 while(__writen__!=(count)) \
43 {\
44 {\
44 __writen__ += rs232write(this->port,((data)+__writen__),((count)-__writen__)); \
45 __writen__ += rs232write(this->port,((data)+__writen__),((count)-__writen__)); \
45 if((timer).elapsed()>(timeout)) \
46 if((timer).elapsed()>(timeout)) \
46 {\
47 {\
47 this->port = (rs232port_t)NULL; \
48 this->port = (rs232port_t)NULL; \
48 this->Connected = false; \
49 this->Connected = false; \
49 emit this->activateSig(false); \
50 emit this->activateSig(false); \
50 error; \
51 error; \
51 } \
52 } \
52 } \
53 } \
53 break;\
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