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:
And the error message in the log:
Many thanks.
Mark
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