<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"><channel><category>pcsoft.us.windev</category><copyright>Copyright 2026, PC SOFT</copyright><lastBuildDate>6 Aug 2019 04:31:51 Z</lastBuildDate><pubDate>8 May 2019 22:19:26 Z</pubDate><description>Hello Everybody,&#13;
&#13;
I'm trying to read serial data that is comming from an Arduino over RS-232.&#13;
The Arduino is supposed to send data in a format like this :&#13;
 [PortNumber1];[Data1]; [PortNumber2];[Data2]; [PortNumber3];[Data3]; followed by a CR&#13;
In fact it's a comma delimited string that should be processed by my program.&#13;
My program isn't sending any data to the device, just reading. &#13;
So I wrote this code to initialize my com-port : &#13;
&#13;
[code:wl]&#13;
//initialize comPort&#13;
IF sOpen(gnComPort,128,128,2000,True) = True THEN&#13;
	IF sParameter(gnComPort,9600,0,8,1,False,False,False) = False THEN&#13;
		Error("Cannot initialize")&#13;
	ELSE&#13;
		sEvent(gnComPort,sEveCharReceived,Incoming2)&#13;
		&#13;
	END&#13;
ELSE&#13;
&#13;
	Error("Cannot initialize")&#13;
END&#13;
[/code]&#13;
&#13;
This part of the code is working fine (it should), but my problem is in the processing of the data that I'm receiving. &#13;
The data has no fixed lenght, and also, sometimes the string isn't perfectly according to the format.&#13;
As a first step I want to be able to have the incomming data processed into separate lines for every piece of data that ends with a CR+LF. But I can't get it working. This is my actual code : &#13;
&#13;
[code:wl]&#13;
PROCEDURE Incoming2(ComPort,EventNum)&#13;
nSize is int&#13;
bFlagOk is boolean&#13;
bFlagOne is boolean&#13;
nSize2 is int&#13;
sBuffer is string&#13;
nLengte is int&#13;
nWaarde is int&#13;
sKarakter is string&#13;
sTekstNieuw is string&#13;
sLijn is string&#13;
&#13;
//trace(sread(ComPort,sInEntryQueue(ComPort)))&#13;
&#13;
bFlagOk = False&#13;
bFlagOne = False&#13;
&#13;
// Read the information about the serial port according to the stop condition&#13;
nSize = sInEntryQueue(ComPort)&#13;
&#13;
IF nSize&lt;&gt;0 THEN&#13;
	WHILE NOT bFlagOk&#13;
		nSize = sInEntryQueue(ComPort)&#13;
		IF nSize &gt; nSize2 THEN&#13;
			nSize2 = nSize&#13;
			bFlagOne = False&#13;
		ELSE&#13;
			IF bFlagOne THEN&#13;
				bFlagOk = True&#13;
			ELSE&#13;
				bFlagOne = True&#13;
				//Multitask(10)&#13;
			END&#13;
		END&#13;
	END&#13;
	sBuffer = sRead(ComPort,nSize)&#13;
END&#13;
&#13;
IF bFlagOk THEN&#13;
	nLengte = Length(sBuffer)&#13;
	FOR nTeller = 1 TO nLengte&#13;
		sKarakter = Middle(sBuffer,nTeller,1)&#13;
		nWaarde =  Asc(sKarakter) &#13;
		IF nWaarde = 13 THEN&#13;
			Trace("CR")&#13;
			//end of line found, show data&#13;
			sLijn = Left(sBuffer,nTeller -2)&#13;
			Trace(sLijn)&#13;
			sLijn = ""		&#13;
		END&#13;
	END&#13;
&#13;
	Wait(10,waitTimer)&#13;
&#13;
END&#13;
[/code]&#13;
&#13;
this is what the device is send (log extracted from terraterm) : &#13;
&#13;
[code:text]&#13;
P1;blala;P2;@0RM0120122;P3;@0RM0090105&#13;
P1;@0RM0121047;P2;@0RM0008321;P3;(&#13;
P1;@0RM0001047;P2;@0RM0000321;P3;@0RM0231521&#13;
P1;blala;P2;@0RM0120122;P3;@0RM0090105&#13;
P1;@0RM0121047;P2;@0RM0008321;P3;(&#13;
P1;@0RM0001047;P2;@0RM0000321;P3;@0RM0231521&#13;
P1;blala;P2;@0RM0120122;P3;@0RM0090105&#13;
P1;@0RM0121047;P2;@0RM0008321;P3;(&#13;
P1;@0RM0001047;P2;@0RM0000321;P3;@0RM0231521&#13;
P1;blala;P2;@0RM0120122;P3;@0RM0090105&#13;
P1;@0RM0121047;P2;@0RM0008321;P3;(&#13;
P1;@0RM0001047;P2;@0RM0000321;P3;@0RM0231521&#13;
P1;blala;P2;@0RM0120122;P3;@0RM0090105&#13;
P1;@0RM0121047;P2;@0RM0008321;P3;(&#13;
P1;@0RM0001047;P2;@0RM0000321;P3;@0RM0231521&#13;
P1;blala;P2;@0RM0120122;P3;@0RM0090105&#13;
P1;@0RM0121047;P2;@0RM0008321;P3;(&#13;
P1;@0RM0001047;P2;@0RM0000321;P3;@0RM0231521&#13;
P1;blala;P2;@0RM0120122;P3;@0RM0090105&#13;
P1;@0RM0121047;P2;@0RM0008321;P3;(&#13;
P1;@0RM0001047;P2;@0RM0000321;P3;@0RM0231521&#13;
[/code]&#13;
&#13;
And this is what my code creates : &#13;
&#13;
[code:text]&#13;
1;@0RM0121047;P2;@0RM0008321;P3;(&lt;\r&gt;&lt;\n&gt;P1;@0RM0001047;P2;@0RM0000321;P3;@0RM023152&#13;
CR&#13;
1;blala;P2;@0RM0120122;P3;@0RM009010&#13;
CR&#13;
047;P2;@0RM0008321;P3;&#13;
CR&#13;
M0000321;P3;@0RM023152&#13;
CR&#13;
;@0RM009010&#13;
CR&#13;
;@0RM0090105&lt;\r&gt;&lt;\n&gt;P1;@0RM0121047;P2;@0RM0008321;P3;&#13;
CR&#13;
P1;@0RM0001047;P2;@0RM0000321;P3;@0RM023152&#13;
CR&#13;
P1;blala;P2;@0RM0120122;P3;@0RM009010&#13;
CR&#13;
;@0RM0121047;P2;@0RM0008321;P3;&#13;
CR&#13;
47;P2;@0RM0000321;P3;@0RM023152&#13;
CR&#13;
2;P3;@0RM009010&#13;
[/code]&#13;
&#13;
The "CR" is just tracecode to see when a CR is detected inside the buffer&#13;
&#13;
Any suggestions on how to get this working properly ? &#13;
&#13;
grtz&#13;
&#13;
Patrick</description><ttl>30</ttl><generator>WEBDEV</generator><language>en_US</language><link>https://forum.pcsoft.fr/es-ES/pcsoft.us.windev/67047-reading-com-port-with-sevent/read.awp</link><title>Reading Com-port with sEvent</title><managingEditor>moderateur@pcsoft.fr (El moderador)</managingEditor><webMaster>webmaster@pcsoft.fr (El webmaster)</webMaster><item><author>eafr21</author><category>pcsoft.us.windev</category><comments>https://forum.pcsoft.fr/es-ES/pcsoft.us.windev/67047-reading-com-port-with-sevent-67172/read.awp</comments><pubDate>6 Aug 2019 04:31:51 Z</pubDate><description>Hi Patrick....I Have the same problem, can you fix them?</description><guid isPermaLink="true">https://forum.pcsoft.fr/es-ES/pcsoft.us.windev/67047-reading-com-port-with-sevent-67172/read.awp</guid><link>https://forum.pcsoft.fr/es-ES/pcsoft.us.windev/67047-reading-com-port-with-sevent-67172/read.awp</link><source url="https://forum.pcsoft.fr/es-ES/pcsoft.us.windev/67047-reading-com-port-with-sevent/read.awp">Reading Com-port with sEvent</source><title>Re: Reading Com-port with sEvent</title></item></channel></rss>
