LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Starting a string when a character is detected

Solved!
Go to solution

Hi,

 

I was wondering how I can start outputting a string once a specific character is detected. So for example my string, when the program is run, will output "llo~hello~hello~he", with the ~ serving as a synchronisation character. How can I make the string output as soon as tilde is detected, not straight away, so that I end up with ~hello~hello~hello and so on. My code is attached if it may prove useful.

 

Regards,

Christopher

0 Kudos
Message 1 of 5
(1,995 Views)
Solution
Accepted by topic author programlad19

Hi lad,

 

can't open your VI (due to its LV version), so a simple suggestion:

check.png

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 5
(1,992 Views)

So I'm looking at your code and have a few questions, or comments. Perhaps you can clarify, I'll number rather than bullet point to make it easier to reference if you'd like:

  1. You're acquiring an analog voltage using DAQmx and then converting to a 'digital' signal by comparison with (max - (0.75*range) - 0.2). Is that right? (Is it what you want?)
  2. You then have a For loop which compares these values and creates what you call a "binary string". Some brief comments here:
    • You don't need to do "=" for True comparisons, the result is the same as the input
    • You can replace the Case structure which has True/False cases with a Select node
    • Rather than using "Append String" in the loop, you could use an Indexing output and then append them all at once (use Concatenate Strings with an array of strings to get a single string). You might have better performance using a different method (e.g. Shift Register and Concatenate String, combined with writing directly to the control (you'd need an Indicator in this case, I'm not sure if that's a problem, if so, you could consider a Local Variable)). You also have a 100ms wait each character, so you may not care about performance.
    • There's a race condition with the Reinit to Default (you don't know when this will occur relative to the writing of the Control, although probably it will happen either before or after the first element is written).
  3. If you right click on the Boolean Array to Element and choose the Properties > Output Configuration, you can set U8 rather than having U32 then converting after
  4. If you want ASCII characters, you can get them from U8 using the following methods: Convert ASCII Characters to ASCII Codes in LabVIEWByte Array to String.
  5. Searching the string as GerdW showed will split it based on a specific character.

GCentral
0 Kudos
Message 3 of 5
(1,961 Views)

Thanks, this works perfectly. Much appreciated.

0 Kudos
Message 4 of 5
(1,930 Views)

To answer your questions:

1) I'm using two myDAQs, one to submit a signal and one to receive it. It's a group project and I'm working on the receiver, which will take a signal and decode it from binary to ASCII. The signal is received as a waveform, and then the Y values are taken from the graph and compared to a comparison value which determines whether the value is greater than or less than the comparison value, aka true or false. This is then compared with the boolean true constant to see whether a 1 or 0 should be appended. The whole append string thing is not needed and it's just something I left in for checking with my project partner's receiver.

 

2) I'll have a look at what you mentioned - I took away the equals comparison thing and it works fine, so thanks for that.

 

3) I've just made these changes as well, thanks.

 

Oh and all the code runs perfectly fine, like I said it's just the representation of the text string I wanted to clear up. Thank you both for your help. Greatly appreciated.

0 Kudos
Message 5 of 5
(1,928 Views)