RS232 / Serial Support

Post your Gambas programming questions here.
Post Reply
AndyGable
Posts: 359
Joined: Wednesday 2nd December 2020 12:11am
Location: Northampton, England
Contact:

RS232 / Serial Support

Post by AndyGable »

Hi all,

Does anyone know of a place i can read up on how to use Serial (Rs232) communication with Gambas?

I as As I have a Serial Barcode Reader and I would like to get the data from this and use it with in my Software (I would also need to get the weight from it as it is a scanner / scale like they use in the supermarkers)

Ideal I would like to have the serial scanner not linked to anything like a keypress (or a Do loop like I had to have in DOS)

any information or example website would be welcomed.
User avatar
PJBlack
Posts: 184
Joined: Tuesday 9th June 2020 10:26pm
Location: Florstadt, Hessen, Germany

Re: RS232 / Serial Support

Post by PJBlack »

https://gambas-buch.de/dwen/doku.php?id ... .1.5:start

( i will come back to you tomorrow ... :( )
User avatar
sarpomira
Posts: 20
Joined: Monday 28th December 2020 4:15pm

Re: RS232 / Serial Support

Post by sarpomira »

I found this several months ago when working with Arduino communication.
Not mine.
This may help with your syntax and setup.
Private Sport As SerialPort
Const None As Integer = 0
Private RxLen As Integer
Private Rx As String

Public Sub Form_Open()
  Sport = New SerialPort As "Sport"
  Sport.PortName = "/dev/ttyACM0" 'Linux serial port to ttyUSB0
  Sport.Speed = "9600"
  Sport.Parity = 0
  Sport.DataBits = "8" 
  Sport.StopBits = "1"
  Sport.FlowControl = 0
  Sport.Open()
End

Public Sub Sport_Read()
  
  Try Read #Sport, Rx, Lof(Sport)
  
    If Error Then 
      Goto NoRx
    Endif
    
    RxLen = InStr(Rx, Chr(13))
    LabelRxlen.Text = RxLen
    ListBox1.Add(Rx)
  
NoRx:

  Rx = ""

End
Please post your serial comm code if you get it working. There are not many working examples kicking around.
cheers
Post Reply