[Gambas-user] Serial port control

nando nando_f at ...951...
Mon Dec 23 10:03:39 CET 2013


My suggestion to reading 124 bytes from a serial stream....

I use this technique mostly because I want to empty the buffer provided by the control
as much as possible.

I would have one function which is the _read of the serial port.
The only thing it does is accumulate bytes in an array.

I have another function which will ask for 124 bytes from the accumlating array.
If there are not enough, it can block, or return an array of zero long
which would mean not enough came in.
In this case you could also do a small time delay (ie. WAIT 0.1) 
just to prevent the CPU from running 100% testing for 124 bytes.


Both of these can be a Gambas Class and the second function is the public function.
You can use _new to instantiate the serial port control.
You don't need to create it at design time.

I used techniques like this and it works like a charm.
-Nando


---------- Original Message -----------
From: Randall Morgan <rmorgan62 at ...626...>
To: mailing list for gambas users <gambas-user at lists.sourceforge.net>
Sent: Sun, 22 Dec 2013 23:35:33 -0800
Subject: Re: [Gambas-user] Serial port control

> I think the RTheshold of VB simply sets the byte count that must accumulate
> in the receive buffer before a comm event is triggered. It doesn't do
> anything else. In the background VB is still polling the buffer and looking
> at the byte count. You can do this in GB but you will have to write it
> yourself. You would need to simply use the read event on the comm object to
> test the byte count. I believe it triggers at 1 byte. Then use that to
> trigger your own custom event when your 124 bytes have arrived.
> 
> You might also be able to talk Benoit into adding an RThreshold property.
> Seems like it might be handy.... At the very least 4Hz is very very slow
> for most computers. And setting up a 4Hz polling of the port wouldn't be
> hard at all.
> 
> On Sun, Dec 22, 2013 at 8:10 PM, Carl Nilsson <nilsson at ...1979...> wrote:
> 
> > Thanks Randall.  I guess it's time to try it and play around a
> > little, which I can't do for a few days.  At the moment I'm trying to
> > look ahead and see where problems might lie.  When push comes to
> > shove, I don't know how these things really work!  I follow
> > recipes!  Don't really want to close the port as the data come in
> > continuously as fast as the device can send them and I don't want to
> > miss any.  (It's attitude sensor data from an inertial management
> > unit in a light aircraft).  Same in principle with another
> > "continuous" stream of binary GPS data with packets of 124 bytes
> > coming in at a slower rate of, say, 4 Hz.  How "continuous" it is
> > would depend on the baud rate at which the port is operating.  The
> > RThreashold property of MScomm handles this issue very well. Doesn't
> > trigger an event until the specified number of bytes is in the serial
> > buffer.
> > Carl
> >
> > At 02:47 PM 23/12/2013, you wrote:
> > >It has been a long while since I have used the serial component of GB but
> > I
> > >have a project starting in which I will need to re-acquaint myself with
> > it.
> > >The stream can be setup as blocking or non-blocking. The PC uses either
> > >polling or interrupt when the port is opened. So trying to manage the
> > >serial port at the same level you would in on uC is pointless in most
> > >cases. Just set up the stream and read the bytes you need from there. If
> > >you're concerned about buffer overflow then you may want to close the port
> > >once you have read the bytes you need.
> > >
> > >Perhaps someone with more recent experience can help you more.
> > >
> > >
> > >
> > >
> > >On Sun, Dec 22, 2013 at 7:15 PM, Carl Nilsson <nilsson at ...1979...>
> > wrote:
> > >
> > > > Randall: Thanks for responding.  OK, I have looked at the stream
> > > > functions:  My question was, basically, how do I specify how many
> > > > bytes I want to take in from a given serial port at each
> > > > instance?  For example, on one input I expect a continuous stream of
> > > > 31 byte packets and I want to take them in for processing 25 (say)
> > > > packets at a time, i.e. 775 bytes at a time.  Now I don't much mind
> > > > if I get a few bytes more or less because I can check for a remainder
> > > > part-packet and put it on the front of the next nominal 775 byte
> > > > intake - that's part of the processing software - but I don't want
> > > > the CPU tied up with that port or stream between intakes of (about)
> > > > 775 bytes.  There are other input streams and data processing to
> > > > attend to.  I don't see how to do that with the stream functions -
> > > > but maybe I'm not understanding how the stream works?  I can see that
> > > > I could (I think!) read a given number of bytes from a stream, but
> > > > does that relieve the CPU from being tied up with that stream until I
> > > > read another 775 bytes?  Is a stream of indefinite length or does it
> > > > have some buffer limit?
> > > > Carl
> > > >
> > > > At 01:09 PM 23/12/2013, you wrote:
> > > > >As I recall gb serial is steam based and so you would handle buffers
> > via
> > > > >the stream not the serial object.
> > > > >
> > > > >
> > > > >On Sun, Dec 22, 2013 at 3:01 PM, Carl Nilsson <nilsson at ...1979...>
> > > > wrote:
> > > > >
> > > > > > G'day all:
> > > > > > Now with Gambas 3 installed, I want to get on with porting my
> > running
> > > > > > software from VB6/Windows.  It requires processing multiple streams
> > > > > > of binary serial data from attached devices.  The serial control in
> > > > > > gambas 3 does not seem up to the job, in so far as the available
> > > > > > properties lack the elements I use under VB MScomm.  ...(snip)
> > > >
> > > >
> > > > > > Carl
> > > > > >
> > > > > > Carl S Nilsson
> > > > > > 137 Gordons Hill Road
> > > > > > Lindisfarne, Tas.
> > > > > > Australia 7015
> > > > > >
> > > > > >
> > > > > >
> > > > > >
> > > > >
> > > >
> > >
> > ------------------------------------------------------------------------------
> > > > > > Rapidly troubleshoot problems before they affect your business.
> > Most IT
> > > > > > organizations don't have a clear picture of how application
> > performance
> > > > > > affects their revenue. With AppDynamics, you get 100% visibility
> > into
> > > > your
> > > > > > Java,.NET, & PHP application. Start your 15-day FREE TRIAL of
> > > > AppDynamics
> > > > > > Pro!
> > > > > >
> > > >
> > http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk
> > > > > > _______________________________________________
> > > > > > Gambas-user mailing list
> > > > > > Gambas-user at lists.sourceforge.net
> > > > > > https://lists.sourceforge.net/lists/listinfo/gambas-user
> > > > > >
> > > > >
> > > > >
> > > > >
> > > > >--
> > > > >If you ask me if it can be done. The answer is YES, it can always be
> > done.
> > > > >The correct questions however are... What will it cost, and how long
> > will
> > > > >it take?
> > > >
> > > > >-----------------------------------------------------------------
> > > -------------
> > > > >Rapidly troubleshoot problems before they affect your business. Most
> > IT
> > > > >organizations don't have a clear picture of how application
> > performance
> > > > >affects their revenue. With AppDynamics, you get 100% visibility into
> > your
> > > > >Java,.NET, & PHP application. Start your 15-day FREE TRIAL of
> > AppDynamics
> > > > Pro!
> > > > >
> > > >
> > http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk
> > > > >_______________________________________________
> > > > >Gambas-user mailing list
> > > > >Gambas-user at lists.sourceforge.net
> > > > >https://lists.sourceforge.net/lists/listinfo/gambas-user
> > > >
> > > > Carl S Nilsson
> > > > 137 Gordons Hill Road
> > > > Lindisfarne, Tas.
> > > > Australia 7015
> > > >
> > > >
> > >
> > ------------------------------------------------------------------------------
> > > > Rapidly troubleshoot problems before they affect your business. Most IT
> > > > organizations don't have a clear picture of how application performance
> > > > affects their revenue. With AppDynamics, you get 100% visibility into
> > your
> > > > Java,.NET, & PHP application. Start your 15-day FREE TRIAL of
> > AppDynamics
> > > > Pro!
> > > >
> > http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk
> > > > _______________________________________________
> > > > Gambas-user mailing list
> > > > Gambas-user at lists.sourceforge.net
> > > > https://lists.sourceforge.net/lists/listinfo/gambas-user
> > > >
> > >
> > >
> > >
> > >--
> > >If you ask me if it can be done. The answer is YES, it can always be done.
> > >The correct questions however are... What will it cost, and how long will
> > >it take?
> >
> > >------------------------------------------------------------------------------
> > >Rapidly troubleshoot problems before they affect your business. Most IT
> > >organizations don't have a clear picture of how application performance
> > >affects their revenue. With AppDynamics, you get 100% visibility into your
> > >Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics
> > Pro!
> > >
> > http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk
> > >_______________________________________________
> > >Gambas-user mailing list
> > >Gambas-user at lists.sourceforge.net
> > >https://lists.sourceforge.net/lists/listinfo/gambas-user
> >
> > Carl S Nilsson
> > 137 Gordons Hill Road
> > Lindisfarne, Tas.
> > Australia 7015
> >
> > ------------------------------------------------------------------------------
> > Rapidly troubleshoot problems before they affect your business. Most IT
> > organizations don't have a clear picture of how application performance
> > affects their revenue. With AppDynamics, you get 100% visibility into your
> > Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics
> > Pro!
> > http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk
> > _______________________________________________
> > Gambas-user mailing list
> > Gambas-user at lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/gambas-user
> >
> 
> -- 
> If you ask me if it can be done. The answer is YES, it can always be done.
> The correct questions however are... What will it cost, and how long will
> it take?
> ------------------------------------------------------------------------------
> Rapidly troubleshoot problems before they affect your business. Most IT 
> organizations don't have a clear picture of how application performance 
> affects their revenue. With AppDynamics, you get 100% visibility into your 
> Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
> http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk
> _______________________________________________
> Gambas-user mailing list
> Gambas-user at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
------- End of Original Message -------





More information about the User mailing list