Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

viRead blocks forever

Hello!

I'm trying to query a response from a Focus iTuner.

Here is my code (the most important lines anyway):

ViStatus status;
ViSession m_defaultRM;
ViSession m_vi;
int actualLength;

status = viOpenDefaultRM(&m_defaultRM);
status = viOpen(m_defaultRM, resourceBuf,VI_NULL,VI_NULL,&m_vi);
status = viWrite(m_vi, "POS? 1\n", strlen("POS? 1\n"), &actualLength);

CString buffer("");

        try
        {
            int actualcnt = 40;
            while(actualcnt > 0)
            {
                ViChar buff[40];
                ZeroMemory(buff, sizeof(buff));
                viRead(m_vi, (unsigned char *)buff, sizeof(buff). &actualcnt );
                buffer += buff;
            }
        }
        catch(...)
        {
            //When I get a timeout the execution gets here...
        }

The code works fine until there are less than 40 bytes to read from the pipe. The execution of the code stops to the viRead -function and blocks there until the timeout expires and an exception is thrown. The last segment of data is not read from the iTuner.

The basic problem is that I don't know the exact number of bytes to be read from the pipe beforehand, and the viRead function blocks until the timeout if the buffer size is larger than the number of bytes available in the pipe.

I want the code to work in a way that if there are for example 24 bytes of data to be read from the pipe and my buffer size is 40, only 24 bytes are read to the buffer and the viRead function returns immediately without a timeout. Is this possible?
 


0 Kudos
Message 1 of 3
(6,830 Views)
Clarification:

The following line of

status = viOpen(m_defaultRM, resourceBuf,VI_NULL,VI_NULL,&m_vi);

should be

status = viOpen("TCPIP0::X.X.X.X::XX::SOCKET", VI_NULL,VI_NULL,&m_vi);

with the striing of "
X.X.X.X::XX" being an IP address and the port.
0 Kudos
Message 2 of 3
(6,829 Views)
Somebody answer?
0 Kudos
Message 3 of 3
(6,800 Views)