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