LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Visa port string and substring

Solved!
Go to solution

Hi Ravens

 

When I start code, only after about 1 secound comes the first string and i am not sure but it is not complete, so after 2 or 3 secounds I have the complete string.

Arduino sends data with a delay of 1secound and my loop is with same delay.

About carriage or line feed (I will see what is this mean) I dont know what is the function

 

Here is some lines from arduino output

 

cpalka_0-1600938649901.png

 

Best regards

cpalka

 

 

 

 

0 Kudos
Message 11 of 18
(823 Views)

This is very basic stuff, and everyone has given you all the knowledge you need to do this.  Well, almost.  I don't think anyone had an idea that you wanted to read every x seconds.  (By not posting your code, it probably delayed your answer by several DAYS.)

 

Everyone's suggestions so far are spot on:

  • Use the termination character to end your read.
  • Throw out the first read; assume it is incomplete.
  • On every message thereafter, parse the string for values.

With the additional information we've managed to rip from you:

  • Use the elapsed time express VI to tell you when the string needs to be dealt with - e.g., saved, displayed, or whatever.
Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
Message 12 of 18
(814 Views)

Hi billko

 

Sorry, for this mistake.

In attach is my code.

Ok, if i use the termination character, i suppose it will "write" a character in the string to tell that string finishes there.

This code as it is will not work too, because in the first moments arduino sends an incomplete string and the scan from string will crashs again.

 

I will try to do a case and when it crashes (error) gives a true and code sends a complete string after that come false and enter the strings from arduino

 

Best regards

cpalka

 

0 Kudos
Message 13 of 18
(802 Views)

@billko wrote:

This is very basic stuff, and everyone has given you all the knowledge you need to do this.  Well, almost.  I don't think anyone had an idea that you wanted to read every x seconds.  (By not posting your code, it probably delayed your answer by several DAYS.)

 

Everyone's suggestions so far are spot on:

  • Use the termination character to end your read.
  • Throw out the first read; assume it is incomplete.
  • On every message thereafter, parse the string for values.

With the additional information we've managed to rip from you:

  • Use the elapsed time express VI to tell you when the string needs to be dealt with - e.g., saved, displayed, or whatever.

Sorry, I'd move the "Parse" step into the second group.  (Why parse a string you're not going to use?)  Oops on my part.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 14 of 18
(795 Views)

Thank you for the code!  (Really, it clears up a lot of stuff!)

 

Okay, enabling termination doesn't actually mean it sends anything.  It means that the read will read until it sees the termination character, then automatically stop.

 

Your code isn't working mainly for one reason.  The loop iteration is dependent on a timer, not depending on when the message being sent is available; therefore, you might get lucky and get a read the first time around; after that, probably (most likely) not.

 

Your thinking on this issue has to change entirely, and this is probably where experience would have helped a lot.  because this instrument is spewing information instead of you asking for it, you can't just say, "I'll check every second for data".  You have to say, "I need to read all the data coming and I'll deal with the current data set every second".

 

So get rid of the "Wait Until next ms Multiple" (it's not being used properly anyway - the first iteration will very likely be something less than 1000 ms the way it is used here) and instead go with the "Elapsed Time" express VI set to one second and do whatever it is you want to do when the Boolean "Time Has Elapsed" == TRUE.

 

Now comes the caveat.  You never mentioned that you are writing as well as reading.  I have no idea what this "+/- SLIP" stuff is all about.  And a note here: NEVER, EVER delete the labels from your front panel objects.  Besides making it very difficult for others to follow your code, there is evidence to show that the compiler can become confused as well.  Hide it if you must, but don't delete it!

 

Because of this new information, all we've been talking about may just be about to be thrown out the window and we'll have to start all over again.  (But at least we know about it now.)

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 15 of 18
(789 Views)

Hi billko

 

What an encyclopedia of labview! Many thanks for your teachings.

 

A litle bit of the story of this project. This is a machine that some mechanical engineers build and let it die. Now me (civil eng.) I will put it working and use it for researching. This is for measure the slip in roads (trailler with a slip wheel) and I can control de slip level increasing "+" or decreasing "-" the amps in a electric breaker.

There is more 2 or 3 commands that I will need to send to arduino.

About electronics there is a lot to do too, the circuit was made by students and without some logical. But now I could put the electronics working. 

 

At the beginning people says to me that the way to work with machine is reading data with HyperTerminal or similar, copy this data into a txt file and that's it.

 

As I know a little bit of labview I would to transform this very poor data into a valuable data, specially during the acquisition (circulating in the road -trailler), I will control better the speed (km/h instead RPM), and other parameters.

I hope You could be patient with me because I am not an expert, and sometimes I use hardware from NI, other I use VISA others LIFA....

So if you do a little bit of each, I am not expert in one 🙂

 

At this time the code is only to test all parameters, after that I will put everything in place an more presentable.

 

Best regards

cpalka 

 

 

 

 

 

 

 

0 Kudos
Message 16 of 18
(776 Views)
Solution
Accepted by cpalka

This is quickly becoming complicated - at least for a novice LabVIEW developer.  This is probably best executed as what is known as the QMH design pattern.

 

You should start with something simple.  Get the QMH to:

1) initialize VISA

2) read one message per iteration (don't worry about processing yet - just stick an indicator on the VISA read output to show you can reliably get a message), call itself until we

3) exit on demand.

 

Hopefully the example mentioned in the link gives you an idea on how to do that.

 

Once we establish that we can do this reliably, we can add stuff in.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 17 of 18
(762 Views)

Thanks billko.

 

 

Best regards

cpalka

Message 18 of 18
(742 Views)