PORTS Forum
Ports and Interfaces => Serial Ports => Topic started by: GlennP 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
-
This discussion might be helpful:
http://www.lvr.com/forum/index.php?topic=683.0
Jan
-
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
-
What is the problem with ReadExisting?
Jan
-
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
-
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