[Gambas-user] Serial port control

Mike Crean mike.crean at ...2897...
Tue Dec 24 01:22:00 CET 2013


  
Hi Carl, 

 I
have a BeagleBone Black up and running with wheezy, LXDE desktop and
Gambas 3.5.9
I am able to use all most all of the available GPIO
and read the AD's using Gambas, I have not had any uarts up. I see no
problem in getting the the uarts to run using standard USB to serial
converters (Jaycar) work well with the Rpi.

I also have Rpi
series B running with the same OS & desktop as the BBB and using
Gambas 3. This is connected to an
Arduino Uno via a usb uart on
the Rpi used to control 6 signals and 7 point motors on a miniature
railway all running at 56000
baud. Using an input from the
terminal the Gambas software sends an ASCII message via the uart to
the Uno and it 
will execute the request (change points or
signals) and send back an ASCII message the request was executed.
This is not a very 
high speed system as changes may be seconds or
minutes.

I have also used Gambas to communicate with PLC's
using Modbus RTU and crc16 at 9600 baud with high volume short
interval requests over
RS485 networks and up to 20 nodes. The
secret was to use a PC, PLC or RTU as the master and use a timer to
set the pole rate from the master.

I have also as you used VB6
to implement an extensive SCADA system for small power house control.
This was a very high volume data through put and I did not find the
need to use any special data handling to free up the PC. The PC was
off doing a lot of other stuff while the
SCADA was running. I have
implemented a small test SCADA module in Gambas and see no problems
with speed compared to commercial
SCADA packages even when using
the DNP3 protocol. The through put with VB6 or Gambas seemed to be
about double compared to commercial solutions.
 I would say I have had best results using an interrupt driven serial
routine to empty the uart buffers and handle the data. VB6 using
OnComm() function and Gambas using Sport_Read() function. Variable
buffer sizes can be dealt with by checking the length of the input
string using CR as the end of line indicator (chr13) as used in most
protocols (modbus ASCII & RTU). 

 Try something like, Try Print #Sport, Tx; Chr$(13) in a timer
function or from terminal input to send data through the uart.

If needed I have the Gambas modbus test
program and a Koyo Click PLC (under $100 au PLC software is free) to test and see if the
code is still OK, the modbus protocol uses binary data over the comms
link.

Hope this is of some help.

Best
Regards
Mike
Merry Christmas to all.

 





On Tuesday, 24 December 2013 2:38 AM, Carl Nilsson <nilsson at ...1979...> wrote:
 
G'day Guys (Nando, Randall and Mike):
Thanks for your helpful replies.  It's 5 am here and I woke up an 
hour ago with this matter running through my head, so your replies 
are welcome!  All good advice.  I realized that, first of all, I 
needed to get a handle on using the stream functions, which are quite 
new to me.  Secondly, as usual, there are many ways to skin a 
cat.  You are right, I need not be dependent on an RThreshold 
property.  I have been using this for years most successfully with 
MScomm in VB6.  It does exert efficient control, but sometimes my 
incoming packets vary in byte count..  So, early in the piece, I 
wrote code that would look for any remainder bytes or shortfall on 
the end of the designated input stream and put them onto the start of 
the next byte block to get back into synch.  The Windows kernel has a 
very efficient function called "MoveMemory" that can be called from 
VB6.  (I presume Linux has something similar).  It's very much faster 
than shifting bytes in Do loops.

Anyway, not being dependent on an totally accurate byte count prior 
to triggering an event suggested an alternate approach:  My principal 
data device is a decade-old  Microstrain Inertial Management Unit 
(IMU).that sends remorselessly at around 2356 bytes (sometimes plus a 
packet or two) per sec.  At the moment I'm doing all my processing on 
an old Advantech 9576F single board computer running Win 2K.  With 
about 8 serial ports in action and heaps of other processing to do, I 
wanted to ease things with some preprocessing of some data streams on 
one of these little new ARM boards like the Raspberry Pi or 
Beaglebone Black - the latter with at least 4 UARTS and running at 1 
GHz seems very attractive. They can run fully embedded under Linux 
with gambas for initial data processing.   I have an RPi now with 
gambas3 and wiring Pi installed to experiment with. Sometimes the IMU 
traffic is duplex when I change parameters in flight and additional 
data packets come back in addition to the normal data flow.  So I 
adjust the RThreshold value dynamically, but that's not vital.  All 
this adds up to the fact that another approach might be to trigger 
processing events simply with a timer - read the full stream each 
time and get the byte count approximately right.  With a "MoveMemory" 
function I can easily handle some unevenness in byte count.  As I 
said, I'm looking for the least drain on CPU load.   I don't really 
need the system tied up waiting and testing for an exact count.

Anyway, I thank you for all your comments.  I now know that what I 
need can be done and the next step is for me to 
experiment.  Yesterday I was having some doubts about choosing 
gambas.  Nice to talk with you guys.  I'll get back to you when I 
have something more useful to say or ask.
Merry Christmas, Carl


At 08:03 PM 23/12/2013, you wrote:
>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.

(snip)


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


More information about the User mailing list