[Gambas-user] Serial Port Reading Issue

nando nando_f at ...951...
Sat Feb 9 03:00:17 CET 2008


The SPort_Read() routine runs when there are SOME
characters received from the serial port..
and they get printed with the PRINT statement.
The PRINT statement adds the LineFeed, so the next
print statement begins on the next line.

So:

INSERISC     <----These characters were available with one SPort_Read event
I COMANDO    <----These characters were available with next SPort_Read event

You have to remember that data transfer at 19200 is very slow compared to the
speed the CPU works, so it can print what it has before all characters arrive.

Here is an idea to solve your problem:

1) Have a public string
PUBLIC serialportread AS STRING

2) the following will accumulate characters received in 'serialportread'
PUBLIC SUB Sport_Read()

  DIM s AS String

  READ #Sport, s, Lof(Sport)
  serialportread = serialportread & s

  'Test here if 'serialportread' has "->" and "<-" in it
  'if it does, then use it. Don't forget to clear serialportread
  'if it doesn't have -> and <-, just exit..hopefully the next event will have it.
  
END

-Fernando





---------- Original Message -----------
From: Marco Mascia <marco at ...1785...>
To: gambas-user at lists.sourceforge.net
Sent: Fri, 08 Feb 2008 17:19:09 +0100
Subject: [Gambas-user] Serial Port Reading Issue

> Hi there!
> We have some trouble making a Serial port Read (first time that i work 
> on it).
> 
> Our card reader is a device that sends a "await command" every 500 ms
> (Note: the device works on a serial port standard RS232 br: 19200, 
> 8-N-1, no flow control.)
> 
> if we do from shell cat /dev/ttyS0/ we obtain:
> 
> INSERISCI COMANDO
> INSERISCI COMANDO
> MEMORIZZAZIONE CODICE ->101027256<- (a card read)
> INSERISCI COMANDO
> ...
> etc
> 
> Instead a read on gambas console with this code:
> 
> PUBLIC SUB Sport_Read()
> 
> DIM s AS String
> 
> READ #Sport, s, Lof(Sport)
> print s
> 
> END
> 
> we obtain:
> 
> INSERISC
> I COMANDO
> 
> INSERISC
> I COMANDO
> 
> MEMORIZZ
> AZIONE CODICE ->10102725
> 6<-
> 
> INSERISC
> I COMANDO
> ...
> etc
> 
> problems:
> 
> Weird output or i am a noob and i miss something? :D
> I need to extract the card code between "->" and "<-" from the stream.
> any help/suggestion?
> 
> anybody knows how to obtain the same result of cat command inside gambas?
> 
> tnx in advance.
> 
> ---
> Marco
> 
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2008.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> _______________________________________________
> 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