From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

signal analysis using serial wite and read

Hello everybody, i´ve been using LV for the last two weeks, i´m not a programer, i´m just trying to comunicate with a hardware of mine, i´m using the Basic serial write and read.vi example, and it works quite good, the thing is that i need to create a table, a graph, and a simple signal analysis such as mean, maximum, and minimum with all the measures taken by my device. i know how to do al these things, but a don´t know how to transform the tring read to a signal, the display of my device shows me the distance measured (example 10.785), the string read is a 7 length string (example +10785, mabe because of the decimal showed at the display), i know it has to be very easy, but i spent the last two weeks trying to figure this out, unsuccesfull untill now...can anyone help me please?

Thank you all....

Pablo.-

0 Kudos
Message 1 of 9
(4,205 Views)

Hello,

 

You can just use the funcion "String to Decimal Number" for example.

 

I'm sending to you a VI with an example.

 

Thanks.

 

Best Regards

 

Luciano Borges

National Instruments Brazil

Luciano Borges
Test Development Engineer
Message 2 of 9
(4,158 Views)

LUCIANO! THANK YOU VERY MUCH! I´VE TRIED THAT ONE TOO! IT SEEMS THAT THE "+" IN THE STRING, WAS THE PROBLEM, AND COULD NOT BE RECOGNIZED, I SOLVED THE PROBLEM THIS MORNING, AFTER A LOT OF WORK, I USED A MATCH PATTERN, AND THEN  SCAN FROM STRING.  AFTER THIS I COULD BUILD THE TABLE, MY NEXT PROBLEM IS HOW TO CUMULATE THOSE STRINGS!!!!, I´M TRYING WITH SHIFT REGISTER, HOPEFULLY IT´S GOING TO WORK...

CHEERS AND THANK´S AGAIN!!!

0 Kudos
Message 3 of 9
(4,152 Views)

Hello,

 

What do you mean with "accumulate strings"?

 

Would you like to concatenate strings?

 

Regards

 

Luciano Borges

National Instruments Brazil

Luciano Borges
Test Development Engineer
0 Kudos
Message 4 of 9
(4,092 Views)

LUCIANO, I´M BACK...FINALLY I USED YOUR EXAMPLE, IS EASIER AND MORE EFFECTIVELY THAN MINE...I HAVE TWO QUESTIONS ABUT THIS...

THE FIRST ONE IS HOW CAN I DO TO CUMULATE ALL THE STRINGS (NOW NUMBERS) I´M COLLECTING? I TRIED DIFFERENT KIND OF SHIFT WITH LOOPS STRUCTURES, BUT I CAN´T DO IT...

THE OTHER OPTION IS TO COLLECT ALL THE MEASURES I CAN (IF A SEND AN "N" LETTER, THE PORT WILL BE OPEN FOR "X" TIME, IN THIS CASE THE PROBLEM IS THAT I HAVE A STRING LIKE THIS (FOR EXAMPLE)

+01421
+01426
+01426
+01426
+01425
+01427
+01426
+0

AND THE DECIMAL STRING TO NUMBER ONLY RECOGNIZE THE LAST NUMBER (IN THIS CASE +01421) WHAT SHOULD I DO TO TRANSFORM THIS STRING?

i´m trying to send my example(is really simple), but i can´t, i dont know why,

Once again, thank you very much for helping me.... 

0 Kudos
Message 5 of 9
(4,077 Views)

hi!! I mean that every line is a measure, and each measure should be in the table and in the graph..So far I can only do this with the last measure, in both cases,

1.If I just send a signal (M) it opens the port just one time, and I read only one string (+01233) i would need to collect the first measure, send de M letter and collect the second measure, an so on...

2. The second alternative, is to send an N letter, so the port will be open, in this case i would ´nt have to accumulate the measures, becouse i woud have all of them in previous example string, the problem is that i can convert only the last "number"

I´m sorry, but I´m no very good programming i´m trying, but it´s just too many things to consider...

0 Kudos
Message 6 of 9
(4,071 Views)

JUST SOLVED, I WAS DOING IT ALL WRONG, FINALLY I INCLUDED ALL THE THE STRUCTURE IN A WHILE LOOP, THIS WAY I SEND THE SIGNAL AND HAVE THE RESPONSE ALMOST INSTANTLY...BUT IT´S STILL NO FAST ENOUGH, I´LL HAVE TO LET THE PORT OPEN AND TAKE ALL THE MEASURES I CAN...CAN ANYONE TELL ME HOW TO SEPARATE THIS STRING? EXAMPLE:

1.00151
 +0015

2.(BLANK)

 0

 +

 +001

  (BLANK)

 +0015 

 

THE STRING CAN HAVE MILLIONS OF DIFFERENT COMBINATIONS, IT DEPENDS ON WHEN I OPEN THE PORT..I WOULD NEED TO ORGANIZE THE STRING SO I CAN READ THEM RIGHT (+00151, THEN +00154 AND SO ON...)

0 Kudos
Message 7 of 9
(4,049 Views)

Please turn off your caps lock when replying.

 

If you have a continuous stream of data, the only real way to separate the data points is by way of some sort of delimiter or termination character.  You have plus signs and spaces (if that is what you mean by blanks) regularly occuring in your data stream.  Do either of them always separate your data?  If so, you could search for those characters in your string where it is all concatenated together to determine where one piece of data ends and the next begins.  Then you can send each piece of data to your string to number conversion.

 

Does your data come in with a termination character such as a line feed?  If so, it is best to use that by enabling the termination character setting for the com port.  Read a sufficiently large number of bytes, and the VISA read will stop when it gets the termination character.  So you will then have a complete piece of data for processing.  (Though the first data point may be incomplete if you open up the port in the middle of its transmission.)  It looks like you used the basic serial read and write example.  That is good for doing a quick read or write of the serial port and learning how to use the functions, but it is a poor example for many real world applications for communicating with real instruments.  The "bytes at port" method returns only the bytes at the port at that instant in time whether they have completely arrived or not.

 

Are you using your attached VI as a subVI in a larger piece of code?  As it is right now, it only runs once.  And there are a lot of odd constructions such as the loops that only run once, and a shift register in the string to number conversion loop where the shift register is never used either inside the loop (which again only runs once) or even outside the loop since you just split it and used an ordinary tunnel.

 

Message 8 of 9
(4,019 Views)

Hi! First of all, thanks for helping me, I´m having the hardest time to put this project together...

the answers to your questions:

  You have plus signs and spaces (if that is what you mean by blanks) regularly occurring in your data stream.  Do either of them always separate your data? ans: the plus signs precede every measurement taken, the spaces, deepens on how fast the reading goes, but it´s not a problem as soon as the "delay before read" is long enough (the minimum time to my project is 4 sec), so the thing should be how to send each piece (considering the "+") to number convertion.

 

If so, you could search for those characters in your string where it is all concatenated together to determine where one piece of data ends and the next begins.  Then you can send each piece of data to your string to number conversion. ans:how can I do this? 

Does your data come in with a termination character such as a line feed? ans: yes, it should have a carriage return constant, I´ve check that using an hyperterminal.

 

If so, it is best to use that by enabling the termination character setting for the com port.  Read a sufficiently large number of bytes, and the VISA read will stop when it gets the termination character.ans I´ve tried this and the string still the same..Perhaps I did´nt understand what you meen..

 

It looks like you used the basic serial read and write example.  That is good for doing a quick read or write of the serial port and learning how to use the functions, but it is a poor example for many real world applications for communicating with real instruments.  The "bytes at port" method returns only the bytes at the port at that instant in time whether they have completely arrived or not. ans Yes, I tried this example because, as a said, this is my first time using Labview, and I have no idea how to program..Every thing I did so far, was using the labview help..when I started it worked so good with my device, that I used this as a platform to my work.

 

Are you using your attached VI as a subVI in a larger piece of code?  As it is right now, it only runs once.  And there are a lot of odd constructions such as the loops that only run once, and a shift register in the string to number conversion loop where the shift register is never used either inside the loop (which again only runs once) or even outside the loop since you just split it and used an ordinary tunnel. ans, I´ve already correct this, I´ve eliminate those loops. Right now a have two options, the first one is to send the M letter, open the port, see what my device is reading this in a loop that runs every "x" ms, in this case  I´ll have one string at the time, and it´s working quite good, but still no fast enough (64 lectures per second). The second option is to use the N letter, this leaves the port open all the time and take all the measurements until I decide to close it, but this is the case I´m having problems with.

 

If you can help me, I´ll be grateful..

 

 

 

 

 

0 Kudos
Message 9 of 9
(3,982 Views)