LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Receive data from the serial port and save it in excel with time and date

Hello, I am doing a program in labview that receives arduino data and saves them in excel along with the time and date.

 

The program is to save the events of the user inputs for an access control system. When the user enters the place, save the user ID along with the time and date in an excel sheet.

 

If a user does not enter the place does not save anything.

 

I have already done the program and it works well. The problem is that the program saves every millisecond of time (without the user having entered the site) (see Labview Excel image) . And consequently saves a lot of data (time and date) that is useless.

 

I need to make a condition that saves the time and date every time I receive a data from the serial port, if the program does not receive any data does not save anything.

 


I did 2 labview programs. In labview 1.0 (see labview 1.0 image) add a case in order to know if I received a serial port data. In case of receiving a data from the serial port "save" in excel the data together with the time and date. In case you do not receive any information "Do not keep anything." But I did not know how to make that condition so I put a boolean.

In labview 2.0 I did the same thing only that I put the structure case outside of the while and the condition put an error state. I get the same result as the previous one. I keep saving the time and date without having received a data by the serial port.

Someone can kindly help me, I'm new and I've been learning labview for 1 week.

 

Thank you very much

 

Merry Christmas and Happy New Year

 

(Translate by: translate google)

 

0 Kudos
Message 1 of 9
(6,921 Views)

Hi Carlos,

 

saves them in excel

No, you create a (formatted) text file. Even naming it with a "xls" suffix seems wrong to me. Use ".csv" instead!

 

The problem is that the program saves every millisecond of time (without the user having entered the site) (see Labview Excel image) . And consequently saves a lot of data (time and date) that is useless.

Yes, you programmed it this way…

 

I need to make a condition that saves the time and date every time I receive a data from the serial port, if the program does not receive any data does not save anything.

That's your condition: "IF no data received THEN don't save to file"!

 

Another problem:

When you set your serial connection to wait for a TermChar you should not use BytesAtPort! (Infact you don't need BytesAtPort at ~99.9% of all serial communication routines!)

Use a "big" number for the bytes to read and check for TimeOut errors…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 9
(6,856 Views)

That's your condition: "IF no data received THEN don't save to file"!

 

Hi, thank you very much for your help. I just want to know how to make that condition in labview? In short, I do not know what function / instruments to use to make that condition.

 

In arduino to receive a data for example is easy:

 

// Read if you received a serial port data
If (Serial.available ()> 0) {

 

   // read the incoming byte:

     read = Serial.read ();

 

   // Print the value "read"
      Serial.println (read);
   //
}

 

But in labview I do not know how to make the condition to know if it received a data or not.

 

I really hope your help, I'm very new to labview and I want to learn, really.

 

It's my only query at the moment, thank you very much. Happy New Year!

0 Kudos
Message 3 of 9
(6,809 Views)

Hi Carlos,

 

In arduino to receive a data for example is easy

"If (Serial.available ()> 0)"

In LabVIEW it's easy too!

You either check for an empty string (after VISARead) or you simply check the output of BytesAtPort - which basically is the same as "Serial.available"…

 

Btw. Using BytesAtPort is just WRONG here! You have initialized your serial communication to use a TermChar (see the help for InitSerialPort): delete the BytesAtPort node and use a constant (like 99) as input for VISARead!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 4 of 9
(6,786 Views)

From your latest image:

Refer to this image that I used here.  This is a proper set up a serial read when the instrument sends data at non-determinate times.  I first use the Bytes At Port to see if any data is available.  If there is data, I read it.  AND DO NOT USE THE BYTES AT PORT TO DETERMINE HOW MANY BYTES TO READ.  With the termination character, the VISA Read will stop reading when that termination character is read.  So tell the VISA Read to read more bytes than your message could possibly be.  The reason is that you could be reading partial messages due to weird race conditions.  This is true not matter what language you use.  The Serial.println does the same thing.  Also note that in the 0 case I have a wait (I think 50ms).  No reason to wait if you have data.

 


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 5 of 9
(6,777 Views)

I did it, it works the way I want it to. Thank you very much for helping me. Happy New Year!

I share it with the community. (Attached image)

0 Kudos
Message 6 of 9
(6,758 Views)

If you want to share your code with the community, do not use a simple picture in jpg. Use a LabVIEW snippet, or attach your actual VI. Besides, if you have found a solution, mark that post as "solution". This helps future visitors with the same problem.

0 Kudos
Message 7 of 9
(6,751 Views)

@Blokk wrote:

Besides, if you have found a solution, mark that post as "solution". This helps future visitors with the same problem.


You should also give Kudos for posts that you found helpful.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 8 of 9
(6,736 Views)

good evening dear,

 

Could  you please share the Arduino code file for this example.   

or a pic

0 Kudos
Message 9 of 9
(3,109 Views)