11-26-2012 01:01 PM
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
11-26-2012 01:07 PM - edited 11-26-2012 01:08 PM
Yours is a programming question.
If you are using LabVIEW, post in that forum.
11-26-2012 01:37 PM - edited 11-26-2012 01:38 PM
If you are using LabVIEW, I would use the Scan From String.
11-26-2012 02:58 PM
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
11-26-2012 03:20 PM
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
11-26-2012 06:24 PM
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?
11-26-2012 07:02 PM
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
11-26-2012 07:28 PM
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.
11-26-2012 08:12 PM
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
11-27-2012 07:01 AM
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.