@@ -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 | |
|
116 | { | |
|
117 | avail = rs232availablebytes(this->port); | |
|
118 | if(timeout.elapsed()>1000) | |
|
115 | 119 | { |
|
116 | read += rs232read(this->port,test2,4-read); | |
|
117 | if(timeout.elapsed()>1000) break; | |
|
120 | if(avail) | |
|
121 | rs232read(this->port,test2,avail); | |
|
122 | SocExplorerEngine::message(this,"Connection Error",2); | |
|
123 | return false; | |
|
118 | 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 |
|
|
|
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 |
|
|
|
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,6 +32,7 | |||
|
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) \ |
@@ -54,20 +55,6 while(1)\ | |||
|
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