LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Saving multiple Modbus reads to a csv file

Solved!
Go to solution

Hello,

The attached VI deals with reading and writing a plc and load cell conditioner. The loadcell output (server1) writes to file very well except is tab separated and I would prefer coma. I would really appreciate some advice how to incorporate the other reads and get them all on one line, comma separated with time stamp. There will be a while loop, of course, around the whole scheme to keep it running. One problem I frequently come across is that the data types are wrong for whatever VI I try to add.

 

0 Kudos
Message 1 of 6
(1,499 Views)

Hi Ed,

 

except is tab separated and I would prefer coma.

Right now I don't see any place in your VI where you even define a separator char.

When you want to use a comma you should define a format string for your FormatIntoFile function…

 

some advice how to incorporate the other reads and get them all on one line, comma separated with time stamp.

First write the timestamp to your file, then write "the other reads", then write your holding register to the file.

Use a format string which fits to your requirements!

 

One problem I frequently come across is that the data types are wrong for whatever VI I try to add.

Then you need to convert them to the needed datatypes…

 

Btw. it's a very bad habit to hide control/indicator labels in the block diagram!

Best regards,
GerdW


using LV2020 on Win8.1+cRIO
Message 2 of 6
(1,465 Views)

HI GerdW

I see  your point, I imagine that I could either try to write each value to an array and then write the whole lot to  a file or  try to append each value to the file consecutively, I dont know which is best. The nice thing about Labview is that you can try things out and if it doesnt work out , no harm done, to have the opinion of an expert though might save a day or so.

Ed

0 Kudos
Message 3 of 6
(1,432 Views)

I have tried the option of putting all data reads in arrays then writing all to file but it doesnt look good and for some reason the link between the concatenate strings and write to spreadsheet file functions doesnt work. I know that the source is string and sink is 1D array of strings but I have seen a youtube where this worked. Any solutions?

 

 

concatenate strings.png

0 Kudos
Message 4 of 6
(1,410 Views)
Solution
Accepted by topic author EdHarris

If you want to build an array it might be a good idea to use the Build Array Function not the Conncatenate Strings functions.

 

BTW, the flat sequence can be omitted - Dataflow already does the job.

The For Loop also is useless as you request the same values 3 times, but only use the last value.

 

Regards, Jens

Kudos are welcome...
Message 5 of 6
(1,401 Views)

Hi jg69,

If anyone else is searching, I have found a solution to write multiple reads on one line. I found that the build aray function will concatenate, which can be altered in the shortcut menu by selecting "concatenate inputs". I also used part of a 2D Boolean to string.vi which I found on a post by P@Anand, to write booleans to an array with a for loop. So I changed the tunnel in my for loop to do the same with the three consecutive reads - which you pointed out would only give a final value. Some of the inputs had to be treated differently to get them all on one line.

Thanks for your suggestions,

Ed

0 Kudos
Message 6 of 6
(1,387 Views)