[Gambas-user] Issue/Problem with Serial Port Component

ron ronstk at ...239...
Mon Jun 5 02:30:59 CEST 2006


On Monday 05 June 2006 01:58, nando wrote:
> The speed is 9600 baud.
> Yes they are sent in one block, but that block is at 9600 baud.
> The _read fires when there is at least one and by the time the code
> to actually READ there may be three or four or maybe many more.
> This means that there are some available to read when the event fires.
> If the event takes a long time to do something, then there will
> be more available the next time the event fires.
> 
> Gambas/Serial component is responsible to fire _read - which
> I am lead to believe is when LOF > 0 for that device.
> 
> Something inside the ASCII stream cannot trigger the event.
> It is the fact that there is at least something available which
> triggers the event.
> 
> The following is totally false:
> 
>     > If send in one part then a READ LOF() should read all
>     > and there is no more to read for a last bunch.
> 
> ...because of differing speeds between
> the computer to process and the 9600 stream.  When one char has arrived,
> Gambas can read it, put it in a string far before the second char has
> arrived.  It is even more pronounced at slower speeds.
> 
> The first LOF(s) only reads a few because only a few have arrived.
> The computer is much faster than a stream of 9600 baud chars.
> 
> -Fernando
> 

OK
Now the problem is more clear.
My idea is to start on the _Read event a timer with a
delay time approx 9600/8 * 120+30.
If the stream at 9600 is constant for those 120 bytes
without gaps then after the delay the LOF(SPort) should have the 
correct count of bytes available.

Drop Timer on the form. (gb.timer does not exist/works, completion?)

PUBLIC SPortReceiveString AS STRING
 
SUB SPort_Read()

  DIM s AS STRING
  DIM ls AS INTEGER

  Timer1.Delay=9600/8+2 * 120+30 ' start/stopbit and some spare bytes
  Timer1.Enable=true
END

public sub Timer1_Timer()
  Timer1.Enabled=False
  SPortMyRead
end
SUB SPortMyRead()
  DIM s AS STRING
  DIM ls AS INTEGER
 
  ls = LOF(SPort)
  READ # SPort, s, ls
  SPortReceiveString = SPortReceiveString & s  'accumulate input
END

May be this could help

Ron





More information about the User mailing list