LabWindows/CVI User Group Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

Save datas automaticly in a .txt file Using CVI

Solved!
Go to solution

Hello,everyone!

I'm a newcomer in the LabWindows/CVI group.

I want to save the datas through serial port automaticly in a .txt file Using CVI. Such as these datas in the following QQ

sectional drawing.

This problem has obsessed me some days.

Is there anyone who has a readymade CVI code that saves the datas automaticly in a .txt file Using CVI ?

Thank you very much  for your help !

I wouldn't care success or failure,for I will only struggle ahead as long as I have been destined to the distance.
0 Kudos
Message 1 of 8
(12,884 Views)

Hello!

A couple of questions.

What speed are going to use the serial port?

The information required stored in any specific order?

Previous to evaluate the best data management strategy.

What is a QQ sectional drawing?

0 Kudos
Message 2 of 8
(8,602 Views)

Thank you for Acm's reply!

The speed I am going to use is 9600 bit/s.

Although the information required sored could be in any specific order, I want the order is CO2,O2,Temperature,CO,Humidity,H2S,CH4.

QQ secticonal drawing is a image in my accessory.

Looking forward to your reply!

Thank you very much !

I wouldn't care success or failure,for I will only struggle ahead as long as I have been destined to the distance.
0 Kudos
Message 3 of 8
(8,602 Views)
Solution
Accepted by topic author 佩林

Hello,

I think you can do something like that:

(in bold modification for changing filename every day)

const char* dateString( void )

{

static char s[128];

time_t t1;

struct tm *t2;

t1 = time( &t1);

t2 = localtime(&t1);

sprintf(s,"%02d%03d",t2->tm_year,t2->tm_yday);

return s;

}

FILE* f;

char fname[128];
double co2,o2,temperature,co,humidity,h2s,ch4;

// here under, replace  panelHandle, PANEL_CO2,PANEL_O2,...,PANEL_CH4 by your actual panel name and controls names

GetCtrlVal (panelHandle, PANEL_CO2, &co2);
GetCtrlVal (panelHandle, PANEL_O2, &o2);
GetCtrlVal (panelHandle, PANEL_TEMPERATURE, &temperature);
GetCtrlVal (panelHandle, PANEL_CO, &co);
GetCtrlVal (panelHandle, PANEL_HUMIDITY, &humidity);
GetCtrlVal (panelHandle, PANEL_H2S, &h2s);
GetCtrlVal (panelHandle, PANEL_CH4, &ch4);

sprintf(fname,"c:\\%s.log",dateString());


f = fopen (fname, "a+");
if( f != NULL )
{
  fprintf(f,"%g,%g,%g,%g,%g,%g,%g\n",co2,o2,temperature,co,humidity,h2s,ch4);
  fclose(f);
}

Regards.

B.Williot

0 Kudos
Message 4 of 8
(8,602 Views)

Thanks a lot for your help ! It's very useful for me !

I add the time to it.

fprintf (f, "%s  %s     ",DateStr(),TimeStr());

It's very pretty.

Thank you very much !

I have anther question. Because of large amounts of datas,shall I save all these datas in this one file?

Regards.

xiepei.

I wouldn't care success or failure,for I will only struggle ahead as long as I have been destined to the distance.
0 Kudos
Message 5 of 8
(8,602 Views)

Hello Xiepei,

I modify the code to change filename everyday.

Hope it will help you.

regards.

B.Williot

0 Kudos
Message 6 of 8
(8,602 Views)

Hello B.Williot.

Thank you very much for your help.

I have been tried the code.It can't record the local time. See my attachment---fname.

I modify the code to display the time when it receive the datas.

if(countt<10)

    countt++;

   else

   {  

    f = fopen ("yibiao.txt", "a+");

             if( f != NULL )

            {

     fprintf (f, "%s  %s     ",DateStr(),TimeStr());

     fprintf(f,"CO2  %g, O2  %g, temperature   %g, CO   %g,humidity   %g, H2S   %g, CH4   %g\n\n",CO2,O2,TEM,CO,HUM,H2S,CH4);

              fclose(f);

             }

    countt=0;

   }

It save the datas automacticly every ten seconds.See my attachment ---- yibiao.txt

I wouldn't care success or failure,for I will only struggle ahead as long as I have been destined to the distance.
0 Kudos
Message 7 of 8
(8,602 Views)

Hello B.Williot.

I'm sorry .I could not add to the attchment.So I paste the records here.

fname

CO2  1, O2  19, temperature   4, CO   19,humidity  24, H2S  22, CH4   3

CO2  1, O2  19, temperature   4, CO   19,humidity  24, H2S  22, CH4   3

yibiao.txt

03-30-2011  9:23:07     CO2  1, O2  21, temperature  25,CO  20,humidity  32,H2S  19, CH4   2

03-30-2011  9:23:18     CO2  1, O2  21, temperature  25,CO  20,humidity  32,H2S  19, CH4   2

Now I want to try another method to save datas automaticly in excel  based on CVI's SQL Tooklit.

Someone says I should use the database to save  datas if I want to save large amounts of datas automacticly.

Can you help me? I don't know how to use CVI's SQL Tooklit. I hope you will give me some directions.

Looking forward to hearing from you.

Best wishes !

xiepei

I wouldn't care success or failure,for I will only struggle ahead as long as I have been destined to the distance.
0 Kudos
Message 8 of 8
(8,602 Views)