cancelar
Mostrando los resultados de 
Buscar en lugar de 
Quiere decir: 

ComRd Funtion dosen't work?

Hi Guys,

I use the function ComRd to read a specified number of bytes, the funtion return bytesread=244 but in my buffer are not 244 bytes?

bytesread=ComRd(1,read_data,244);

In read_data are few than 244? In my input queue are available 4096! Where is the problem?????

Please help me thx




Ing. Mayda Martínez Prince
- Software Entwicklung / Elektronik -
pro-micron GmbH & Co. KG modular systems
Innovapark 20
D-87600 Kaufbeuren

Tel.: +49(0)8341 9164-23
Fax: +49(0)8341 9164-20
mailto: mayda.martinez@pro-micron.de

http://www.pro-micron.de
0 kudos
Mensaje 1 de 9
5.319 Vistas

If you are expecting binary data in your buffer but you are examining it as if it was a string, then a received 0x00 would appear to truncate the buffer at that point. If the function says it is receiving 244 bytes I would tend to believe it.

JR

0 kudos
Mensaje 2 de 9
5.306 Vistas
How are you determining that there are 4096 bytes available?  Did you call GetInQLen, or are you just expecting 4096 bytes to be available?  4096 is the minimum input buffer size allocated on Windows, but it is not necessarily going to be full of new bytes.  Try calling GetInQLen before calling ComRd.  If the functions return different numbers, please reply back with a code sample or more details about your program, as well as the version of the runtime engine (cvirte.dll in the system directory) on the machine that you have problems with.

Thanks.

Mert A.
National Instruments
0 kudos
Mensaje 3 de 9
5.295 Vistas
Hi Mert A, and JR

There is a part from my code

Anzahl=244;

inputBytes = GetInQLen (portlist[iPortIndex]);               

//inputBytes are > 244 for example(512,1024, etc..)
                 
 while (inputBytes < Anzahl)
                    {
                        ProcessSystemEvents ();
                        Delay ((64-inputBytes)*8/(double)38400);
                        inputBytes = GetInQLen (portlist[iPortIndex]);
                    }      
        
                    read_data[0]='\0';
                
                    Delay(1.0);
                    
                    bytesread=ComRd(portlist[iPortIndex],read_data,Anzahl);

in bytesread=244 but in read_data are < 244 Bytes

I don't understand it????
Ing. Mayda Martínez Prince
- Software Entwicklung / Elektronik -
pro-micron GmbH & Co. KG modular systems
Innovapark 20
D-87600 Kaufbeuren

Tel.: +49(0)8341 9164-23
Fax: +49(0)8341 9164-20
mailto: mayda.martinez@pro-micron.de

http://www.pro-micron.de
0 kudos
Mensaje 4 de 9
5.281 Vistas

How are you determining that there are less than 244 bytes in the string? As JR suggested, if you are using strlen () and in the received string there are some NUL bytes strlen will return a value less than 244 (exactly the position of the first NUL byte in the string).

I suggest you place a breakpoint immediately after ComRd and examine your read_data variable enabling Options >> Display entire buffer and Format >> Decimal options in string display window: this way you will see the entire buffer and be able to examine all the received message eventually beyond the NUL bytes received.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 kudos
Mensaje 5 de 9
5.274 Vistas
Hi Robert,

in the .doc you can see my screenshot from my programm.
I did  what you said, but in my buffer are less than 244 bytes??  and bytesread is 244 why?

i rewrote the progamm in Visual Studio Profesional 2005 VB.Net, with it works out very good!!!

Why don't works in  Labwindows/CVI? which is the difference between VB.Net and CVI? where is the error??

Ing. Mayda Martínez Prince
- Software Entwicklung / Elektronik -
pro-micron GmbH & Co. KG modular systems
Innovapark 20
D-87600 Kaufbeuren

Tel.: +49(0)8341 9164-23
Fax: +49(0)8341 9164-20
mailto: mayda.martinez@pro-micron.de

http://www.pro-micron.de
0 kudos
Mensaje 6 de 9
5.267 Vistas

Are you sure you activated Options >> Display entire buffer option? 'cause what I see is that of 25000 bytes read_data is made of only the first 94 are shown (up to first nul byte) and nothing else...

As far as I can see you are reading data in blocks of 16 bytes [ read_data[i-1] + (read_data[i] << 😎 ] so your equipment seems to be sending binary data in which values up to 256 are represented as 0+xxx: that is every very little measure introduces a nul byte in the string. It is still possible that JR hipothesys is true.

Anyway, despite the fact that you have determined that less than 244 bytes are available, have you tried to proceed with your decodification loop (where you put the breakpoint)? Did you get erroneous results or some errors?



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 kudos
Mensaje 7 de 9
5.256 Vistas
From looking at the source code, it is clear what the problem is. You are expecting data in binary format, but you are using an ASCII string function (strlen()) to analyse it. strlen() will terminate when it sees a 0x00 in a string, giving an incorrect indication of the number of bytes. You already have a variable with the actual number of bytes in the string: bytesread. Just use that instead of trying to use strlen().
 
JR
Mensaje 8 de 9
5.250 Vistas
Forgot to add - the same goes for strcat() and strncat() - being string functions they will not work on binary data. Use memcpy() instead.
 
JR
0 kudos
Mensaje 9 de 9
5.244 Vistas