03-18-2014 05:56 AM
I need to read data from two COM port and order of data appearance from COM port is not fixed.
I have used small timeout and reading data in while loop continously . If my application is steady for sometime it gets hangs and afterwards it doesnt receive any data again.
Then I need to restart my application again to make it work.
I am attaching VI. Let me know any issue.
03-18-2014 09:44 AM - edited 03-18-2014 09:47 AM
@Ranjeet_Singh wrote:
I need to read data from two COM port and order of data appearance from COM port is not fixed.
I have used small timeout and reading data in while loop continously . If my application is steady for sometime it gets hangs and afterwards it doesnt receive any data again.
Then I need to restart my application again to make it work.
I am attaching VI. Let me know any issue.
What do you mean, "not fixed?" If there is no termination character, no start/stop character(s) or even a consistent data length, then how can you really be sure when the data starts and stops?
I probably misunderstood you though. Assuming the last case is not ture - there is a certain length to the data - then you should use the bytes at port, like in the otherwise disastrous serial port read example. In this case, it's NOT disastrous. You have to make sure that you read all the data that came through. Right now you have no idea how much data you just read. Also, if this is streaming data, you might want to break it out into a producer/consumer design pattern.
03-18-2014 11:15 AM
Ranjeet,
The way the VI is written you need to get one set of data from both VISA inputs in order for the loop to make another pass. So, if only one of the VISA inputs stalls, you're dead in the water. Are you sure that the problem isn't from one of your inputs, not this program?
You also haven't put any timing in the loop at all, so it sucks up all the CPU cycles it can and maybe that causes it to miss one byte from one of your inputs (die) - put at least a 1 msec wait in the loop. I've found that when you leave out all timing in the loop, anything can happen, especially anything bad.
Cameron
03-18-2014 08:33 PM
The VISA Reads serve as timing/waits so this is not a greedy loop.
Two loops might be better. 1. With different timeouts one channel always runs the risk of missing some data. 2. You should check the error out for timeout errors and for overflow errors. Handling the errors appropriately will eliminate false or misleading data and might help reduce the hanging problem. 3. Three loops might be needed. The database code could take a long time if the database is offline or responds slowly. I do not have the database subVIs so I have no idea whether they contain timeouts. You certainly are not handling any errors from them.
Lynn
03-18-2014 09:46 PM
@billko wrote:
@Ranjeet_Singh wrote:
I need to read data from two COM port and order of data appearance from COM port is not fixed.
I have used small timeout and reading data in while loop continously . If my application is steady for sometime it gets hangs and afterwards it doesnt receive any data again.
Then I need to restart my application again to make it work.
I am attaching VI. Let me know any issue.
What do you mean, "not fixed?" If there is no termination character, no start/stop character(s) or even a consistent data length, then how can you really be sure when the data starts and stops?
I probably misunderstood you though. Assuming the last case is not ture - there is a certain length to the data - then you should use the bytes at port, like in the otherwise disastrous serial port read example. In this case, it's NOT disastrous. You have to make sure that you read all the data that came through. Right now you have no idea how much data you just read. Also, if this is streaming data, you might want to break it out into a producer/consumer design pattern.
Not fixed means order is not fixed, data from any com port can come anytime. lenght is fixed, one com port have 14 byte and other 8 byte fixed..
Reading data is not an issue for me as it works nice but I have a query that why my application hangs after sometime and stops reading data from COM PORT.
03-18-2014 09:52 PM - edited 03-18-2014 10:13 PM
Hi Cameron
I am sure there is absolutely no problem in input side.
I thought there is not timing needed as I am waiting for max 800ms to read data so that is sufficient as I thought.
My problem here is my application hangs after sometime. Do you think this is only becasuse I havent used any timings. But I am already waiting for 600 and 800ms then only I am looping again.
what is the meaning of this -'when you leave out all timing in the loop, anything can happen, especially anything bad.' Can you please elobrate
03-18-2014 10:10 PM - edited 03-18-2014 10:14 PM
Hi lynn
I have used one loop becasue I need to corelate data from two ports and inside one loop I have used case structure for all testing and corelating the datas. I am sure there is no problem with database.
1. there is no data missing untill application hangs after sometime and this 'sometime' is also not fixed.
2. I am taking care of as there is no problem in handling the data.
3. There is no problem with database that I am sure for.
IF MY APPLICATION STEADY FOR SOMETIME THEN IT HANGS AND ONLY OPTION I HAVE IS TO RESTART THE APPLICATION. Why this happening?
03-18-2014 10:22 PM - edited 03-18-2014 10:24 PM
This is basically weight serial number linking application..
1st COM port - Serial number
2ndCOM port - Weight
When I get valid weight then I store the value and keep monitoring for serial number, if serial number read then I will link and write to database or otherwise if I read weight again then I will update the weight value then monitor for serial number.
This is what my application
03-19-2014 01:35 AM - edited 03-19-2014 01:35 AM
Will making both timeout same makes any differences?
03-19-2014 03:15 AM
I think two producer loops would be better because the way you have it, the loop would have to wait for the slowest read to happen before it can continue. With two producer loops you can still correlate them in the consumer loop.
You are trying to force timed reads when it cannot be done. The data gets there when it gets there.