[Gambas-user] does nothing using serial object as class property to implements
PICCORO McKAY Lenz
mckaygerhard at ...626...
Mon Nov 30 23:56:50 CET 2015
i'm trying t5o use the serial port with a class..
but when i try to write to the serial port nothing happened.. only wend
data if i made all the port stuff from the form class
here the code and the problems in comments:
'' ************* Begin class serial manager
Private SComm As SerialPort
Public Sub _new()
SComm = New SerialPort As "SComm"
SComm.Speed = 9600
SComm.Parity = SerialPort.None
SComm.DataBits = SerialPort.Bits8
SComm.StopBits = SerialPort.Bits1
SComm.FlowControl = SerialPort.Both
End
Public Function usarpuerto(puerto As String) As Boolean
' use port name passed
SComm.PortName = puerto
Try
SComm.Open()
If Error Then
Print "Error " & Error.Code & " en " & Error.Text & " ---- " &
Error.Backtrace
Return Null
Endif
' write to the port
Print #SComm, Chr$(2) & "X" & Chr$(3)
If Error Then
Return False
Endif
' now close the port
If SComm.Status = Net.Active Then
Try
SComm.Close()
If Error Then
Return Null
Endif
Endif
Return True
End
'' ************ end class serial manager
'' ************ begin of the from that implements serial class
Public libreria As ClassSerial
Public Sub Form_Open()
Dim dispositivo As SerialPort
libreria = New ClassSerial
End
Public Sub btn_Click()
libreria.usarpuerto("/dev/ttyS0")
'' here nothings happened on the device
'' but if i code all on the form class works
End
'' ************ end of form that implements the class
Lenz McKAY Gerardo (PICCORO)
http://qgqlochekone.blogspot.com
More information about the User
mailing list