Ports
May 23, 2013, 05:56:48 pm *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: SMF - Just Installed!
 
   Home   Help Search Login Register  
Welcome to the PORTS Forum. Please post your questions, answers, and comments relating to USB and other hardware interfaces in the appropriate forums below. - Jan
Pages: [1]
  Print  
Author Topic: Need a method of reading data \r &'>'  (Read 1552 times)
GlennP
Frequent Contributor
****
Posts: 126


« on: February 29, 2012, 10:28:50 am »

Hi All,

I have been struggling with ReadExisting() I think now in need a ReadTo() as I the ReadLine() will not work as certain parts of the code spit back  \r\r 's, and other parts returned \n\r, ReadExisting() will read everything back but with problems.  I have looked at using the Read method but this has problems as the data can be variable lengths.

Any advice, help or good wishes gratefully received!
Glenn

Logged
Jan Axelson
Administrator
Frequent Contributor
*****
Posts: 1629


WWW
« Reply #1 on: February 29, 2012, 10:56:18 am »

This discussion might be helpful:

http://www.lvr.com/forum/index.php?topic=683.0

Jan
Logged
GlennP
Frequent Contributor
****
Posts: 126


« Reply #2 on: February 29, 2012, 11:28:58 am »

Hmm,
Not really, I think the answer is in the ReadTo() method. As both old and new give out ">", its just the older gives out two separated by a '\r'.  I have tried the ReadLine() and again this works with the new code I just hangs with the older   
Logged
Jan Axelson
Administrator
Frequent Contributor
*****
Posts: 1629


WWW
« Reply #3 on: February 29, 2012, 11:45:41 am »

What is the problem with ReadExisting?

Jan
Logged
GlennP
Frequent Contributor
****
Posts: 126


« Reply #4 on: February 29, 2012, 12:18:33 pm »

It appears to loose data or a better way of putting it some data is being missed below is an output where it appears to have gone wrong:

                                     00000041077156 >UD:0002=H2000941135400486160027165 >
                                     UD:0003=H2000941133101713460027142 >
                                     UD:0004=H2108200619700000041071171 >
                                     UD:0005=H2207312751800000041075161 >
                                     UD:0006=H10006737610000247001159 >
                                     UD:0007=H10006724650001218129160 >
                                     UD:0008=H10006737270999999130136 >

A second run gives

                                     UD:0001=H2108200619700000041071172 >
                                     UD:0002=H2000950463700045160077162 >
                                     UD:0003=H2207315026200000041077154 >
                                     UD:0004=H10006737270999999130149 >
                                     UD:0005=H10006724650001218129174 >
                                     135400486160027158 >UD:0007=H2000941133101713460027157 >
a third gives
                                     1800000041075151 >UD:0002=H10006737610000247001145 >
                                     UD:0003=H2000950463700045160077148 >

                                     >UD:0005=H10006737270999999130151 >
                                     UD:0006=H10006724650001218129172 >
                                     UD:0007=H2108200619700000041071100 >
                                     UD:0008=H2000941133101713460027144 >
a forth gives
                                    UD:0001=H10006737610000247001167 >
                                    UD:0002=H2000841167000379260077192 >
                                    UD:0003=H2000941135400486160027170 >
                                    UD:0004=H2000941133101713460027145 >

                                    >UD:0006=H10006724650001218129153 >
                                    UD:0007=H2108200619700000041071172 >

a fifth give                     UD:0001=H2000950463700045160077139 >
                                   UD:0002=H2207315026200000041077153 >
                                   UD:0003=H10006737270999999130147 >
                                   UD:0004=H2000941135400486160027163 >
                                   UD:0005=H2000941133101713460027143 >
                                   UD:0006=H2207312751800000041075164 >
                                   UD:0007=H2207309137000000041077160 >
So on the whole not very reliable there are not always the same amount of data as this is an RF based system. All data should start with a UD: and end with a >

Glenn
Logged
GlennP
Frequent Contributor
****
Posts: 126


« Reply #5 on: March 01, 2012, 07:50:07 am »

Much Coffee and nights sleep yield this method it seems to work :
  private void port_DataReceived_1(object sender, SerialDataReceivedEventArgs e)
        {

            InputData = myComPort.ReadExisting();
            InputBuffer += InputData;
            if (InputData.Contains(">"))
            {
                Data_From_PitStop = InputBuffer;
                Reply_Status = (int)REPLY.YES_REPLY;
                InputBuffer = "";
            }



This appears to work! but further tests are on going.

Glenn
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!