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

Hi,

 

I am trying to write a vi which can read serial data from 2 com ports and write to the single port one by one.

For example:  Read VISA 1 o/p--- > 1 string 

                       Read VISA 2 o/p--- > 1 string

 

How can i write the 2 strings of serial data one by one @ single port with the help of Write VISA?

 

Thanks

 

 

0 Kudos
Message 1 of 38
(4,034 Views)

Quickly thinking, you will want 3 loop: one for each read port and another for the write port.  You can use a queue to have each of the read loops send data the write loop.  The write loop will dequeue one element at a time and write the string.  You can have a look at Producer/Consumer to get some ideas.


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 2 of 38
(3,999 Views)

Thanks Crossrulz, i will try to implement the concept and will let you know if i face any difficulties.

0 Kudos
Message 3 of 38
(3,982 Views)

Hi Crossrulz,

 

I have attached the vi, pls review and let me know where i am getting wrong.

 

1st read loop -- 

Error -1073807360 occurred at Property Node (arg 1) in VISA Configure Serial Port (Instr).vi->simulator_sample.vi

Possible reason(s):

VISA: (Hex 0xBFFF0000) Unknown system error (miscellaneous error).

 

2nd read loop - Error -1073807339 occurred at VISA Read in simulator_sample.vi

 

 

Thanks

Aniket

0 Kudos
Message 4 of 38
(3,965 Views)

Also, it is not writing to the third port. Pls correct me where i have gone wrong.

0 Kudos
Message 5 of 38
(3,960 Views)

I hope you have other settings in reality than in the vi. All three ports point to com1.

But also what if no message is received? in the two upper loops.

You should realize that a timeout is not forever but defaults to 10 seconds.

And how should loop 3 know where to leave the data?

greetings from the Netherlands
0 Kudos
Message 6 of 38
(3,957 Views)

Hi Albert,

In loop 3 i am using Write VISA function to the port, so i guess there shouldn't be any problem  now, also i can write the data to the third port but the problem is inconsistency:

 

 

Observed:

16:55:16.955: Rx: 0D 0A 41 42 43 0A 0D
16:55:16.963: Rx: 0D
16:55:17.858: Rx: 0D 0A 41 42 43 0A 0D
16:55:17.868: Rx: 0D
16:55:18.858: Rx: 0D 0A 41 42 43 0A 0D
16:55:18.866: Rx: 0D

Expected is 

16:55:16.955: Rx: 0D 0A 41 42 43 0A 0D
16:55:17.858: Rx: 0D 0A 41 42 43 0A 0D
 

If there is a way to write the data to the 3rd port as smooth as "Expected one" pls let me know.

 

Thanks

Aniket

0 Kudos
Message 7 of 38
(3,952 Views)

If no data is coming into the serial ports, then you will get a timeout.  When the timeout happens, you are sending an empty string to the loop that writes the data.  What is the best way to avoid this?  In my opinion, it is to handle your serial ports correctly in the first place.

 

So it sounds like your data is coming in at very irregular intervals (data is sent to you at random times).  In this case, I recommend using the Bytes At Port to see if any data is available to read.  If there is, read the data.  If there is no data, wait and check again on the next iteration of the loop.  The following code is from another thread (here).  For you, your Enqueue Elements should be inside the case structure with the VISA Read.  And the "0" case just has a wait (I think 50ms).


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 8 of 38
(3,947 Views)

Hi Crossrulz,

 

I have used the "bytes at port" function and can successfully write to the 3rd port but the data i am writing is not consistence. For example:

 

Read port 1 - Tx: OD OA 41 42 43 OA OD

Read port 2 - Tx: OD OA 43 44 45 OA OD

 

Write port 3 - Rx: OD OA 43 44 45 OA OD

                      Rx: OD

                      Rx: OD OA 41 42 43 OA OD

                      Rx: OD OA 43 44 45 OA OD

                      Rx: OD

 

But i want the data to be written as 

                      

                      Rx: OD OA 43 44 45 OA OD

                      Rx: OD OA 41 42 43 OA OD

                      Rx: OD OA 43 44 45 OA OD

 

 

Is it something related to "termination character" usage, should i enable the termination and if yes, the how to use it.

 

Thanks

Aniket

0 Kudos
Message 9 of 38
(3,941 Views)

You are already using the termination characters.  0D is the Carriage Return while 0A is the Line Feed.  If you are looking to remove the additional 0D character, add a check for the first 2 characters of the string to begin 0D 0A.  If it starts with something else like 0D 0D, then drop the first character.  It will then keep the 0D and wait for the 0A to continue building the string line.

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