LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How much loading does SetComTime timeout impose on the CPU?

How much loading does "SetComTime(portNum, timeOut);"  place on the PC processor when monitoring the serial port?

Does it take 100% of the CPU resource?

I am using LW-CVI 7.1.0.

Thanks,

JLV

Message 1 of 7
(5,013 Views)
I am not sure how much loading "SetComTime(portNum, timeOut);" puts on the PC processor but LabWindows appears frozen during the timeout period.  I am modifiying an application that has SetComTime set for for two or three minutes and during that time you can't resize or move LabWindows/CVI windows and if you want to stop the program early you have to use the Windows Task Manager.

I modified that program to use time functions for the timeout.  SetComTime is set to 2 seconds or less so LabWindows won't appear to be frozen.

    time_t startTime;
    time_t currentTime;

    SetComTime( comPort, 2); 
   
    startTime = time(&startTime);
    currentTime = time(&currentTime);

    do                                  
    {
        ProcessSystemEvents();  // Use this or program will appear to be frozen
        status = ComRdTerm( comPort,inbuf, 254, 13 );    // read until CR

        // Code here to copy inbuf to another buffer and
       //  search for correct prompt or pass/fail condition.

    } while ( difftime(currentTime, startTime) <= comTimeoutSec);     



John Bessire

Message 2 of 7
(4,964 Views)


@JohnB10000 wrote:
I am not sure how much loading "SetComTime(portNum, timeOut);" puts on the PC processor but LabWindows appears frozen during the timeout period.  I am modifiying an application that has SetComTime set for for two or three minutes and during that time you can't resize or move LabWindows/CVI windows and if you want to stop the program early you have to use the Windows Task Manager.


I observed the exact same thing which is what triggered my question.
 
It may not take 100% of the CPU, but it does slow down every process (to a crawl)  which are running in Windows.
I was not sure if the cause was a relatively "economical" multi-port serial (pci-card).
 
Thanks,
 
JLV
Message 3 of 7
(4,949 Views)
I gave the VISA serial driver a try and it wasn't much better.  The COM port was set with long timeout and a terminating character that would never be reached.  During this time I was able to move windows slowly.  Quitting the program early still requires using the Windows Task Manager or rebooting the computer.

When using the VISA driver or the LabWindows/CVI com port commands the Windows Task Manager shows "program not responding" during the timeout period.

John Bessire
0 Kudos
Message 4 of 7
(4,933 Views)

Thanks John for the info.

My work around was to create a short timeout, but place the read-serial port within a loop that monitors incoming data from the serial port.  The data is stored into a buffer until the desired "end-of-message" is reached.  It also uses a maximum string length to force an exit to the loop which is basically my version of a timeout process.  If the expected message is not received, then the data is either discarted or saved in a debug file. 

But basically, I keep the actual timeout to a value no higher than 1 sec.

JLV

Message 5 of 7
(4,922 Views)
Setting the SetComTime (COMPort, 0) to zero then polling the serial port reduced the amount of load put on the CPU.  The code shown below is what I am now using.  The function writes to a console window and to a file while it is polling the com port without losing characters.

On a 350 Mhz Pentium II other LabWindows\CVI windows and other programs can be used while the program is running.  One of our products takes to three minutes to bootup and sends status messages.  When no characters were being received the CPU usage was just a few percent.  When a large number of characters arrived at once the CPU time shot up to 25 percent but I was still able to move and resize other windows without problems.

This function also searches for word or phrase instead of the single termination character used in ComRdTerm.

time_t startTime;
time_t currentTime;
  
startTime = time(&startTime);
currentTime = time(&currentTime);

SetComTime (COMPort, 0);  //  Set time to zero or CPU will load down

FlushInQ (COMPort);
FlushOutQ (COMPort);

status = ComWrt (COMPort, command, strlen(command));  
do                                  
{
    ProcessSystemEvents();  // Use this or program will appear to be frozen

    inputBytes = GetInQLen (COMPort);
    if (inoutBytes > 0)
    {
        status = ComRd (COMPort, inBuffer, inputBytes);

        // Code here to copy inbuf to another buffer, writes to console
       // write to a file and  search for correct prompt or pass/fail condition.


        currentTime = time(&currentTime);

        // Search for termination string
        if (strstr(Buffer, endOfString) timeout = -1;

    } while ( difftime(currentTime, startTime) <= comTimeoutSec);




John Bessire



Message 6 of 7
(4,903 Views)

Hi John,

Interesting... makes sense.. nice approach..

I didn't think of setting the SetComTime to zero.  I did something similar to this in LV..   Which is why I think it makes sense.

I will give it a try..  I can see the perfomance improvement, especially if this is inside other loops.

🙂

JLV

 

Message 7 of 7
(4,876 Views)