LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Multi signals acquisition from the same serial port

Hello,

I'm doing a program so I can acquire 3 signals from an acquisition card by a serial port. With VISA I write a command " c01" to receive the signal with read VISA. I did it for one signal and It works. But for multiple signals, I found a way that is not very good. Because I can see a lot of spikes in the graph.

 

"c01" send this command to acquire signal from channel 1

"c02"  send this command to acquire signal from channel 2

"c03"  send this command to acquire signal from channnel 3

but the graphs are not correct.

here is attached the program i made.

0 Kudos
Message 1 of 26
(2,970 Views)

Why are you using Bytes at Port in your communication scheme?

 

You are writing your command, then immediately checking Bytes at Port then reading that many.  Guess what?  You didn't give the device any time to return a response!

 

DON'T USE BYTES AT PORT!

 

What does a normal response look like?  Does it end in a termination character like a carriage return or linefeed?  Your VISA configure is setup to use a termination character as a linefeed.  If the response ends with a termination character, use it.

 

Get rid of Bytes at Port and make your VISA Read a large number of bytes, larger than the longest message you ever expect to receive.

0 Kudos
Message 2 of 26
(2,965 Views)

I am receiving a string of 3 bytes in ASCII code. but I only need the first 2 bytes which are a voltage value between

0 and 4095 mV 

instead of using "bytes at port" do I create a constant where I put the number of bytes.

 

In the end, I acquire an ECG signal with an amplitude of a few millivolts. I visualize three signals in parallel to observe it simultaneously. the Signals are not identical.

 

 

0 Kudos
Message 3 of 26
(2,943 Views)

@sam2017 wrote:

instead of using "bytes at port" do I create a constant where I put the number of bytes.


Yep.  I tend to use 50 or 100.  I would not set it to be 3 since that is how many bytes are supposedly in your message.  Considering an ASCII message format, that length could change on you.  So set it to be much larger to cover your bases.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 4 of 26
(2,928 Views)

@RavensFan wrote:

DON'T USE BYTES AT PORT!


Why aren't you emphasizing this? Smiley Wink


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 5 of 26
(2,926 Views)

@crossrulz wrote:

@RavensFan wrote:

DON'T USE BYTES AT PORT!


Why aren't you emphasizing this? Smiley Wink


Larger font and in red?  I figured that'd be overkill.  Smiley Very Happy

0 Kudos
Message 6 of 26
(2,922 Views)

I did it but it is getting worse. At first, I can receive the signals and visualize them in the graph even spikes. But now, it only acquires the data of the first command without showing any graphs. 

 

0 Kudos
Message 7 of 26
(2,900 Views)

I fixed the issue. I just needed to put the exact number of bytes "3". Because when I put a random number like 50 or 100 the read visa shows an error and it becomes very slow. so putting more bytes then you need can generate errors and slow the program.

 

When I put the right numbers of bytes it works great without spikes and very fast so I just added a "wait".

 

Thank you very much.

Best regards.

0 Kudos
Message 8 of 26
(2,899 Views)

Hi sam,

 

I just needed to put the exact number of bytes "3".

You just need to follow the exact message format specs of your device! Setting the right TermChar might be much easier…

 

You read 3 bytes and convert the string to an array of bytes. Then you convert that array to a cluster of 9 elements (!?) to use Unbundle: why don't you just IndexArray the array elements? Much easier, simple, self-documenting, …

Why do you need to flush the VISA buffer?

Why do you need a sequence structure?

Why don't you use AutoCleanup?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 9 of 26
(2,896 Views)

You read 3 bytes and convert the string to an array of bytes. Then you convert that array to a cluster of 9 elements (!?) to use Unbundle: why don't you just IndexArray the array elements? Much easier, simple, self-documenting, …

=> Because I receive the data on ASCII format. So I convert it into bytes array to only use the first two bytes and convert it to decimal to read the voltage value.

 

Why do you need to flush the VISA buffer?

=> So I empty it for the next commands 

Why do you need a sequence structure?

=>  to write the commands and read the signals respectively.

But I figure out that  I receive the same signal in the three graphs. So If you have a solution to read the three signals simultaneously it will help me a lot. 

Why don't you use AutoCleanup?

=> I don't know it, thank you for mention it. Is that a subVI ? i will try it

0 Kudos
Message 10 of 26
(2,900 Views)