 crossrulz
		
			crossrulz
		
		
		 
		
		
		
		
		
	
			03-02-2017 10:17 AM
Ok, time to take a step back. Please describe in detail the protocol of the message you are trying to read and then pass on. Is it binary data or ASCII? Does it use a termination character? Do you have any control on the protocol used?
03-02-2017 10:57 AM
The message protocol is a simple serial data generated by external HW from 2 ports, so my job is to create a simulator which will read the data from those 2 ports and output/write to 3rd HW (single port) one by one.
Now data which is being sent by ext HW continously is like :port 1 : 0D 0A 41 42 43 0A 0D
port 2 : 0D 0A 44 45 46 0A 0D
And port 3 where i have to write the data one by one continously and which is received by port1 & port 2 is like
0D 0A 41 42 43 0A 0D
0D 0A 44 45 46 0A 0D
0D 0A 41 42 43 0A 0D
0D 0A 44 45 46 0A 0D
0D 0A 41 42 43 0A 0D
0D 0A 44 45 46 0A 0D ........ so on
Termination character are 0A & 0D, so i guess this uses termination character.
Sorry I dont understand what does it mean by protocol control.
Pls let me know if you need more info.
Thanks
Aniket
 crossrulz
		
			crossrulz
		
		
		 
		
		
		
		
		
	
			03-02-2017 12:12 PM
@aniketjha wrote:
Sorry I dont understand what does it mean by protocol control.
That was a question of whether or not you had input to what the message format is. Right now it is kind of weird or a serial protocol. They typically do not start and end with the same termination characters. What I am getting at is it would make life a lot easier if you could get those first two bytes removed. From there, I am assuming you are only dealing with ASCII data, so then the termination character is exactly what you want to use (set to 0xD since that is the last byte in the message). If you can manage that, then you just read a line with VISA Read by letting the Termination Character stop the read and you just send the data through the queue when you get data.
But if that is not the case, then it will be a little more interesting to get a single message out. You would need a State Machine of sorts to process the data and then pass it on when you get the full message. States would include reading a single byte looking for the first byte (0D), read a byte and verify it is 0A, and set the termination character to TRUE and read the rest of the message. If a step fails, back to the first.
03-03-2017 05:03 AM
Hi,
The data which is being sent on serial port is devoid of termination characters, so there is no use of applying termination character. I have done everything but the message i am receiving is all messed up such as below:
16:26:55.955: Rx: 0D 0A 31 32 33 0A 0D 0A 
16:26:55.975: Rx: 0A 
16:26:56.952: Rx: 0D 0A 31 32 33 0A 0D 0A 
16:26:56.973: Rx: 0A 
16:26:57.949: Rx: 0D 0A 31 32 33 0A 0D 
16:26:57.969: Rx: 0D 0A 
16:26:57.984: Rx: 0A 
16:26:58.948: Rx: 0D 0A 31 32 33 0A 0D 
16:26:58.968: Rx: 0D 0A 
16:26:58.980: Rx: 0A 
16:26:59.966: Rx: 0D 0A 31 32 33 0A 0D 
16:26:59.981: Rx: 0D 0A 
16:27:00.001: Rx: 0A
I dont know why and from where extra 0A 0A appears.
Pls see my attached vi.
 Albert.Geven
		
			Albert.Geven
		
		
		 
		
		
		
		
		
	
			03-03-2017 09:57 AM
Hi
In the upper loop you are reading 7 characters.
In the second loop you are reading the number of characters available maybe less or more than 7
In the lower loop you are writing all you read.
I don't think that what you type is what you received and sended.
Can you add indicators in what you receive (both loops separate indicators), the same way as in the lower loop and after running the vi goto edit/make current values default and send that vi again.
03-04-2017 10:45 AM
More than 90% i successfully read the data from 2 ports and forwarded to the single port one by one but still i see the data are missing such as below:
19:12:23.510: Rx: 43 44 45 
19:12:23.689: Rx: 31 32 33 
19:12:24.447: Rx: 43 44 45 
19:12:24.625: Rx: 31 32 33 
19:12:25.404: Rx: 43 44 45 
19:12:25.538: Rx: 31 32 33 
19:12:26.498: Rx: 31 32 33 
19:12:27.414: Rx: 31 32 33 
19:12:28.369: Rx: 31 32 33 
19:12:29.315: Rx: 31 32 33 
19:12:30.221: Rx: 31 32 33 
19:12:31.154: Rx: 31 32 33 
19:12:32.108: Rx: 31 32 33 
19:12:33.047: Rx: 31 32 33 
19:12:33.962: Rx: 31 32 33 
19:12:34.921: Rx: 31 32 33 
19:12:35.854: Rx: 31 32 33 
19:12:36.774: Rx: 31 32 33 
19:12:37.740: Rx: 31 32 33 
19:12:38.644: Rx: 31 32 33 
19:12:39.582: Rx: 31 32 33 
19:12:40.518: Rx: 31 32 33 
19:12:41.451: Rx: 31 32 33 
19:12:42.387: Rx: 31 32 33 
19:12:43.338: Rx: 31 32 33 
19:12:44.263: Rx: 31 32 33 
19:12:45.226: Rx: 31 32 33 
19:12:46.131: Rx: 31 32 33 
19:12:47.083: Rx: 31 32 33 
19:12:48.024: Rx: 31 32 33 
19:12:48.897: Rx: 31 33 
19:12:48.960: Rx: 33 
19:12:49.895: Rx: 31 32 33 
19:12:50.844: Rx: 31 32 33 
19:12:51.779: Rx: 31 32 33
Read from port 1: 0D 0A 31 32 33 0A 0D
Read from port 1: 0D 0A 43 44 45 0A 0D
write to single port:
19:12:23.510: Rx: 43 44 45 
19:12:23.689: Rx: 31 32 33 
19:12:24.447: Rx: 43 44 45 
19:12:24.625: Rx: 31 32 33 
19:12:25.404: Rx: 43 44 45
I trim the 0D 0A as those are CR & LF termination characters, so valid data are in the middle
Here is the attached vi.
Can you help me in correcting the vi how can i be 100% in receiving as well forwarding the data one by one with no miss or mixed data.
Also i tried the another vi (ni_forum_sample2) but it is not working.
 Albert.Geven
		
			Albert.Geven
		
		
		 
		
		
		
		
		
	
			03-04-2017 03:27 PM
Just guessing, you wait in sample 2 300 ms in the upper loop so mixing of parts of the message with loop 2 is quite possible.
That can give errors.
You should reread what crossrulz wrote about protocol.
You now read exactly the number of bytes that is detected but you know it always should be a fixed number! Or wait that number of bytes (calculate that from the baudrate) and read again the number of bytes!
But anyhow don't wait too long or too short.
03-06-2017 02:47 AM
Hi Albert,
In sample vi 1 whenever i read the data >4, tool throwing inconsistent behavior. For example:
It is writing to the single port as:
11:25:20.928: Rx: 43 44 45 46
11:25:21.867: Rx: 43 44 45 46
11:25:22.803: Rx: 46
11:25:23.739: Rx: 43 44 45 46
11:25:24.672: Rx: 46
11:25:25.607: Rx: 43 44 45 46 
11:25:26.544: Rx: 43 44 45 46
11:25:27.480: Rx: 46
Now i am facing the above issue. And yes the no. of bytes is not fixed.
Any help on the vi is most welcome.
Thanks
Aniket
 crossrulz
		
			crossrulz
		
		
		 
		
		
		
		
		
	
			03-06-2017 04:11 AM
@aniketjha wrote:
And yes the no. of bytes is not fixed.
Which brings me back to my question: what is the exact protocol of the messages? Something has to tell you how many bytes to read for a message. It could be a message ID, or a length byte, or a termination character.
 Minions
		
			Minions
		
		
		
		
		
		
		
		
	
			03-06-2017 07:31 AM
I threw this together. It could be used as your serial port input loops if duplicated for the other. It will only enqueue the data if the last character read is one of the termination characters and the data string length is >0. The enqueued data string does not contain the termination characters. You may need to adjust the wait time for when no characters are waiting at the port.