<div dir="ltr"><div><div>um ok make sense that if there's already a event handler why use the manual reading..<br><br></div>the problem its that sometimes i made manual reading an get extra data that are not in the event handler (yep sound quite strange) due i'm managing a fiscal kit printer device<br><br></div>i'll try to use your semaphore, but there's another way maybe using the<span class="gmail-inherit"><u><a href="http://gambaswiki.org/wiki/comp/gb.net/serialport/.ctschange"> CTSChange</a></u></span> <br><div class="gmail-tooltip-activator"><span class="gmail-inherit"><u><a href="http://gambaswiki.org/wiki/comp/gb.net/serialport/.dcdchange">DCDChange</a></u></span> <span class="gmail-inherit"><u><a href="http://gambaswiki.org/wiki/comp/gb.net/serialport/.dsrchange">DSRChange</a></u></span> <span class="gmail-inherit"><u><a href="http://gambaswiki.org/wiki/comp/gb.net/serialport/.dtrchange">DTRChange</a></u></span> <span class="gmail-inherit"><u><a href="http://gambaswiki.org/wiki/comp/gb.net/serialport/.rngchange">RNGChange</a></u></span> <span class="gmail-inherit"><u><a href="http://gambaswiki.org/wiki/comp/gb.net/serialport/.rtschange">RTSChange</a></u></span> <br></div> <div><div><div>??<br><br clear="all"><div><div dir="ltr" class="gmail_signature"><font color="#888888">Lenz McKAY Gerardo (PICCORO)</font><div><font color="#888888"><a href="http://qgqlochekone.blogspot.com" target="_blank">http://qgqlochekone.blogspot.com</a></font></div></div></div><br></div></div></div></div><br><div class="gmail_quote"><div dir="ltr">El lun., 6 de ago. de 2018 a la(s) 13:41, T Lee Davidson (<a href="mailto:t.lee.davidson@gmail.com">t.lee.davidson@gmail.com</a>) escribió:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">You will have problems if you try to utilize both an event triggered serial port read and a manual read.<br>
<br>
The SerialPort.Read event is triggered when there is data available to be read. If you read that data in the event handler, the<br>
port is cleared and there will be no data available to a manual read.<br>
<br>
If you want to manually read the port, then you should not read the data from it in the SerialPort.Read event handler. Perhaps<br>
you do not even need to implement that event handler.<br>
<br>
I could be incorrect since I haven't verified this. But, it seems logical to me that Stream.Blocking would be False by default<br>
otherwise an attempt to read the port would hang the application until data is available and that should not be a default behavior.<br>
<br>
I can think of two ways to implement manual reading.<br>
<br>
1. Do not implement a SerialPort.Read event handler, ensure that Stream.Blocking = False, and simply read the port manually<br>
understanding that there may be no data available. In this case READ would appear to do nothing, but the application would not hang.<br>
<br>
2. Use the SerialPort.Read event handler to set a flag indicating that data is available and read that flag in your Sub rp()<br>
function. For example:<br>
<br>
Private PortDataAvailable As Boolean<br>
<br>
Public Sub SComm_Read()<br>
PortDataAvailable = True<br>
End<br>
<br>
Public Sub rp()<br>
If myDataAvailableBoolean then<br>
' Do the port reading stuff<br>
' Read port blah blah blah<br>
' All data has been read<br>
PortDataAvailable = False<br>
Else<br>
Print "No data available"<br>
Return<br>
Endif<br>
End<br>
<br>
<br>
___<br>
Lee<br>
<br>
<br>
On 08/06/2018 12:05 PM, PICCORO McKAY Lenz wrote:<br>
> OK hans, and tobias, yes the code in my first mail last week was bad,<br>
> now i understant some problems when i read agains the printert<br>
> but i need and i want a manual read funtion "also": so i have now:<br>
> <br>
> the read event for the port, as documents suggest "is triggered"<br>
> when data "can be read" so if there's some data to read or available<br>
> the event will be executed by itselft, but i want also a manual "rp" method<br>
> that read also the port manually, at this point i dont know<br>
> if will be sync or async, i have a "sale" class that will be polled into a form,<br>
> but as Tobias said i used the Scom_Read<br>
> but still need a manual read funtion due the inherits so i have :<br>
> <br>
> 1) the read event:<br>
> <br>
> ' this event will be triggered in read operations by the stream when data its available<br>
> Public Sub SComm_Read()<br>
> dim buffers as string = ''<br>
> Read #SComm, buffers, Lof(SComm)<br>
> dataread &= buffers<br>
> End<br>
> <br>
> 2) here, how can i code a read manual operation do not conflict if there's already an operation triggered by teh read event?<br>
> <br>
> i used some code proposed by Tobias but:<br>
> <br>
> '' generic read port buffer data<br>
> Public Sub rp()<br>
> dim start as date = Now<br>
> dim buffers as string = ''<br>
> Do<br>
> Wait 0.1<br>
> Read #SComm, buffers, Lof(SComm)<br>
> dataread &= buffers<br>
> Loop Until DateDiff(start, Now, gb.Millisecond) > 500<br>
> End<br>
> <br>
> now i have the problem of locking, as Tobias said I not even sure how Read<br>
> behaves when Lof is zero or if the read are just triggered at same time the rp was invoqued!<br>
> so then reading would block.<br>
> <br>
> i dont know how to use the SComm.Blocking = False to make manual polling,<br>
> <br>
> <br>
> Lenz McKAY Gerardo (PICCORO)<br>
> <a href="http://qgqlochekone.blogspot.com" rel="noreferrer" target="_blank">http://qgqlochekone.blogspot.com</a><br>
> <br>
> <br>
> El lun., 6 de ago. de 2018 a la(s) 09:59, PICCORO McKAY Lenz (<a href="mailto:mckaygerhard@gmail.com" target="_blank">mckaygerhard@gmail.com</a> <mailto:<a href="mailto:mckaygerhard@gmail.com" target="_blank">mckaygerhard@gmail.com</a>>) escribió:<br>
> <br>
> El lun., 6 de ago. de 2018 a la(s) 09:52, Hans Lehmann (<a href="mailto:hans@gambas-buch.de" target="_blank">hans@gambas-buch.de</a> <mailto:<a href="mailto:hans@gambas-buch.de" target="_blank">hans@gambas-buch.de</a>>) escribió:<br>
> <br>
> have a look at the chapters and the projects... under <a href="https://www.gambas-buch.de/doku.php?id=k24:k24.1:k24.1.5:start" rel="noreferrer" target="_blank">https://www.gambas-buch.de/doku.php?id=k24:k24.1:k24.1.5:start</a>!<br>
> <br>
> THANKS HANS! now reading...<br>
> isend this mail to the list.. maybe you send too quickly and forgett to do!<br>
> <br>
> <br>
> <br>
> <br>
> <br>
> ----[ Gambas mailing-list is hosted by <a href="https://www.hostsharing.net" rel="noreferrer" target="_blank">https://www.hostsharing.net</a> ]----<br>
> <br>
<br>
----[ Gambas mailing-list is hosted by <a href="https://www.hostsharing.net" rel="noreferrer" target="_blank">https://www.hostsharing.net</a> ]----<br>
</blockquote></div>