LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Error on seriel-read-prozes

Hello,
 
i have a problem by use the seriel ports.
Then i have a read-error the program stopt after the timeout and a popupmesage come.
I need a methode for identify an error and i can respond.
Can me help somewhere.
 
Thanks
0 Kudos
Message 1 of 5
(3,469 Views)

Hello wolf,

you should use the SetBreakOnLibraryErrors function to make sure that LabWindows doesn't interrupt your program when a timeout occurs:

// Get all available bytes from the serial port.  
SetBreakOnLibraryErrors (0);
buffer_size = GetInQLen (port_nr);     // Get the number of bytes in the serial input buffer.
num_bytes = ComRd (port_nr, buffer, buffer_size); // Read the bytes from the buffer.
SetBreakOnLibraryErrors (1);

// Check if an error occurred.
if (num_bytes < 0)
 MessagePopup ("Error", GetRS232ErrorString (num_bytes));

0 Kudos
Message 2 of 5
(3,464 Views)
Hello
 
thanks for the info.
I use im the moment the function out of the asistant für make I/O-instruments.
Is it the same problem?
Here is my code.
 
ViStatus RunRead_VD(ViString *token, ViReal64 *token2, char *Schnitt)     //Ergebnis übertragen
{
 ViStatus ViErr = 0;
    ViSession resourceName = 0;
    ViString output = 0;
    ViReal64 output1 = 0;
 // Open a session to the resource manager
 ViErrChk(viOpenDefaultRM(&sRMSession));
 // Open a session to the instrument
 ViErrChk(viOpen(sRMSession, Schnitt, 4, VI_NULL, &resourceName));
 // Set the timeout
 ViErrChk(viSetAttribute (resourceName, VI_ATTR_TMO_VALUE, 3000));
 // Set the termination character attributes
 ViErrChk(SetTermCharAttributes(resourceName, 10));
 // Send the command to the instrument
 ViErrChk(viPrintf(resourceName, "%s\n", "VAL?"));
 // Parse a delimited string
 ViNullChk(output = (ViString)calloc(MAX_ARRAY_SIZE, 1));
 ViErrChk(viScanf(resourceName, "%255[^,; \r\n\t]%*[,; \r\n\t]", output));
 // Parse a delimited number
 ViErrChk(viScanf(resourceName, "%lf%*[,; \r\n\t]", &output1));
 // Clear the buffer
 ViErrChk(viFlush(resourceName, VI_READ_BUF_DISCARD));
    *token = output;
    *token2 = output1;
Error:
    CloseInstrSession(resourceName);
    if (ViErr < 0) {
     free(output);
    }
 return ViErr;
}
 
Thanks
 
 
0 Kudos
Message 3 of 5
(3,455 Views)
Hello
 
no i test with the commando in the upper code.
I the moment i have a problem with "viOpenDefaultRM"
I need it for become a handle for the instrument.
But i become zero return in the handle-variable.
That is the cause in my problem?
 
Thanks
 
 
 
 
 
 
 
0 Kudos
Message 4 of 5
(3,441 Views)
Hi Wolf,

To locate your error, the best way is to try to use this function "viOpenDefaultRM" alone (for exemple in CVI) and see the response of this function.
If an error occured you can easily locate the problem.
An other solution is to run NI Spy programm and check the message sent and received and also the returned error.

Let me know if you find something helpful.

Regards.

Matthieu Papaux
AE, National Instruments
0 Kudos
Message 5 of 5
(3,403 Views)