LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Error: the number of samples must be > 0

When I try to perform a serial communication between two computers via RS-232 (cable less than 3 meters) an error occured (on the topic).Why?! I´m using the following program to solve this problem.

Thanks for help me...

Rafael Rorato

0 Kudos
Message 1 of 20
(4,982 Views)

Most probably, you never get the right chars on the receiver side since you didn't provide a way of synchronization. How many chars should you receive ? Your receiver will get only the chars already arrived on the serial port, even if the string has not be received entirely, resulting in an error. And of course, at the next loop iteration, the things will get even worse, since reading the serial port will bring the unread remains of the previous com...

Read the port until you have received all the chars, before converting to actual numerical values.

Chilly Charly    (aka CC)
0 Kudos
Message 2 of 20
(4,974 Views)
A way of synchronization that I think should solve it would be to put the same number of bytes on "byte count" input. I don´t know exactly how may bytes is necessary for my communication to be free of that error. I´m using 20 bytes on byte count input, and the error persists. How can I proceed?!
 
Thanxs...
Rafael

Message Edited by 8144-9199 on 12-21-2005 11:24 AM

0 Kudos
Message 3 of 20
(4,960 Views)
The right byte count is 100, as you may check by monitoring the length of the string written to the serial port.
I don't think that this would completely solve your problem, though, because you are streaming data at the maximum possible speed (I mean program speed, not baudrate).
If the sync is lost for some reason (an unexpected latency), there is no mechanism to regain it. You should make sure that the receiver has got all the data before sending another packet (you could slightly improve situation with a little effort e.g. by enabling hardware handshaking in port configuration - but you need the proper cable connections of course).
Other suggestions:
- don't open and close the port for every iteration, do it once at program start and stop
- in the serial port configuration, disable the termination character
- try to manage errors: if something goes wrong you have little chance to stop the vi (as it happened to me when I forgot to set the VISA resource before running it)

Paolo
Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
0 Kudos
Message 4 of 20
(4,934 Views)

Synchronization is not the only issue in your vi. There is also a mistake in the way you convert from double to U8 in the sender, and back on the receiver side. Any number would be converted to an integer value between 0 and 255, and I don't thik that this is what you had in mind. There are several solutions. I have attached a simple one, to convert the double array into a tab separated string, then back to an array.

An example of what you could do to synchronize the reception is also given. As I said, it is an example, not a solution to your problem. You will have to get a better understanding of what is going on when you communicate between machines. For instance, what happens during the first communication, immediately after start ?

Chilly Charly    (aka CC)
Message 5 of 20
(4,960 Views)
CC,
 
I can´t run your program because your LV version is 7.1 and my 7.0, could you give me a way how can I get LV 7.1 or greater than?! My conversion is correctly. Look the following program.
 
Thanks for help me...
 
Rafael Rorato

Message Edited by 8144-9199 on 12-22-2005 01:59 PM

0 Kudos
Message 6 of 20
(4,897 Views)
Here is a 7.0 version. I'm afraid that the only way to get a more recent LV version is to ask NI for an update...
 
Chilly Charly    (aka CC)
Message 7 of 20
(4,893 Views)
CC,

I can´t understand your program. When I select 1000 bytes on byte count input, the same error occured. I´m sending exactly 1000 bytes (put a indicator on return count in VISA Write) you will can see that, use the test simulation.vi that I prupose.

Thanxs

Message Edited by 8144-9199 on 01-06-2006 01:44 PM

0 Kudos
Message 8 of 20
(4,849 Views)

I already told you that your conversion was a mess, but you didn't listen to me... and you didn't either verify your work !

You are creating a curve with 1000 points (doubles) that is exactly 8000 bytes long. Then you convert it implicitely to a 1000 bytes U8 array (means that the highest value will be equal to 255, all the negative values will be converted to 0, and all intermediates values in between will be rounded to integers. If your sine waves had an amplitude equal to one, you will finish with a nice square wave !). The residual 1000 U8 array is then converted to a string, successfully sent through the serial port, then converted back to U8 and to Doubles. Of course there is no way to recover the initial values since the first conversion step has spoiled the data.

I have modified your test vi, just removing the communication operations. See my point now ?

There are several other ways to convert numerical values to serial string. The simplest one is to use the Fract/Exp String to Number function, in the string/number conversion subpalette. A more advanced technique would be to convert your double array to a string using the Type Cast function (in the Advanced/Data Manipulation subpalette) then back to a double array. I have added this method in the attached vi. Just see in the case structure...

Chilly Charly    (aka CC)
0 Kudos
Message 9 of 20
(4,826 Views)
CC,

I´m not a "master" on LV...because this I need your help. Returning to my own mistake on test simulation.vi, when I run this program and  jumped Tx and Rx (a loop back) on RS-232 cable my program works very well (look the frequency measure and the waveform). But, when I try to communicate with other computer this message subject error apears (because the receiver don´t received the signal, I´m think it, it´s right?!). I believe you, but I don´t understand because this program work well on "loopback test" and don´t work between computers (synchronization problem). Please, send me your last program on LV 7.0 (my version), if possible!

Thanxs
0 Kudos
Message 10 of 20
(4,810 Views)