Hello Evryone!
I use jSerial library to connect to some device on serial/usb port.
I've a class that manage the connection with the devices and I'd like to catch the "Port not found" exception if the specified port doesn't exist.
I've used this code in the class that manage the connections:
and in the main module I use the this code to connect and catch the exception:
But the execution in case of not found port ends on "exc.Throw" line on the connection class with the exception "jssc.SerialPortException: Port name - COM11; Method name - openPort(); Exception type - Port not found." without propagate the exception to the main module.
What I'm missing or doing wrong?
Thanks for the attention.
I use jSerial library to connect to some device on serial/usb port.
I've a class that manage the connection with the devices and I'd like to catch the "Port not found" exception if the specified port doesn't exist.
I've used this code in the class that manage the connections:
B4X:
Sub Class_Globals
Dim objSerial As Serial
Dim mPort As String
Dim mEventName As String
Dim objCaller As Object
...
End Sub
Public Sub Initialize(Port As String,EventName As String,Caller As Object)
objSerial.Initialize("objSerial")
mPort = Port
mEventName = EventName
objCaller = Caller
End Sub
public Sub Connect()
Dim exc As ExceptionEx
Try
objSerial.Open(mPort)
objSerial.SetParams(9600,8,1,0)
objAsyncStream.Initialize(objSerial.GetInputStream,objSerial.GetOutputStream,"objAsyncStream")
If SubExists(objCaller,mEventName & "_Connected") Then
CallSubDelayed(objCaller,mEventName & "_Connected")
End If
Catch
exc = LastException
exc.Throw
End Try
End Sub
and in the main module I use the this code to connect and catch the exception:
B4X:
Sub AppStart (Args() As String)
Try
objConn.Initialize("COM11","objConn",Me) ' COM11 doesn't exist
objConn.Connect()
StartMessageLoop
Catch
Log("Error " & LastException.Message)
End Try
End Sub
But the execution in case of not found port ends on "exc.Throw" line on the connection class with the exception "jssc.SerialPortException: Port name - COM11; Method name - openPort(); Exception type - Port not found." without propagate the exception to the main module.
What I'm missing or doing wrong?
Thanks for the attention.
Last edited: