LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

urgent help needed:saving serial port data in multiple txt file

Solved!
Go to solution

Hi guys, i am working on a project in which i am trying to read the serial port data from the micro-controller and saving the data in multiple file location. i have written a code which can read the data  and create multiple text or csv file simultaneously, now the size of the micro-controller adc buffer is 453, so what i want to do is to acquire  and save the 453 values on multiple file on each iteration, but when i am running the code the the data is stored randomly on the multiple file location means instead of getting 453 values in the text file  i am getting 253 or sometimes 1000 values on each iteration. can someone help me with this, i am in urgent need.

Thanks

0 Kudos
Message 1 of 18
(3,316 Views)

You need to post your code (the actual VI, not a screenshot) for us to help you.  If it's a lot of VIs, put them in a zip file first.

0 Kudos
Message 2 of 18
(3,313 Views)

this is the vi

0 Kudos
Message 3 of 18
(3,272 Views)

Hi lm,

 

i have written a code which can read the data  and create multiple text or csv file simultaneously,

No. Your VI creates one file per iteration, one after another.

Nothing "simultaneous" found here.

 

now the size of the micro-controller adc buffer is 453, so what i want to do is to acquire  and save the 453 values

Then why do you use BytesAtPort?

Why do you read 306 times BytesAtPort bytes?

Why not just read 453 values (of known bytecount)?

You initialized the serial port to use a TermChar, so use that one!

 

Why is there a 100ms wait in the FOR loop? Does it really take ~30s to transfer 306 values over the serial port?

Why do you create a 2D array before ArrayToSpreadsheetString?

Do you really need those VISA events? VISARead can also wait until a certain number of bytes are received…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 18
(3,268 Views)

Can you provide some information about the VISA configuration of the Sender?  Is the data being streamed?  Is it Ascii, binary, something else?  Does the Sender use the (relatively common) convention of sending a Termination Character (typically <LF>, 0x0A) after a series of bytes?

 

I notice you are using some VISA commands and configurations I've not seen before, and wonder if this might be messing up your communication.  I've successfully used VISA with microcontrollers sending at high rates just by using "usual VISA Procedures", including using Termination Characters and/or an understandable Transmission Protocol from the sender.

 

Bob Schor

0 Kudos
Message 5 of 18
(3,266 Views)

Ok, time to take a small step back.  What exactly is the message format coming out of the micro-controller?  We need to know this in order to provide any advise.  Is the data in a raw binary/hex data or is it converted into an ASCII string?

 

If ASCII:  Is there a delimiter between the samples and a termination character?

 

If raw binary/hex:  Is there a start character, length byte(s), and/or a checksum?  How many bytes are a single data point?


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 6 of 18
(3,254 Views)

dude here one more vi, it  is working fine for some like 5 to 10 mins and after that the continous flow data to be stored in the file is mismatching, and sometimes the data is getting corrupted.......

0 Kudos
Message 7 of 18
(3,250 Views)

Dude, there are some problems with your code

  1. You read Bytes at Port before your For Loop, and then assume for each iteration of the For loop you will have the same number of bytes at the port. What happens if the number is smaller? You will get a Timeout Error that occurs 10s later, you configured it this way. Once you get an error, because it is in a shift register, subsequent iterations will not run correctly because you have an error.
  2. You are writing new files in your while loop, then close each file in the while loop. Right now you are only closing the last file.

Good luck dude!

mcduff

0 Kudos
Message 8 of 18
(3,243 Views)

dude i am new to labview, actually i have to a endurance test over a pneumatic valve for a period of 1 month and i have to generate  around millions of files with data which i can use for further processing in matlab,now for the code should i use  a peoperty node inside the for loop or while loop, or any other ways to store the adc vaues in txt file, any code correction or code would be helpful.

0 Kudos
Message 9 of 18
(3,231 Views)

dude i am new to labview,

You don't say.

 

Dude what I attached still sucks, but maybe an extremely tiny bit less than what you previously had. (I have meeting to go to and real work to do.) You need to write down you requirements and start testing simple things, that way you will learn.

 

Be excellent to each other.

 

mcduff

 

 

EDIT: I forgot my own advice move the Close file inside the while loop.

0 Kudos
Message 10 of 18
(3,228 Views)