B4J Question [Solved] Error on connecting to COM Port

Mark Read

Well-Known Member
Licensed User
Longtime User
I am having trouble connecting to a COM Port with the code below. The point is to read data coming from an Arduino. The code works fine on my friends computer but not on mine. Can someone give me a hint where I can look? PC is running Windows 10, 64 Bit. The Arduino IDE is open but the Serial Monitor is not. If I close the Arduino IDE, the problem still exists.

Code:
B4X:
#Region  Project Attributes
    #MainFormWidth: 600
    #MainFormHeight: 400
#End Region

Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private Label1 As Label
    Private Label3 As Label
    Private TextArea1 As TextArea
    Private myserial As Serial
    Private astream As AsyncStreams
    
    Private MyPort As String
    Private BaudRate As Int=9600
    Private btn_Connect As Button
    Private btn_Quit As Button
    Private rcvStr As String
    Private cb_UARTList As ComboBox
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.SetFormStyle("UNIFIED")
    MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
    MainForm.Show
        
    myserial.Initialize("")
    For Each ComPort In myserial.ListPorts
        cb_UARTList.Items.Add(ComPort)
    Next       
End Sub

Sub btn_Quit_MouseClicked (EventData As MouseEvent)
    ExitApplication
End Sub

Sub btn_Connect_MouseClicked (EventData As MouseEvent)
    Log("Com Port: " & MyPort)
    If btn_Connect.Text="Connect" Then
        btn_Connect.Text="Disconnect"   
        myserial.Open(MyPort)
        myserial.SetParams(BaudRate,8,1,0)
        astream.Initialize(myserial.GetInputStream,myserial.GetOutputStream,"astream")
    Else   
        btn_Connect.Text="Connect"
        astream.Close
        myserial.Close
    End If
End Sub

' Called when bt stream gets new data
Sub astream_NewData (Buffer() As Byte)
    rcvStr = BytesToString(Buffer, 0, Buffer.Length, "UTF8")
    Log("Received: " & rcvStr)
    
End Sub

Private Sub cb_UARTList_ValueChanged (Value As Object)
    MyPort=Value
End Sub

And the error message in the log:

Error from Log:
Waiting for debugger to connect...
Program started.
Com Port: COM3
#
# A fatal error has been detected by the Java Runtime Environment:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x000000006a00b5bb, pid=12880, tid=11536
#
# JRE version: OpenJDK Runtime Environment (11.0.1+13) (build 11.0.1+13)
# Java VM: OpenJDK 64-Bit Server VM (11.0.1+13, mixed mode, tiered, compressed oops, g1 gc, windows-amd64)
# Problematic frame:
# C  [jSSC-2.6_x86_64.dll+0xb5bb]
#
# No core dump will be written. Minidumps are not enabled by default on client versions of Windows
#
# An error report file with more information is saved as:
# D:\Basic4Java\My Apps\Com Port Test\Objects\hs_err_pid12880.log
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#

Many thanks.
Mark
 

Mark Read

Well-Known Member
Licensed User
Longtime User
Thanks Chris2 for your answer but that does not help as I am running in debug mode. I am not finished coding so that I can use the packager. The error occurs immediately after trying to open the COM Port.
 
Upvote 0

Mark Read

Well-Known Member
Licensed User
Longtime User
In the additional libraries folder, I found jscc.jar. This I renamed to jssc-old.jar. Copied the jssc-2.9.4.jar file to this directory and renamed to jssc.jar.

Now my program is working. Thanks Erel.
 
Upvote 0

Didier9

Well-Known Member
Licensed User
I have given up on OpenJDK for apps that use the serial port. I use Oracle's version and serial port problems went poof.
If you use OpenJDK, I suggest you try Oracle instead.
I realize Oracle has turned into somewhat of a monster with java licensing, but their serial implementation works.
 
Upvote 0
Top