B4J Question jSerial

drponciano

Member
Licensed User
Longtime User
What would be the correct sequence for closing a serial port (in case the USB-Serial adapter is disconnected) and opening it again?

like
Open serial:
            Dim usb1 as serial
            Dim stream1 as asyncstreams
            Dim puerto_serial as string="COM1"
            
...
            Sub open_port
            usb1.initialize("x")
            
            Try
                usb1.Open(puerto_serial)
            Catch
                toast.ToastShow("ERROR.")
                Return
            End Try

            usb1.SetParams(57600,8,1,0)
            If Not(stream1.IsInitialized) Then stream1.Initialize(usb1.GetInputStream, usb1.GetOutputStream, "Stream1")
            end sub
            
sub close_port
                usb1.PurgePort(usb1.PURGE_RXCLEAR)
                stream1.SendAllAndClose
                usb1.Close
end sub

private Sub Stream1_NewData (buflocalserial() As Byte)
log(buflocalserial.lengh)
end sub

If I call open_port after using close_port I don't get bytes from Stream1_NewData
 
Top