Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

Parse one String (containing numbers) into two Arrays and display results in meter (eg thermometer)

Hi experts,

 

 

I am reading from a barometer though the serial port. The data I receive are just numbers, eg. 256 for temperature and 29876 for pressure. These numbers will be divide by 10 and 100 at a later stage in LV. 

 

I have placed these two numbers in a string in the form of "256 29876", a total of 9 bytes including 'space'?

 

I want to break down this string into two strings of 4 and 5 bytes to read temp(4 bytes) and pres(5 bytes) values or put them in an array and do the breakdown there, and then display the results on meters

 

I thought using a string to array and then parse the array and display the results but still haven't figured out how.

 

I also don't know  what to do after the array function takes place and how would I possibly  cast the data

 

 

Thank you for reading 

 

Stav

0 Kudos
Message 1 of 15
(5,187 Views)

Yours is a programming question.

If you are using LabVIEW, post in that forum.

 

 

0 Kudos
Message 2 of 15
(5,186 Views)

If you are using LabVIEW, I would use the Scan From String.


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 3 of 15
(5,181 Views)

Indeed I am using LV

 

Thank you for the prompt reply

 

I will try using this when reading data fromt the serial port cause at the moment I typed the numbers in an empty string myself

 

 

 

0 Kudos
Message 4 of 15
(5,167 Views)

Hi again,

 

 

It seems like it doesn't like something the way it is

 

The error coming up is: "LabVIEW:  Scan failed. The input string does not contain data in the expected format."

 

This is my VI so far following in the attachment 

 

Any help, ideas would be much appreciated

 

 

Thank you in advance

 

Stav

0 Kudos
Message 5 of 15
(5,165 Views)

First I have to ask if the data coming in is in the correct format.  You said it should be a number followed by a space and another number.  Is this truely what you are getting?


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 15
(5,139 Views)

Yes it is.

 

Is a 4 bytes number (including space) e.g 256 for temperature and a 5 bytes number for pressure e.g 27849

 

I am using a microcontroller and have programmed it to send the data out the serial port in this specific format, just numbers.

 

I think I read that 'space' might make the string to scan function thinking that this is the end of the string.

 

Alternatively, I could output the data as one long number e.g 25627849, without space, but still I need to break it down in 3 and 5 bytes.

 

Any ideas would be much appreciated.

 

Thank you

 

Stav

0 Kudos
Message 7 of 15
(5,135 Views)

Are you sending the termination character?  If not, the read won't work right unless you set the Enable Termination Character to FALSE in the serial port setup.


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 15
(5,131 Views)

Thank you for the reply

 

I don't quiet understand what the termination char does, I set it 'true' as I though it's right

 

I have just tried to turn it to 'false' but I still get the same error

 

Are there any other possible ways of doing that?

 

I was trying to treat the string as one string and break it down into two parts in an array but not sure how to go about it quiet yet

 

This is have I did, which doesn't work but at least I get some numbers (attachment ReadPort.vi)

 

In this vi, data come in with a douple space so that I have 5 bytes for temperature and 5 bytes for pressure

 

It seems like I get the same number in both meters

 

Any thoughts what to do?

 

 

Thank You for your time

 

Stav

0 Kudos
Message 9 of 15
(5,125 Views)

Something I just noticed.  Why are you reading 1 byte at a time (20 in your new VI)?  Your message is 10 bytes.  So read 10 bytes at a time.


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 10 of 15
(5,101 Views)