LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

String to number

Hello everybody, I´m getting data from the COM port, throught Arduino with Visa interface (Serial), the program that is loaded in my arduino is the attached in the txt file. In labview I had put a "Match pattern" to look in the string for the "T" and "H" variable as seen on the VI jpeg. The problem is when I run the program I get the following results of 0.000 exp after the frac/exp string to number instead to the real values of this variables, I need another "block" for the conversion?, what can I do to solve this problem please help me. 😞vi.jpg

Download All
0 Kudos
Message 1 of 17
(4,450 Views)
Why are you looking for : besides the t and h? You have not probed the string do it is impossible to say what you actually read.

You have a few problems. First, you should not use the VISA Bytes at Port. Just use a read with a high Bute count. Instead of two different match patterns, it would be simpler to split the string to get the prefix and number and wire the prefix to a case statement.
0 Kudos
Message 2 of 17
(4,433 Views)

VISa.PNG

Well a few days back, I found this on the web, I´m testing a few sensors though arduino, I can´t use the arduino toolkit because I need some libraries to acquire the data, so I´m trying to do some thing like the picture above. I´m attached another picture of the actually VI that I´m using and It´s works fine, but tha final thing that I want to do Is no to use a lot of "Bytes at port", just put patterns to find the variables of the string just like the picture above.

0 Kudos
Message 3 of 17
(4,423 Views)
Then enable the termination character on the VISA Configure Serial Port. And, as I already mentioned, multiple Match Pattern functions are not necessary unless you don't mind the indicators going to zero.
0 Kudos
Message 4 of 17
(4,414 Views)

Excuse me, buth I don´t understand at all... I´m new on this, In the arduino, well you already saw the program that is running in the arduino, I put the data in variable (T and H), so how can I read that data in labview software, I´m already look for that in utube but without success 😞

0 Kudos
Message 5 of 17
(4,353 Views)

All of the code I've seen from Arduinos sending data through the serial port append an End Of Line character to the end of the message.  That is a Termination Character.  It is a way of telling the reciever that the message is done.  So with the VISA API, you want to enable the termination charcter and use 0xA (Line Feed) as the termination character.  Both of those are the default settings if you leave them unwired on the VISA Configure Serial Port.

 

What the VISA Read will do from there is read all of the the data until one of three things happen: 1) the timeout has expired (default it 10 seconds), 2) the number of bytes you requested are read, or 3) the termination character is found.  So what you want to do is get rid of that Bytes At Port node and tell the VISA Read to read a lot more bytes than you would ever expect.  For instance, if the long message is 35 characters, tell the VISA Read to read 50 bytes.

 

So now that you have your message, I would use Search Split String to locate and split the messag at the ':' (colon).  The string before match should then go into the case selector of a case structure.  So you set up a case for each possible message you can receive.  Inside each case, you do whatever decoding/parsing is necessary to get your data and update the UI.


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 17
(4,346 Views)

How is the data read in from your VISA Read function getting to your Match Pattern functions?

 

Wire the "Read Buffer" output of the VISA Read to your Match Pattern functions!

Omar
0 Kudos
Message 7 of 17
(4,336 Views)

Thanks, but I´m already done but without success again in the conversion string to number part, shows me the value of zero instead of a real value. I have write the code below that is running on arduino (maybe I have wrong in there), I attached an image with a VI that´s it´s works fine (VISA_INTERFACE_TEST) to this message, the difference beetween that I want to do is only to use one single Bytes at Port instead of 1 for each variable that I want to read, just like the VI above, the one that have pressure, temp, long, lat, alt, sat, the largest VI one. This is the code that im running on the arduino, I want to read in labview the T and H variables.

 

void setup() {
  Serial.begin(9600);
  dht.begin();
}

void loop() {
  if(Serial.available() >0)
  {
    in = (byte)Serial.read() & ~ (0x20);
    
   if (in == 'T')
    {
      
      Serial.println(temp= dht.readTemperature());
   }else if(in == 'H')
    {
      Serial.println(hum= dht.readHumidity());
    }
  }
  delay(1000);
}

ScreenLV.PNG

VisaInterface_Test.PNG

0 Kudos
Message 8 of 17
(4,315 Views)

Again, GET RID OF THE BYTES AT PORT.  That does nothing but add complications and race conditions.  Your microcontroler is sending out the termination character.  So why are you ignoring its usefulness?  Set the number of bytes to read to 50 and the VISA Read will do on its own what you have while loops doing.

 

What is happening inside of your ReadTemperature() and ReadHumidity() functions?  Are they returning data formatted into ASCII?


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 9 of 17
(4,308 Views)

The bottom LabVIEW code has VISA Writes where the "H" and "T" are written to your device before an attempt to read H and T.

 

The top LabVIEW code does not have any VISA Writes.

 

Do you expect your device to send you H and T without first requesting it?

Omar
0 Kudos
Message 10 of 17
(4,304 Views)