LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem in reading data from serial port continuously- application hangs after sometimes

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.

--------------------------------------------------------------------------------------------------------
Kudos are always welcome if you got solution to some extent.

I need my difficulties because they are necessary to enjoy my success.
--Ranjeet
0 Kudos
Message 1 of 60
(6,285 Views)

@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.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 2 of 60
(6,237 Views)

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

 

To err is human, but to really foul it up requires a computer.
The optimist believes we are in the best of all possible worlds - the pessimist fears this is true.
Profanity is the one language all programmers know best.
An expert is someone who has made all the possible mistakes.

To learn something about LabVIEW at no extra cost, work the online LabVIEW tutorial(s):

LabVIEW Unit 1 - Getting Started</ a>
Learn to Use LabVIEW with MyDAQ</ a>
0 Kudos
Message 3 of 60
(6,224 Views)

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

0 Kudos
Message 4 of 60
(6,200 Views)

@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.

--------------------------------------------------------------------------------------------------------
Kudos are always welcome if you got solution to some extent.

I need my difficulties because they are necessary to enjoy my success.
--Ranjeet
0 Kudos
Message 5 of 60
(6,191 Views)

 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

--------------------------------------------------------------------------------------------------------
Kudos are always welcome if you got solution to some extent.

I need my difficulties because they are necessary to enjoy my success.
--Ranjeet
0 Kudos
Message 6 of 60
(6,188 Views)

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?

 

 

--------------------------------------------------------------------------------------------------------
Kudos are always welcome if you got solution to some extent.

I need my difficulties because they are necessary to enjoy my success.
--Ranjeet
0 Kudos
Message 7 of 60
(6,180 Views)

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

--------------------------------------------------------------------------------------------------------
Kudos are always welcome if you got solution to some extent.

I need my difficulties because they are necessary to enjoy my success.
--Ranjeet
0 Kudos
Message 8 of 60
(6,172 Views)

Will making both timeout same makes any differences?

--------------------------------------------------------------------------------------------------------
Kudos are always welcome if you got solution to some extent.

I need my difficulties because they are necessary to enjoy my success.
--Ranjeet
0 Kudos
Message 9 of 60
(6,149 Views)

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.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 10 of 60
(6,140 Views)