Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

Read data from 2 serial port and forwarding to single port

Needed to move the string build to the outside of the while loop to contain the string when the last character is not a termination character and the enqueued string length is > 0.

Help the Community (and future reviewers) by marking posts as follows:
If it helped - KUDOS
If it answers the issue - SOLUTION
0 Kudos
Message 21 of 38
(1,514 Views)

Hi Minions,

 

Thanks for the vi, it helped me to understand a bit but i need to read from the 2 ports.

So i can use the same vi for my 2nd port also, then dequeue  and write to the 3rd port.

 

Did you check the vi if it can able to write to other port and data consistency is maintained, i.e., no mixing or missing of the data, also continuously sending serial data from 1 port  and writing the data to other port.

 

Thanks

Aniket

0 Kudos
Message 22 of 38
(1,504 Views)

Here is a cleaned up version of what you should be trying.  Both Read loops will run until the stop is set.  Inside their main loop, they will build the string without termination characters.  Each time a termination character is received, it will send the string if it is > 0 characters.  Once the string is sent, it will clear that string and begin building another.  The write will also continue until the stop is set or there is an error during the dequeue process.  Before dequeue, it checks to see if there is anything in the queue, if not, it will wait

W wait (ms)

time in milliseconds before checking the queue again.

 

Help the Community (and future reviewers) by marking posts as follows:
If it helped - KUDOS
If it answers the issue - SOLUTION
0 Kudos
Message 23 of 38
(1,488 Views)

Thanks Minions, i will check and let you know the outcome

0 Kudos
Message 24 of 38
(1,480 Views)

Hi Minion,

 

As far as i understood, if there is no termination characters in data which i send then loop will run continuously and without writing to the port.

So i executed the vi you shared, my observation - vi trying to find the termination characters in the string and it continues to build the string. But what i am sending is without termination characters so vi won't work. 

 

I am also looking for vi which can write data to other port irrespective of termination characters.

 

Regards

Aniket

0 Kudos
Message 25 of 38
(1,477 Views)

Try re-enabling the termination characters in the read ports.  In your current configuration, you will get interleaved data if it simply forwards the data in to the output port.  How do you expect a program to know when the characters read from a port can be sent onto the output port without some sort of timeout or termination?

Help the Community (and future reviewers) by marking posts as follows:
If it helped - KUDOS
If it answers the issue - SOLUTION
0 Kudos
Message 26 of 38
(1,473 Views)

So i tried enabling the termination, but same result.

Also, radio data doesn't have the termination characters, so how to proceed then.

I successfully forwarded the data without any miss but it seems there is an issue with particular scenario - whenever my serial port is open and data is continuously received + my vi is stopped = after i start the vi, loads of data is transferred at one shot to the other port giving a very ugly picture. 

How to resolve the issue because there are data at port and since there is no way to transfer the data to other port other than vi, it will store somewhere in buffer and as soon as i start the vi, a big chunk of data getting transferred at one shot - not good. 

 

Thanks

Aniket

0 Kudos
Message 27 of 38
(1,464 Views)

You might try to use the

Visa Flush I/O Buffer

right after your port initialization and before entering your producer loops.  This should drop and clear any data awaiting on the port prior to the start of your vi.

 

Help the Community (and future reviewers) by marking posts as follows:
If it helped - KUDOS
If it answers the issue - SOLUTION
0 Kudos
Message 28 of 38
(1,439 Views)

Try this, I changed the delay function in your code to the metronome, it's provides much more reliable loop timing than the 'Wait ms'. In fact, don't ever use the Wait ms, unless you really understand why.

 

If that does not work, there is another technique of reading the chars from the port without a wait, that works when there is no termination character. It's involves a shift register.

 

Regards

Jack Hamilton

0 Kudos
Message 29 of 38
(1,428 Views)

Jack

did you ever have problems with the wait ms?

I always had with the metronome!

Especially in a parallele measuring system where all activities misteriously seem to happen all at he same time!

greetings from the Netherlands
0 Kudos
Message 30 of 38
(1,419 Views)