B4J Question Serial Communication between ESP32 and Desktop PC - B4J

JacoMuller

Member
Licensed User
Longtime User
I am working on a project where I use an ESP32 to connect to the CAN Bus of a vehicle. I want to create small desktop App to read the data from the ESP32 with a USB Cable and display the data in a table. I have used Arduino IDE to develop a sketch for the EPS32 and that works well. I can see all the data in SavvyCAN. I now want to make my own tool to reverse engineer the CAN Data. the Idea was to use B4J but this will be my first B4J project. I have done many VB projects before. The issue I am facing is to get the Serial communication going. I have used ChatGPT but we are only going in circles.

This is my (ChatGPT) code:
B4X:
#Region Project Attributes

    #MainFormWidth: 900

    #MainFormHeight: 600

#End Region



Sub Process_Globals

    Private fx As JFX

    Private MainForm As Form



    Private Serial1 As Serial

    Private AStream As AsyncStreams



    Private btnConnect As Button

    Private cmbPorts As ComboBox

    Private txtLog As TextArea

End Sub



Sub AppStart (Form1 As Form, Args() As String)



    MainForm = Form1

    MainForm.RootPane.LoadLayout("Main")



    Serial1.Initialize("Serial1")



    Dim Ports As List = Serial1.ListPorts



    For Each p As String In Ports

        cmbPorts.Items.Add(p)

    Next



    If cmbPorts.Items.Size > 0 Then

        cmbPorts.SelectedIndex = 0

    End If
 
Last edited:

besoft

Active Member
Licensed User
Longtime User
Hello,

It's hard to tell much from this code. Could you describe your issue in more detail so we can understand what you're trying to do?

Is this the complete code? There are quite a few things missing for it to work.
 
Upvote 0

JacoMuller

Member
Licensed User
Longtime User
Sorry, you are right :). I should have explained the issue. I have the following libraries selected: jXUI, jSerial, jNetwork, jFX and jCore.
 

Attachments

  • CAN Bus Sniffer - Stage 1.b4j.zip
    6.9 KB · Views: 4
Upvote 0

besoft

Active Member
Licensed User
Longtime User
Hi,
if I understand correctly, you need serial communication between B4J and Arduino?

What kind of data is expected from the Arduino device?
What is being sent to the Arduino?
 
Upvote 0

JacoMuller

Member
Licensed User
Longtime User
Hi,
if I understand correctly, you need serial communication between B4J and Arduino?

What kind of data is expected from the Arduino device?
What is being sent to the Arduino?
Hi,
Thank you for your time. I have an ESP32 connected to a vehicle's CAN Bus. The data is in the format for SavvyCAN. The ESP32 module works fine and I can see the data in the SavvyCAN app on my laptop. I want to create my own app with B4J to customise it for my specific requirements.
 
Upvote 0

teddybear

Well-Known Member
Licensed User
Why doesn't the PC use TCP to connect to the WiFi AP of the ESP32? that would make things simpler.
 
Upvote 0
Top