02-24-2017 12:11 AM
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
02-24-2017 07:15 AM
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.
02-26-2017 10:53 PM
Thanks Crossrulz, i will try to implement the concept and will let you know if i face any difficulties.
03-02-2017 01:59 AM
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
03-02-2017 04:07 AM
Also, it is not writing to the third port. Pls correct me where i have gone wrong.
03-02-2017 04:12 AM
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?
03-02-2017 06:11 AM
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
03-02-2017 08:14 AM
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).
03-02-2017 09:44 AM - edited 03-02-2017 09:45 AM
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
03-02-2017 10:15 AM
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.