LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

What is the reason for hing using on CPU and the low sample speed?

I have a sample program to realize this task: do the data acquisition from 2 rs232 interfaces(both of the two interfaces is created by MOXA Nport5610-8  www.moxa.com/usa). Every RS232 is connected with a instrumnet . Every instrumnet has 3 sensors. The data  acquisition needs to be done once in 1 second.
The communication between PC and One sensor have 4 steps:
step1 PC send sentence(consist of 5 letter) to sensor
step2: PC read sentence(consist of 3 letter) from sensor
step3 PC send sentence(consist of 1 letter) to sensor
step4: PC read sentence(consist of 12 letter) from sensor
There are 6 sensor in 2 rs232 interfaces. So there are 12 Rdcom and 12 Wrcom in my code once in 1 second.
After sampling the data, the program will save data to TXT file. After saving the code will compare the sampled data with alarm setpoint.

There have been a program (writen by VB) to realize this data acquisition task once in 1 second.
I am working to realize this task using CVI.
The program produced by CVI have a problem : the usage of the CPU almost reach 60%. And always can not finish the data aquisition once in 1 second.
My PC is configured as this: Pentium 4 2.4,512 rambus memory.
What is the reason for this problem?
Thanks for your reply.
0 Kudos
Message 1 of 5
(4,127 Views)
Hi lct0811, CVI should be able to handle all this communications in the correct time: assuming a speed of 9600 baud, the whole protocol for 12 sensors will take approx. 250 msecs (transmission time only) leaving you enough time to manage the messages and other things; it's strange that you cannot complete the whole process in a second...
You could avoid some windows latency by opening the com port with a negative value for transmission buffer lenght: this will make CVI write directly to the output port instead of passing the messages to the driver and this one writing to the port. This is described in the online help for OpenComConfig.
Also, which timeout have you set for reading on both ports?
 
It's difficult to give you more suggestions on this item with so few data regarding it: if you can post the part of your code that handles serial communications it will be helpful for us to try helping you.


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 2 of 5
(4,120 Views)

code for opening  com port  is as below

status = OpenComConfig (comport1, devicename, 9600, 0, 8, 1, 0, 0);
   //配置失败,显示出错信息
      if(status!=0)
       {
        MessagePopup ("Error", "TPG1串口配置错误Config failed!");
       }
   //openTPG2com:
   
   status = OpenComConfig (comport2, devicename, 9600, 0, 8, 1, 0, 0);
   //配置失败,显示出错信息
       if(status!=0)
        {
         MessagePopup ("Error", "TPG2串口配置错误Config failed!");
        }

0 Kudos
Message 3 of 5
(4,088 Views)

My main code is as below:  I have deleted some code without relation to communication with com port

 

int j;//cycle variable for data string copy
 int i;//cycle variable for sample data from multi-channel
 
 if(strcmp(TimeStr(),"00:00:00")==0)//08:49:44
  {
   CloseFile (filehandle);
   for(i=0;i<10;i++)
    {
     datestr[i]=*(DateStr()+i);
    }
   datestr[10]='.'; datestr[11]='t'; datestr[12]='x'; datestr[13]='t'; datestr[14]='\0';
   filehandle = OpenFile (datestr,VAL_READ_WRITE, VAL_APPEND, VAL_ASCII);
  }
 switch (event)
  {
  case EVENT_TIMER_TICK:
   {
    if(filehandle!=-1)
     {
      WriteFile (filehandle, TimeStr (), 8);
     }

    for(i=0;i<6;i++)
    {
     //step1
step1:   ComWrt ((i/3+2),str1[(i%3)+3], 4);

     //if(status!=4) 
      //{
       //MessagePopup ("Error", "Send data step1 failed!");
      //}

     //step2
step2:    status=ComRd((i/3+2),rdcom, 3);
     rdcom[3]='\0';

     if(status!=3) 
            {
                //if  a error happens during reading  com port,then there will be message popup

                MessagePopup ("Error", "Read data setp_2 failed!");

               }
           //step3
step3:     if((((rdcom[0]-str2[0])||(rdcom[1]-str2[1])||(rdcom[2]-str2[2]))==0))//check the letters ( one by one) in  the return string
      {

             ComWrt ((i/3+2),str3, 1);
       //if(status!=1) 
      //{
       //MessagePopup ("Error", "Send data step3 failed!");

      //}

            }
           else
      {
               MessagePopup ("Error", "Read data setp_2 未返回正常数据!");
               }
     //step4
step4:    status=ComRd((i/3+2),str4,12);
//for quick
     if(status!=12)
      {
                //读取数据失败,显示出错信息并退出
                MessagePopup ("Error", "Step_4 Read data failed!");
                //SetCtrlVal (panelHandle4, PANEL4_LED4_2, 1);
               }
     /*else
            {
             SetCtrlVal (panelHandle4, PANEL4_LED4, 1);
            }*/

0 Kudos
Message 4 of 5
(4,086 Views)

add the below code to the end of last message    

 

 

 //choose the real data,delete the sensor status
     //0,-0.001E+2
     //0,0.001E+2
     switch(str4[0])
      {
       case 48:
        {
        if(str4[2]!='-')
         {
           for(j=0;j<6;j++)
            {
             str5[j]=str4[j+2];//基数部完成1.234  str5[0~4]
            }
           if(str4[8]=='+')//str4   0,1.234E+5   str5=1.234E+4
            {
             str5[7]=str4[9]+2;//data of TPG is mbar,to be Pascal we have to multiplate 100
             str5[6]=43;
            }
           else//以下都为负指数bar
            {
             if(str4[9]>'2')//如果为-2次bar以下
              {
               str5[6]='-';
               str5[7]=str4[9]-2;
              }
             else//-2 and -1
              {
               if(str4[9]=='1')
                {
                 str5[6]='+';
                 str5[7]='1';
                }
               else
                {
                 str5[6]='+';
                 str5[7]='0';
                }
              }
            }
           str5[8]='\0';
          }
        else 
         {
          ComRd((i/3+2),str0,1);
          for(j=0;j<8;j++)
           {
           str5[j]=str4[j+3];
           }
         str5[8]='\0';
         }
        break;
        }
       case 49:
        {
         strcpy(str5,"UnderRan");
         break;
        }
       case 50:
        {
         strcpy(str5,"OverRang");
         break;
        }
       case 53:
        {
         strcpy(str5,"NoSensor");
         break;
        }
      }
     //display data in the table control      SetTableCellVal (panelHandle, PANEL_TABLE, MakePoint(1,i+1), str5);
     //output the data sampled from com port
     str6[3]=(i%3)+49;//00i的i
     
     if(filehandle!=-1)
      {
      WriteFile (filehandle,str6,5);
      WriteFile (filehandle,strcat(str5,","),9);
      }
    //do the alarm check

     if((str4[0]==48)&&(strtonum(str5)>uplim[i])&&(limflag[i]))
      {
      if(alarmsoundenable)
       {
        LaunchExecutable ("d:\\Program Files\\TTPlayer\\TTPlayer.exe");
       }
      SetTableCellAttribute (panel, PANEL_TABLE, MakePoint(1,i+1), ATTR_TEXT_BGCOLOR, VAL_RED);
      SetTableCellAttribute (panel, PANEL_TABLE, MakePoint(3,i+1), ATTR_TEXT_BGCOLOR, VAL_RED);
      }
     
     Delay (0.01);

ProcessSystemEvents ();

0 Kudos
Message 5 of 5
(4,085 Views)