LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

ComFromFile() failed with CVI 8.1

I use the function ComFromFile(PortNumber, FileHandle, Count, TerminationByte) to send a binary file to a device via the serial com port. To send the whole file until EOF encountered, I set the argument 'Count' to 0 and the argument 'TerminationByte' to -1. Compiled with CVI 8.0.1 this works properly.
But when I compile this with CVI 8.1 the function failed. The returned value 'BytesWritten' of this function is set to 0. Also the global variable 'rs232err' is set to 0. But the file is not send.

The function only works, if I set the argument 'Count' to the size of the file, which I get from a call to GetFileInfo(). This works properly for binary files. For ASCII files the filesize determined by this function could be bigger than the count of bytes loaded from the file and send via com port, because of the CR/LF translation. But it should work too.

Fortunately I have found a solution for this problem myself. But I want to know, if this is a bug, or if it was wrong usage of the function by me.

Best regards,

Martin Schmidt
0 Kudos
Message 1 of 8
(4,899 Views)
Martin,

I've confirmed this change in behavior between 8.0.1 and 8.1.  It is indeed a bug, since the documentation clearly states that 0 may be passed to send until EOF, the termination byte, or an error.  In version 8.1, the behavior was incorrectly modified to interpret the 0 count literally as a request to send 0 bytes.

This will be fixed for the next release.  Until then, you can pass 0x8FFF (max int) instead of 0 to achieve the same effect.  This applies whether you want to write the whole file or just up to a termination character.  As long as you pass a count at least as large as the number of bytes that actually need to be written, it should work.

Thanks for pointing this out, and I appologize for the inconvenience.

Mert A.
National Instruments

Message Edited by Mert A. on 12-18-2006 11:14 AM

0 Kudos
Message 2 of 8
(4,886 Views)
I've just downloaded and installed CVI 8.1.1 and this problem is still there. Grrrr....Smiley Sad
0 Kudos
Message 3 of 8
(4,751 Views)
JDG,

Sorry for the long delay in this response.  I have just tested this out, and I've confirmed that the problem was fixed in the CVI 8.1.1 Run-Time Engine.  It does not matter which version of CVI compiles the code, but the behavior will depend on the version of the CVI Run-Time Engine that is installed on the machine you're running your program on.  You should confirm that the version of cvirte.dll in the system directory is 8.1.1.x.

The expected, corrected behavior is that passing a count value of 0 to ComFromFile causes it to read and send the entire file.  If you are seeing a different behavior, please let me know, and I'll be happy to help you figure out what is wrong.

Mert A.
National Instruments
0 Kudos
Message 4 of 8
(4,701 Views)
Thanks Mert for your reply.

1) I try check the version of cvirte.dll but never find any values - so I download and install the latest version from ni web (NILWCVIRTE811.exe) (btw - how to localize and find version informations ?).
2) There are no change in wrong behaviour (see code segment below):

            FlushOutQ (Port);
            if ((hndFLoad = OpenFile (Project.symtable.loadfile, VAL_READ_ONLY, VAL_OPEN_AS_IS, VAL_BINARY)) < 0) {
                MessagePopup ("Error opening file", GetFmtIOErrorString (GetFmtIOError()));
            }
            else if (GetFileInfo (Project.symtable.loadfile, &length) == 1) {
                pLoad = malloc (length * sizeof(char));
                ReadFile (hndFLoad, pLoad, length);

//              count = ComWrt (Port, pLoad, length);                                // Using the ComWrt function and length - works

                count = ComFromFile (Port, hndFLoad, length, -1);            // Using the ComFromFile function - doesn't work, return count = 0

//              count = ComFromFile (Port, hndFLoad, 0, -1);                    // Using the ComFromFile function - doesn't work, return count = 0

                free (pLoad);
            }

3) Any suggestions?

Thanx,
Jiri
0 Kudos
Message 5 of 8
(4,672 Views)
Hello Jiri,

did you try to comment out the ReadFile() function call?
I'm not sure, but could it be that after reading the file the file-pointer points to the end of the file? And when calling ComFromFile() this function starts at these position. But there is nothing left to send, because the file-pointer already points to EOF.
I didn't try it, it's just an assumption...

Best regards,

Martin
0 Kudos
Message 6 of 8
(4,667 Views)
Hello, Martin!

Yes, you are right ! ... So the problem is between chair and keyboard again ... ;-(

Thanks!

Jiri
0 Kudos
Message 7 of 8
(4,664 Views)


@jdg wrote:
(btw - how to localize and find version informations ?).

Thanx,
Jiri



Use GetCVIVersion () function to get the version of the Run-Time Engine running on the system


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
Message 8 of 8
(4,657 Views)