<html><head></head><body><div style="font-family:Helvetica Neue, Helvetica, Arial, sans-serif;font-size:13px;"><div style="font-family:Helvetica Neue, Helvetica, Arial, sans-serif;font-size:13px;"><div><div><span>
        
        
        


<p style="margin-bottom: 0cm; line-height: 100%">I disagree that the
RS232, RS485 controls are no longer relevant. Industrial automation
uses these controls quite extensively when talking to PLC’s RTU’s
and specialised control hardware that is controlled by the Modbus,
DMP3 and many other industrial communications protocols. The speed
over a network is generally not an issue as most industrial process
are slow when compared to RS232, RS485 data speeds of around 9600 or
the now common 19200 BAUD rates. I have had extensive experience with
this type of communication over many years controlling and remote
control of small Power Stations of 1 to 10 megawatt using 1 megawatt
modules. Each module uses at least 1 PLC per generator and up to an
additional 5 or 6 for general utility control and at least 1 RTU.
These are generally all serviced over a RS485 network at 9600 BAUD. I
have not seen any bottle necks with this number of devices as long as
network usage is prioritised correctly.</p>
<p style="margin-bottom: 0cm; line-height: 100%"><br>

</p>
<p style="margin-bottom: 0cm; line-height: 100%">Regards</p>
<p style="margin-bottom: 0cm; line-height: 100%">Mike</p></span><br></div><div><br></div><div class="ydpb4df0dffsignature"><div style="font-family:Helvetica, Arial, sans-serif;font-size:13px;"><div><br></div><div><br></div></div></div></div>
        <div><br></div><div><br></div>
        
        </div><div id="yahoo_quoted_4592595041" class="yahoo_quoted">
            <div style="font-family:'Helvetica Neue', Helvetica, Arial, sans-serif;font-size:13px;color:#26282a;">
                
                <div>
                    On Tuesday, 7 August 2018, 11:36:07 am AWST, Tony Morehen <tmorehen@ajm-software.com> wrote:
                </div>
                <div><br></div>
                <div><br></div>
                <div><div dir="ltr"><br></div><div dir="ltr"><br></div><div dir="ltr"><br></div><div dir="ltr">-------- Forwarded Message --------<br></div><div dir="ltr">Subject:     Re: [Gambas-user] using events of serial ports for reading how_?<br></div><div dir="ltr">Date:     Mon, 6 Aug 2018 20:12:50 -0400<br></div><div dir="ltr">From:     Tony Morehen <<a ymailto="mailto:tmorehen@ajmconsulting.ca" href="mailto:tmorehen@ajmconsulting.ca">tmorehen@ajmconsulting.ca</a>><br></div><div dir="ltr">To:     PICCORO McKAY Lenz <<a ymailto="mailto:mckaygerhard@gmail.com" href="mailto:mckaygerhard@gmail.com">mckaygerhard@gmail.com</a>><br></div><div dir="ltr"><br></div><div dir="ltr"><br></div><div dir="ltr"><br></div><div dir="ltr">In modern serial communications, there is almost no use for CTS, DCD, <br></div><div dir="ltr">DSR, DTR,RNG, RTS, all of it at the driver level.  The driver handles <br></div><div dir="ltr">all handshaking and flow control.  Further, your serial port reads and <br></div><div dir="ltr">writes are not made directly to the serial port but to buffers in the <br></div><div dir="ltr">driver.<br></div><div dir="ltr"><br></div><div dir="ltr">You must remember that serial port communications are slow. That's the <br></div><div dir="ltr">reason you have missing or leftover data. The sequence is something like:<br></div><div dir="ltr"><br></div><div dir="ltr">1) Printer starts to send a line of data<br></div><div dir="ltr">2) Driver receives a byte, raises a read event<br></div><div dir="ltr">3) Your programs responds, likely before the end of the line, reading <br></div><div dir="ltr">what's currently in the driver's buffer.<br></div><div dir="ltr">4) Printer finishes sending the rest of the line, triggering more read <br></div><div dir="ltr">events.<br></div><div dir="ltr"><br></div><div dir="ltr">Serial communications tend to be packet-based so your low level read <br></div><div dir="ltr">routine should read an entire packet before raising a dataavailable event:<br></div><div dir="ltr"><br></div><div dir="ltr">If each received byte is independent, say a instrument reading, raise a <br></div><div dir="ltr">dataavailable event for every byte.<br></div><div dir="ltr"><br></div><div dir="ltr">If a packet is fixed-length, raise the event every packet-length bytes.  <br></div><div dir="ltr">Fixed-length packets frequently have sync bytes between packets.  These <br></div><div dir="ltr">should be ignored.  Decide how to handle partial packets.<br></div><div dir="ltr"><br></div><div dir="ltr">Variable length packets have to be handled according to their <br></div><div dir="ltr">structure.  Some will be packet followed by an end of packet marker.  <br></div><div dir="ltr">Raise the dataavailable event when your program encounters the marker.<br></div><div dir="ltr"><br></div><div dir="ltr">Other variable-length packets will inclu<br></div><div dir="ltr"><br></div><div dir="ltr"><br></div><div dir="ltr">On 2018-08-06 05:10 PM, PICCORO McKAY Lenz wrote:<br></div><div dir="ltr">> um ok make sense that if there's already a event handler why use the <br></div><div dir="ltr">> manual reading..<br></div><div dir="ltr">><br></div><div dir="ltr">> the problem its that sometimes i made manual reading an get extra data <br></div><div dir="ltr">> that are not in the event handler (yep sound quite strange) due i'm <br></div><div dir="ltr">> managing a fiscal kit printer device<br></div><div dir="ltr">><br></div><div dir="ltr">> i'll try to use your semaphore, but there's another way maybe using <br></div><div dir="ltr">> the_CTSChange <br></div><div dir="ltr">> <<a href="http://gambaswiki.org/wiki/comp/gb.net/serialport/.ctschange" target="_blank">http://gambaswiki.org/wiki/comp/gb.net/serialport/.ctschange</a>>_<br></div><div dir="ltr">> _DCDChange <br></div><div dir="ltr">> <<a href="http://gambaswiki.org/wiki/comp/gb.net/serialport/.dcdchange" target="_blank">http://gambaswiki.org/wiki/comp/gb.net/serialport/.dcdchange</a>>_ <br></div><div dir="ltr">> _DSRChange <br></div><div dir="ltr">> <<a href="http://gambaswiki.org/wiki/comp/gb.net/serialport/.dsrchange" target="_blank">http://gambaswiki.org/wiki/comp/gb.net/serialport/.dsrchange</a>>_ <br></div><div dir="ltr">> _DTRChange <br></div><div dir="ltr">> <<a href="http://gambaswiki.org/wiki/comp/gb.net/serialport/.dtrchange" target="_blank">http://gambaswiki.org/wiki/comp/gb.net/serialport/.dtrchange</a>>_ <br></div><div dir="ltr">> _RNGChange <br></div><div dir="ltr">> <<a href="http://gambaswiki.org/wiki/comp/gb.net/serialport/.rngchange" target="_blank">http://gambaswiki.org/wiki/comp/gb.net/serialport/.rngchange</a>>_ <br></div><div dir="ltr">> _RTSChange <br></div><div dir="ltr">> <<a href="http://gambaswiki.org/wiki/comp/gb.net/serialport/.rtschange" target="_blank">http://gambaswiki.org/wiki/comp/gb.net/serialport/.rtschange</a>>_<br></div><div dir="ltr">> ??<br></div><div dir="ltr">><br></div><div dir="ltr">> Lenz McKAY Gerardo (PICCORO)<br></div><div dir="ltr">> <a href="http://qgqlochekone.blogspot.com" target="_blank">http://qgqlochekone.blogspot.com</a><br></div><div dir="ltr">><br></div><div dir="ltr">><br></div><div dir="ltr">> El lun., 6 de ago. de 2018 a la(s) 13:41, T Lee Davidson <br></div><div dir="ltr">> (<a ymailto="mailto:t.lee.davidson@gmail.com" href="mailto:t.lee.davidson@gmail.com">t.lee.davidson@gmail.com</a> <mailto:<a ymailto="mailto:t.lee.davidson@gmail.com" href="mailto:t.lee.davidson@gmail.com">t.lee.davidson@gmail.com</a>>) escribió:<br></div><div dir="ltr">><br></div><div dir="ltr">>     You will have problems if you try to utilize both an event<br></div><div dir="ltr">>     triggered serial port read and a manual read.<br></div><div dir="ltr">><br></div><div dir="ltr">>     The SerialPort.Read event is triggered when there is data<br></div><div dir="ltr">>     available to be read. If you read that data in the event handler, the<br></div><div dir="ltr">>     port is cleared and there will be no data available to a manual read.<br></div><div dir="ltr">><br></div><div dir="ltr">>     If you want to manually read the port, then you should not read<br></div><div dir="ltr">>     the data from it in the SerialPort.Read event handler. Perhaps<br></div><div dir="ltr">>     you do not even need to implement that event handler.<br></div><div dir="ltr">><br></div><div dir="ltr">>     I could be incorrect since I haven't verified this. But, it seems<br></div><div dir="ltr">>     logical to me that Stream.Blocking would be False by default<br></div><div dir="ltr">>     otherwise an attempt to read the port would hang the application<br></div><div dir="ltr">>     until data is available and that should not be a default behavior.<br></div><div dir="ltr">><br></div><div dir="ltr">>     I can think of two ways to implement manual reading.<br></div><div dir="ltr">><br></div><div dir="ltr">>     1. Do not implement a SerialPort.Read event handler, ensure that<br></div><div dir="ltr">>     Stream.Blocking = False, and simply read the port manually<br></div><div dir="ltr">>     understanding that there may be no data available. In this case<br></div><div dir="ltr">>     READ would appear to do nothing, but the application would not hang.<br></div><div dir="ltr">><br></div><div dir="ltr">>     2. Use the SerialPort.Read event handler to set a flag indicating<br></div><div dir="ltr">>     that data is available and read that flag in your Sub rp()<br></div><div dir="ltr">>     function. For example:<br></div><div dir="ltr">><br></div><div dir="ltr">>     Private PortDataAvailable As Boolean<br></div><div dir="ltr">><br></div><div dir="ltr">>     Public Sub SComm_Read()<br></div><div dir="ltr">>             PortDataAvailable = True<br></div><div dir="ltr">>     End<br></div><div dir="ltr">><br></div><div dir="ltr">>     Public Sub rp()<br></div><div dir="ltr">>             If myDataAvailableBoolean then<br></div><div dir="ltr">>                     ' Do the port reading stuff<br></div><div dir="ltr">>                     ' Read port blah blah blah<br></div><div dir="ltr">>                     ' All data has been read<br></div><div dir="ltr">>                     PortDataAvailable = False<br></div><div dir="ltr">>             Else<br></div><div dir="ltr">>                     Print "No data available"<br></div><div dir="ltr">>                     Return<br></div><div dir="ltr">>             Endif<br></div><div dir="ltr">>     End<br></div><div dir="ltr">><br></div><div dir="ltr">><br></div><div dir="ltr">>     ___<br></div><div dir="ltr">>     Lee<br></div><div dir="ltr">><br></div><div dir="ltr">><br></div><div dir="ltr">>     On 08/06/2018 12:05 PM, PICCORO McKAY Lenz wrote:<br></div><div dir="ltr">>     > OK hans, and tobias, yes the code in my first mail last week was<br></div><div dir="ltr">>     bad,<br></div><div dir="ltr">>     > now i understant some problems when i read agains the printert<br></div><div dir="ltr">>     > but i need and i want a manual read funtion "also": so i have now:<br></div><div dir="ltr">>     ><br></div><div dir="ltr">>     > the read event for the port, as documents suggest "is triggered"<br></div><div dir="ltr">>     > when data "can be read" so if there's some data to read or available<br></div><div dir="ltr">>     > the event will be executed by itselft, but i want also a manual<br></div><div dir="ltr">>     "rp" method<br></div><div dir="ltr">>     > that read also the port manually, at this point i dont know<br></div><div dir="ltr">>     > if will be sync or async, i have a "sale" class that will be<br></div><div dir="ltr">>     polled into a form,<br></div><div dir="ltr">>     > but as Tobias said i used the Scom_Read<br></div><div dir="ltr">>     > but still need a manual read funtion due the inherits so i have :<br></div><div dir="ltr">>     ><br></div><div dir="ltr">>     > 1) the read event:<br></div><div dir="ltr">>     ><br></div><div dir="ltr">>     > ' this event will be triggered in read operations by the stream<br></div><div dir="ltr">>     when data its available<br></div><div dir="ltr">>     > Public Sub SComm_Read()<br></div><div dir="ltr">>     >    dim buffers as string = ''<br></div><div dir="ltr">>     >   Read #SComm, buffers, Lof(SComm)<br></div><div dir="ltr">>     >    dataread &= buffers<br></div><div dir="ltr">>     > End<br></div><div dir="ltr">>     ><br></div><div dir="ltr">>     > 2) here, how can i code a read manual operation do not conflict<br></div><div dir="ltr">>     if there's already an operation triggered by teh read event?<br></div><div dir="ltr">>     ><br></div><div dir="ltr">>     > i used some code proposed by Tobias but:<br></div><div dir="ltr">>     ><br></div><div dir="ltr">>     > '' generic read port buffer data<br></div><div dir="ltr">>     > Public Sub rp()<br></div><div dir="ltr">>     >    dim  start as date = Now<br></div><div dir="ltr">>     >    dim buffers as string = ''<br></div><div dir="ltr">>     >   Do<br></div><div dir="ltr">>     >     Wait 0.1<br></div><div dir="ltr">>     >     Read #SComm, buffers, Lof(SComm)<br></div><div dir="ltr">>     >     dataread &= buffers<br></div><div dir="ltr">>     >   Loop Until DateDiff(start, Now, gb.Millisecond) > 500<br></div><div dir="ltr">>     > End<br></div><div dir="ltr">>     ><br></div><div dir="ltr">>     > now i have the problem of locking, as Tobias said I not even<br></div><div dir="ltr">>     sure how Read<br></div><div dir="ltr">>     > behaves when Lof is zero or if the read are just triggered at<br></div><div dir="ltr">>     same time the rp was invoqued!<br></div><div dir="ltr">>     > so then reading would block.<br></div><div dir="ltr">>     ><br></div><div dir="ltr">>     > i dont know how to use the SComm.Blocking = False to make manual<br></div><div dir="ltr">>     polling,<br></div><div dir="ltr">>     ><br></div><div dir="ltr">>     ><br></div><div dir="ltr">>     > Lenz McKAY Gerardo (PICCORO)<br></div><div dir="ltr">>     > <a href="http://qgqlochekone.blogspot.com" target="_blank">http://qgqlochekone.blogspot.com</a><br></div><div dir="ltr">>     ><br></div><div dir="ltr">>     ><br></div><div dir="ltr">>     > El lun., 6 de ago. de 2018 a la(s) 09:59, PICCORO McKAY Lenz<br></div><div dir="ltr">>     (<a ymailto="mailto:mckaygerhard@gmail.com" href="mailto:mckaygerhard@gmail.com">mckaygerhard@gmail.com</a> <mailto:<a ymailto="mailto:mckaygerhard@gmail.com" href="mailto:mckaygerhard@gmail.com">mckaygerhard@gmail.com</a>><br></div><div dir="ltr">>     <mailto:<a ymailto="mailto:mckaygerhard@gmail.com" href="mailto:mckaygerhard@gmail.com">mckaygerhard@gmail.com</a> <mailto:<a ymailto="mailto:mckaygerhard@gmail.com" href="mailto:mckaygerhard@gmail.com">mckaygerhard@gmail.com</a>>>)<br></div><div dir="ltr">>     escribió:<br></div><div dir="ltr">>     ><br></div><div dir="ltr">>     >     El lun., 6 de ago. de 2018 a la(s) 09:52, Hans Lehmann<br></div><div dir="ltr">>     (<a ymailto="mailto:hans@gambas-buch.de" href="mailto:hans@gambas-buch.de">hans@gambas-buch.de</a> <mailto:<a ymailto="mailto:hans@gambas-buch.de" href="mailto:hans@gambas-buch.de">hans@gambas-buch.de</a>><br></div><div dir="ltr">>     <mailto:<a ymailto="mailto:hans@gambas-buch.de" href="mailto:hans@gambas-buch.de">hans@gambas-buch.de</a> <mailto:<a ymailto="mailto:hans@gambas-buch.de" href="mailto:hans@gambas-buch.de">hans@gambas-buch.de</a>>>) escribió:<br></div><div dir="ltr">>     ><br></div><div dir="ltr">>     >         have a look at the chapters and the projects... under<br></div><div dir="ltr">>     https://www.gambas-buch.de/doku.php?id=k24:k24.1:k24.1.5:start!<br></div><div dir="ltr">>     ><br></div><div dir="ltr">>     >     THANKS HANS! now reading...<br></div><div dir="ltr">>     >      isend this mail to the list.. maybe you send too quickly<br></div><div dir="ltr">>     and forgett to do!<br></div><div dir="ltr">>     ><br></div><div dir="ltr">>     ><br></div><div dir="ltr">>     ><br></div><div dir="ltr">>     ><br></div><div dir="ltr">>     ><br></div><div dir="ltr">>     > ----[ Gambas mailing-list is hosted by<br></div><div dir="ltr">>     <a href="https://www.hostsharing.net " target="_blank">https://www.hostsharing.net </a>]----<br></div><div dir="ltr">>     ><br></div><div dir="ltr">><br></div><div dir="ltr">>     ----[ Gambas mailing-list is hosted by <a href="https://www.hostsharing.net" target="_blank">https://www.hostsharing.net</a><br></div><div dir="ltr">>     ]----<br></div><div dir="ltr">><br></div><div dir="ltr">><br></div><div dir="ltr">><br></div><div dir="ltr">> ----[ Gambas mailing-list is hosted byhttps://www.hostsharing.net  ]----<br></div><div dir="ltr"><br></div><div dir="ltr"><br></div><div dir="ltr"><br></div><div dir="ltr">----[ Gambas mailing-list is hosted by <a href="https://www.hostsharing.net " target="_blank">https://www.hostsharing.net </a>]----<br></div></div>
            </div>
        </div></div></body></html>