LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

help with serial

Several issues:

  • The loop should be around the Read, since that's what you're continuously doing. Did you look at the Advanced Serial Write and Read example? Where is the loop in that VI?
  • Also, why are you sending an *IDN? command? Is the device you're talking to expecting it? If not, why are you sending it?
  • Your use of local variables is a race condition, and has already been mentioned. The code that works with the data that's been received should be next to the data that's being received, not in some far off land with you using a courier to send it.
  • As I already mentioned, you cannot guarantee that you're going to get the right number of bytes on the serial port. You have to accumulate the serial port data and convert it when you have the right number of bytes.
  • You're converting the data into an integer. Is this a scaled value? If so, you are not performing any kind of scaling on the values you receive.
  • I have no idea why you're type casting an array of floating point values to a Boolean. If you want to turn on/off the Boolean indicator use the Greater Than 0? function (or one of the other comparison functions) to get you the true/false state. And, using a case structure to update the Boolean indicator is simply silly. Use the wire, which is already a Boolean value.
0 Kudos
Message 11 of 46
(1,766 Views)

thank you for you intention

but i have put the while loop ,i want to plot the sine wave after reading immedialtly and the data is string so i will not plot string so i convert it to integer to have the same shape of sine wave .do you have any solutions else.

 

0 Kudos
Message 12 of 46
(1,749 Views)

You're not really understanding what I'm saying. Perhaps it's a language issue. Yes, you have a loop, but you have it over the entire code. That's not correct. You do not want to reinitialize the port every time. That could clear your buffer. Again, did you look at the Advanced Serial Write and Read example? This is the third time I've asked this.

 

Also, why are you converting it to an integer? Is this what was generated? You had mentioned in your original thread that you're sampling the waveform. OK, so are the samples floating point values, or scaled values (which would be integers). You have to convert the data you receive based on what you sent. If you sent a floating point number then you don't want to convert it to an integer on the receiving side. That would make no sense, since you'd lose data. If you're scaling the value at the source, then you also have to scale it at the receiving end.

 

I will try to put together an example later this morning.

0 Kudos
Message 13 of 46
(1,736 Views)

Attached is an example (LV 8.2) that monitors the serial port for data. It converts data in 4-byte multiples, as that seemed to be what you were implying. You did not indicate whether your source data is being sent as a floating point number or an integer or if it's scaled, so the conversion uses the SGL data type. If your source data type is different, then you will need to modify the number of bytes, and the data type of the array fed to the Type Cast function. See how far this gets you.

0 Kudos
Message 14 of 46
(1,729 Views)

please i am not professional all what i did that i convert data from analog to digital and send it as byte

that's all

whan i try to plot it it didnot give me any thing ,because serial read it as string and i want to plot it as numbers  i used array and type cast and it give me shape is quite close to origin

0 Kudos
Message 15 of 46
(1,704 Views)

when i tried the advanced example it give the same shape when i change number of bytes to read

but problem is still exist because when i change the frequncey of analog signal it want to change number of bytes to read and i told  that my signal contain more than one frequncey,so do we have solution for this problem

0 Kudos
Message 16 of 46
(1,671 Views)

Did you look at the example I posted? You've still only provided half the information. For instance, what is the datatype at the source? How is it being converted to a string? Do you have the code for the source?

0 Kudos
Message 17 of 46
(1,661 Views)

yes i looked in your example i didnot go as i want it ,i send data as bytes

which code do you mean ,some body asked before ,i sent the program for microcontroller and he was very angry

as he said this is labview forum

0 Kudos
Message 18 of 46
(1,648 Views)

(Again, another reason to keep it one one thread.)  Link to the basic code.

 

It looks like that code is writing out a series of bytes followed by a carriage return and linefeed.

 

So it would be a good idea to set your VISA port to enable the termination character and to be a linefeed character.  Now read a sufficiently larger number of bytes, and you will get the whole message once the linefeed is read.  Then you can strip off the last two characters of the received string.

 

Now the mystery is, what is the function WordToStrWithZeros(temp_res, output) ' Convert result to string doing?  How is it taking your data and converting it to bytes?  Once you know how it does that, then you can figure out how to convert those bytes back into to data.

 

I am going to guess that it isn't sending data in raw binary format.  Let's say where a double floating point number (8 bytes) is not typecast to a string of 8 bytes.  But it is probably being converted to a human readable series of ASCII formatted characters.  Why?  Because if a typecast of just the right number winds up with a hex0A byte (10 decimal or a linefeed character), how would you ever know that that byte is a part of a piece of binary data, as opposed to a termination character.

 

Why don't you post an example of the bytes being received in LabVIEW?  I don't think I have seen that yet in any of your posts.  It is kind of hard to help you decode any data when you don't provide the data that you are receiving, and tell us what you expect that data to say.

0 Kudos
Message 19 of 46
(1,639 Views)

 word to string  convert  the output of conversion to string

i used a nother  simple program send the result as bytes

0 Kudos
Message 20 of 46
(1,627 Views)