01-15-2019 08:12 AM
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.
01-15-2019 08:22 AM
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.
01-15-2019 09:13 AM
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.
01-15-2019 11:19 AM
@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.
01-15-2019 11:21 AM
@RavensFan wrote:
DON'T USE BYTES AT PORT!
Why aren't you emphasizing this?
01-15-2019 11:56 AM
@crossrulz wrote:
@RavensFan wrote:
DON'T USE BYTES AT PORT!
Why aren't you emphasizing this?
Larger font and in red? I figured that'd be overkill.
01-16-2019 03:50 AM
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.
01-16-2019 04:01 AM
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.
01-16-2019 04:36 AM - edited 01-16-2019 04:37 AM
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?
01-16-2019 05:13 AM
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