Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

serial data missing in multiple port operation

Solved!
Go to solution

Hello.

My unit is transferring 51 bytes of asynchronous data in frames(each frame at 80ms) on six different channels (ch1,ch2,ch3,ch4 of baud rate-19200 and other two ch5,ch6 of baud rate 115200) and these six diff serial data is received by my system and it has to be checked for any byte error...(as i'm new to labview I've programmed a lengthy vi) in which I use visa read and process the received data... But now my real issue starts... upto certain time my system 'll be receiving data without any loss but aftr some time(say around 15mins) the data loss starts from the channel having baud rate of 115200 and later other channels start acting same...But my system is expected to run for 4hours for an endurance test of an aircraft... If the data loss is very less in numbers then its OK but 3 out of 4 frames starts missing...that is like loosing 75% of data.... I 'm attaching a snap of my code..Its just for a single port(in a while loop) I've taken..Imagine I;ve done same thing to rest port in a single while loop.... Please guide me where ive gone wrong or is it anything to do with time delay....pls help me out

the thing is still my system application needs is gonna grow more so I've to rectify this in beginning itself

0 Kudos
Message 1 of 14
(3,945 Views)

There is no need to do the VISA Configure Serial Port with each iteration and doing a VISA Flush I/O Buffer makes no sense to me. You are waiting 30 msec, discarding all data and then waiting to read the 51 bytes. Try it with just a VISA Read inside the loop. 

0 Kudos
Message 2 of 14
(3,934 Views)

Thanks...yes I tried only visa read inside the loop..For 20 mins ther was no issue...but after that data started missing...even though I was receiving 51 bytes data frame header and footer had changed their positions...Then I aborted and rerun the program immediately and observed and same thing occurred after 20mins.. Y is this happening?

0 Kudos
Message 3 of 14
(3,916 Views)

You have disabled the termination character and yet you are using a fixed byte count for a read. Are you sure there aren't more than 51 bytes being sent? Have you tried using the VISA Bytes at Serial Port to tell you exactly how many bytes are available?

0 Kudos
Message 4 of 14
(3,906 Views)

Yeah I'm sure that 51 bytes of data in a frame/80ms is sent per channel..In that header is hex"55" and footer is hex"CC" ,penultimate bit is check-sum(that is XOR'ed result from 1st to 48th bit). And I admit that I have no proper idea abt the termination character function. So ,is the issue bcoz of termination character? I'm starter to this lv programming.. pls help me clear this... Can u show me an example for my requirements where out of 6 ports 2 COM ports 'll have baud rate at 115200kb/s and 4 COM ports 'll 've baud rate at 19200kb/s... Its jus simple that the unit is sending 51byte data frame at 80ms in all 6 channels... And my PC has to just receive dese data for a quite long time and display them & 've to be written to a txt file... I've given responsibility to accomplish dis..But I'm stuck up in the data receiving part and unable to proceed to next step.. I'll try out the method u suggest..Data processing part I've completed..Only long term data receiving is unsuccessful.. 

0 Kudos
Message 5 of 14
(3,891 Views)

Yeah I'm sure that 51 bytes of data in a frame/80ms is sent per channel..In that header is hex"55" and footer is hex"CC" ,penultimate bit is check-sum(that is XOR'ed result from 1st to 48th bit). And I admit that I have no proper idea abt the termination character function. So ,is the issue bcoz of termination character? I'm starter to this lv programming.. pls help me clear this... Can u show me an example for my requirements where out of 6 ports 2 COM ports 'll have baud rate at 115200kb/s and 4 COM ports 'll 've baud rate at 19200kb/s... Its jus simple that the unit is sending 51byte data frame at 80ms in all 6 channels... And my PC has to just receive dese data for a quite long time and display them & 've to be written to a txt file... I've given responsibility to accomplish dis..But I'm stuck up in the data receiving part and unable to proceed to next step.. I'll try out the method u suggest..Data processing part I've completed..Only long term data receiving is unsuccessful.. 

0 Kudos
Message 6 of 14
(3,891 Views)

Often it is better to separate the Reads from the interpretation of the data, especially when timing is critical. With all that conversion code and all the indicators in the loop things may slow down due to the OS writing to the screen.  Look at the Producer/Consumer Design Patterns which come with LV for ideas about how to separate the reads from the interpretation.

 

Termination characters are caracters sent at the end of each frame, often a line feed or carriage return.  If hex CC is guaranteed to never occur in the data, then CC may be used as the termination character.  When using a termination character you set the bytes to read to a large number (in your case I would use some thing larger than two frames, perhaps 120 or 200). The Read automacially stops when the termination character is found in the data stream.  The first time through the loop you may get a short frame or extra characters but after that it should give you one complet frame for each read.

 

If I interpretted your description properly, you are receiving less than 4000 bytes per second.  That should not be a problem.  Are your COM ports on the mother board of your computer, on PCI cards, or on USB adapters?  The problem my be with the way the OS interacts with the port drivers.

 

Lynn

Message 7 of 14
(3,888 Views)

Thanks lynn..my COM ports are on pxi card... NI PXI 1042Q.. one more thing i have to mention... along with this receiving operation i'm also sending commands to 3 channels out of 6 and also controlling lambda power supply and load thru serial communication in a single program... so will all these contribute for system slow? or have i made my code complex..? my seniors requirement is to run everything at a single click.. am i messing up the code or something?

0 Kudos
Message 8 of 14
(3,881 Views)

The PXI-1042 is a chassis.  The modules you plug into it do the work. I suppose you may have something like the PXI-8430/8 module in the chassis.

 

The data rates you are using should not be a problem. My guess is that your program architecture causes the program to slow down or one part of the program may be blocking other parts from running.

 

With multiple instruments communicating simultaneously but asynchronously, you need to be careful in the design of the program to make sure that all communications ahre handled promptly.

 

Since this is a school project, it is important for you to learn how to do these things for yourself.

 

I presumed that you are using LabVIEW for the programming, but you did not say that.  Is this correct?

 

Handling multiple instruments is not a trivial task. Prepare a design specification (if you have not already done so) which clearly indicates what communications tasks are required for each instrument. It must also specify what data (including commands) are sent to each instrument and the source of that data. Similarly specify the data received from each instrument and where it goes and what will be done with it. What inputs does the user provide? What information is displayed to the user? What information goes to files? When you have these specifications, then you can begin to select appropriate architectures for your program.

 

Anything which will be done multiple times or places in your program (such as serial port communications) should be made into subVIs.  Make sure there is no data dependency between any subVIs which may need to run in parallel.

 

Lynn

0 Kudos
Message 9 of 14
(3,870 Views)

I apologies if I have not conveyed my message properly... Yes Lynn you're right I'm performing serial operation using pxi 8432/8 module on pxi chassis... By the way this is not a school project what u presumed is right... Based on above comments and suggestion I tried serial communication using only single channel as a experiment and there was progress Upton some extent as the system was receiving data Upton 50 mins continuously, but I had used hex C as termination char., so whenever hex C appeared in any other position other than footer,I'm loosing data frame.It happens for every 200 read,can this be solved...?After 50th minute program hangs and forcibly I've to end whole labview program:(  And I'm running power supply control program and serial communication program in separate vi window simultaneously... 

0 Kudos
Message 10 of 14
(3,844 Views)
0 Kudos
Message 11 of 14
(950 Views)
Solution
Accepted by topic author rg.naveen

I started to reply earlier but the Forums were shut down for maintenance.

 

I prefer to keep the discussions here so that others may benefit from anything learned.

 

Your block diagram is huge! The style guides recommend keeping the size of the diagram to one screen.  This makes it much easier to see what the program is doing.

 

If your devices are not sending a termination character, disable the termination character in the configuration VI.  Then just read the number of bytes being sent.  Iy looks like your data starts with 55 and ends with CC.  If CC is never allowed to occur in the data, use CC as the termination character.  If you run without termination character, you will need to identify the frames as 51 character strings starting with 55 and ending with CC.  Because your reads may not be synchronized with the frames, you need to do some extra buffering with a shift register.

 

The main problem you have is that you are building arrays in a while loop.  Because LabVIEW does not know in advance how many iterations the loop will run, it cannot pre-allocate memory for the arrays.  As the arrays grow new space must be allocated.  Arrays are stored in contiguous memory locations. After numerous allocations the memory may be sufficiently fragmented that it is no longer possible to allocate a new space big enough for the relay.  At that point the program will fail.  It should throw an error, but crashes are possible.

 

Although it has nothing to do with the program hanging, why are you wiring True constants to dozens of Selector functions? Perhaps this was something you simplified for the tests?

 

It appears that a few of the bytes in each frame are not used and at least one was used twice.

 

Lynn

Message 12 of 14
(932 Views)

THANK YOU SO MUCH..See you were right building arrays was the main issue which was against my expectation of result.... As per our solution I removed all array building functions in my code and have made it to write directly to the harddisk as a text file, and the continuous receiving data is just monitored by the sub vi which I've made and a string display to monitor the frame received at that moment. as an experiment , I operated on two channels with out building any array inside the loop and my program executed for bat 3Hrs with out any signs of obstacles...And lynn as I'm new to lab view I have made this code very huge I guess,I myself notice that..Can u suggest where else I can still make it simplifier (if needed)And the purpose I have use true select function is because that byte will have value either FFor 0F so I had planned that way n designed.. Is that a wrong way to do? I accept and learn wat you suggest..Thank you

 

 

naveen

0 Kudos
Message 13 of 14
(920 Views)

Instead of using all of those separate Index Array functions, use one and drag it down. No need to wire inputs. The first output is index 0, second output is index 1, etc.

 

Your logic is flawed. If in fact the byte can be just one or another, a single equal comparison wired directly to the Boolean indicator is enough.

 

p.s. I don't think your checksum VI is at all correct.

Message 14 of 14
(915 Views)