B4R Question ESP32 and AsyncStreams

Paradicsom

New Member
Hi,
i need to establish a communication with Hardware-serial.
It is not possible to comile this little code.
Using:
- ESP32 DevModule,
- Arduino ide 2.3.10 (Updates for all Boards and librarys
- B4R 4.0

I hope somebody can help

Test-Application:
#Region Project Attributes
    #AutoFlushLogs: True
    #CheckArrayBounds: True
    #StackBufferSize: 300
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'Public variables can be accessed from all modules.
    Public Serial1 As Serial
    'DFÜ mit Nextion
    Private SerialNative2 As Stream
    Private Stream1 As AsyncStreams
    
End Sub

#if C
//HardwareSerial Serial2(2); // second Hardware Port
HardwareSerial Serial2(2);
void SerialNative2(B4R::Object* unused) {
   ::Serial2.begin(9600);
  b4r_main::_serialnative2->wrappedStream = &::Serial2;
}
#end if



Private Sub AppStart
    Serial1.Initialize(115200)
    Log("AppStart")
    
    Dim s As String
    
    Log("Stream initialize")
    Stream1.Initialize(SerialNative2, "Nextion_NewData", "Nextion_Error")
    'Page 1 on Nextion
    s = JoinStrings(Array As String("page 1"))
    Stream1.Write(s.GetBytes).Write(Array As Byte(0xFF, 0xFF, 0xFF))
End Sub

Sub Nextion_NewData(Buffer() As Byte)

End Sub

Sub Nextion_Error(Buffer() As Byte)

End Sub

I get everytime this error-codes (also in older versions):

Error-Codes:
B4R Version: 4.00
Parse den Code.    (0.00s)
Building folders structure.    (0.04s)
Kompiliere den Code.    (0.01s)
Erstelle Projekt    (0.03s)
Compiling (ESP32 Dev Module)    Error
F:\B4R\Projekte\ESP-Test\Objects\src\b4r_main.cpp: In static member function 'static void b4r_main::_appstart()':
F:\B4R\Projekte\ESP-Test\Objects\src\b4r_main.cpp:35:31: error: invalid conversion from 'void (*)(B4R::Array*)' to 'B4R::SubVoidVoid' {aka 'void (*)()'} [-fpermissive]
   35 | b4r_main::_stream1->Initialize(b4r_main::_serialnative2,_nextion_newdata,_nextion_error);
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                               |
      |                               void (*)(B4R::Array*)
In file included from F:\B4R\Projekte\ESP-Test\Objects\src\B4RDefines.h:25,
                 from F:\B4R\Projekte\ESP-Test\Objects\src\b4r_main.cpp:1:
F:\B4R\Projekte\ESP-Test\Objects\src\rRandomAccessFile.h:199:98: note:   initializing argument 3 of 'void B4R::AsyncStreams::Initialize(B4R::B4RStream*, B4R::SubVoidArray, B4R::SubVoidVoid)'
  199 |                         void Initialize (B4RStream* Stream, SubVoidArray NewDataSub, SubVoidVoid ErrorSub);
      |                                                                                      ~~~~~~~~~~~~^~~~~~~~
Fehler beim Build: exit status 1
 

Paradicsom

New Member
Hi,
i need to establish a communication with Hardware-serial.
It is not possible to comile this little code.
Using:
- ESP32 DevModule,
- Arduino ide 2.3.10 (Updates for all Boards and librarys
- B4R 4.0

I hope somebody can help

Test-Application:
#Region Project Attributes
    #AutoFlushLogs: True
    #CheckArrayBounds: True
    #StackBufferSize: 300
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'Public variables can be accessed from all modules.
    Public Serial1 As Serial
    'DFÜ mit Nextion
    Private SerialNative2 As Stream
    Private Stream1 As AsyncStreams
  
End Sub

#if C
//HardwareSerial Serial2(2); // second Hardware Port
HardwareSerial Serial2(2);
void SerialNative2(B4R::Object* unused) {
   ::Serial2.begin(9600);
  b4r_main::_serialnative2->wrappedStream = &::Serial2;
}
#end if



Private Sub AppStart
    Serial1.Initialize(115200)
    Log("AppStart")
  
    Dim s As String
  
    Log("Stream initialize")
    Stream1.Initialize(SerialNative2, "Nextion_NewData", "Nextion_Error")
    'Page 1 on Nextion
    s = JoinStrings(Array As String("page 1"))
    Stream1.Write(s.GetBytes).Write(Array As Byte(0xFF, 0xFF, 0xFF))
End Sub

Sub Nextion_NewData(Buffer() As Byte)

End Sub

Sub Nextion_Error(Buffer() As Byte)

End Sub

I get everytime this error-codes (also in older versions):

Error-Codes:
B4R Version: 4.00
Parse den Code.    (0.00s)
Building folders structure.    (0.04s)
Kompiliere den Code.    (0.01s)
Erstelle Projekt    (0.03s)
Compiling (ESP32 Dev Module)    Error
F:\B4R\Projekte\ESP-Test\Objects\src\b4r_main.cpp: In static member function 'static void b4r_main::_appstart()':
F:\B4R\Projekte\ESP-Test\Objects\src\b4r_main.cpp:35:31: error: invalid conversion from 'void (*)(B4R::Array*)' to 'B4R::SubVoidVoid' {aka 'void (*)()'} [-fpermissive]
   35 | b4r_main::_stream1->Initialize(b4r_main::_serialnative2,_nextion_newdata,_nextion_error);
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                               |
      |                               void (*)(B4R::Array*)
In file included from F:\B4R\Projekte\ESP-Test\Objects\src\B4RDefines.h:25,
                 from F:\B4R\Projekte\ESP-Test\Objects\src\b4r_main.cpp:1:
F:\B4R\Projekte\ESP-Test\Objects\src\rRandomAccessFile.h:199:98: note:   initializing argument 3 of 'void B4R::AsyncStreams::Initialize(B4R::B4RStream*, B4R::SubVoidArray, B4R::SubVoidVoid)'
  199 |                         void Initialize (B4RStream* Stream, SubVoidArray NewDataSub, SubVoidVoid ErrorSub);
      |                                                                                      ~~~~~~~~~~~~^~~~~~~~
Fehler beim Build: exit status 1

Hi,
i need to establish a communication with Hardware-serial.
It is not possible to comile this little code.
Using:
- ESP32 DevModule,
- Arduino ide 2.3.10 (Updates for all Boards and librarys
- B4R 4.0

I hope somebody can help

Test-Application:
#Region Project Attributes
    #AutoFlushLogs: True
    #CheckArrayBounds: True
    #StackBufferSize: 300
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'Public variables can be accessed from all modules.
    Public Serial1 As Serial
    'DFÜ mit Nextion
    Private SerialNative2 As Stream
    Private Stream1 As AsyncStreams
   
End Sub

#if C
//HardwareSerial Serial2(2); // second Hardware Port
HardwareSerial Serial2(2);
void SerialNative2(B4R::Object* unused) {
   ::Serial2.begin(9600);
  b4r_main::_serialnative2->wrappedStream = &::Serial2;
}
#end if



Private Sub AppStart
    Serial1.Initialize(115200)
    Log("AppStart")
   
    Dim s As String
   
    Log("Stream initialize")
    Stream1.Initialize(SerialNative2, "Nextion_NewData", "Nextion_Error")
    'Page 1 on Nextion
    s = JoinStrings(Array As String("page 1"))
    Stream1.Write(s.GetBytes).Write(Array As Byte(0xFF, 0xFF, 0xFF))
End Sub

Sub Nextion_NewData(Buffer() As Byte)

End Sub

Sub Nextion_Error(Buffer() As Byte)

End Sub

I get everytime this error-codes (also in older versions):

Error-Codes:
B4R Version: 4.00
Parse den Code.    (0.00s)
Building folders structure.    (0.04s)
Kompiliere den Code.    (0.01s)
Erstelle Projekt    (0.03s)
Compiling (ESP32 Dev Module)    Error
F:\B4R\Projekte\ESP-Test\Objects\src\b4r_main.cpp: In static member function 'static void b4r_main::_appstart()':
F:\B4R\Projekte\ESP-Test\Objects\src\b4r_main.cpp:35:31: error: invalid conversion from 'void (*)(B4R::Array*)' to 'B4R::SubVoidVoid' {aka 'void (*)()'} [-fpermissive]
   35 | b4r_main::_stream1->Initialize(b4r_main::_serialnative2,_nextion_newdata,_nextion_error);
      | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                               |
      |                               void (*)(B4R::Array*)
In file included from F:\B4R\Projekte\ESP-Test\Objects\src\B4RDefines.h:25,
                 from F:\B4R\Projekte\ESP-Test\Objects\src\b4r_main.cpp:1:
F:\B4R\Projekte\ESP-Test\Objects\src\rRandomAccessFile.h:199:98: note:   initializing argument 3 of 'void B4R::AsyncStreams::Initialize(B4R::B4RStream*, B4R::SubVoidArray, B4R::SubVoidVoid)'
  199 |                         void Initialize (B4RStream* Stream, SubVoidArray NewDataSub, SubVoidVoid ErrorSub);
      |                                                                                      ~~~~~~~~~~~~^~~~~~~~
Fehler beim Build: exit status 1
Ok,
after correcting the Error-Sub (stupid error) it is possible to compile !

But the ESP32 reboot endless.
Error Code: Guru Meditation Error: Core 1 panic'ed (LoadProhibited). Exception was unhandled.

When i uncomment the Stream1.Initialize Line, it works normally.
The same problem (endless rebooting) when i use the following Code tu use serial3 with free Pin's
Code:
'RX=12 (DI), TX=13 (D0) 
#if C
HardwareSerial Serial3(3); // Third Serial Port
void SerialNative3(B4R::Object* unused)
{
::Serial3.begin(9600, SERIAL_8N1, 12, 13);
b4r_main::_serialnative3->wrappedStream = &::Serial3;
}
#End If

Some ideas ??
 
Upvote 0

embedded

Active Member
Licensed User
Longtime User
WORKING EXAMPLE OF TWO UART OF ESP32....THIRD UART IS NOT USED TILL NOW...


ESP32 SERIAL BRIDGE:
#Region Project Attributes
    #AutoFlushLogs: True
    #CheckArrayBounds: True
    #StackBufferSize: 2000
#End Region
'Ctrl+Click to open the C code folder: ide://run?File=%WINDIR%\System32\explorer.exe&Args=%PROJECT%\Objects\Src

Sub Process_Globals
    Public Serial1 As Serial
    Private wifi As ESP8266WiFi
    Private SerialNative2 As Stream
    Public Timer1 As Timer
    Dim Counter,This_DeviceId As Int
    Public mylcd As LiquidCrystal_I2C
    Dim bc As ByteConverter
    Dim ledPin,RelayPin,gsmON As Pin
    Public astream As AsyncStreams
    Dim bc As ByteConverter
    Dim bond_buffer(50) As Byte
    Dim bond_pointer As Byte=0
    Dim reyaxReset As Pin
End Sub

'this bunch of code make bridge between two UART Port of ESP32
'UART1 TX----Connected to---UART2---Tx
'UART2 Rx----Connected to---UART1---Rx
'with the help of this code PC and send data to a UART DEVICE
'Date-06/10/23
'TESTED WITH GSM MODEM WORKING OK----------HTTP POST DATA WORKING OK...
Private Sub AppStart
    Serial1.Initialize(115200)
    Log("AppStart")
   
    'example of connecting to a local network
    ledPin.Initialize(2,ledPin.MODE_OUTPUT)
    RelayPin.Initialize(5,ledPin.MODE_OUTPUT)
    gsmON.Initialize(32,gsmON.MODE_OUTPUT)
    gsmON.DigitalWrite(True)
    ledPin.DigitalWrite(False)
    RelayPin.DigitalWrite(False)
    reyaxReset.Initialize(33,reyaxReset.MODE_OUTPUT)
    reyaxReset.DigitalWrite(False)
    Delay(50)'appstart
    reyaxReset.DigitalWrite(True)
    Timer1.Initialize("Timer1_Tick",2000)
    Timer1.Enabled=True
    Counter=0
    astream.Initialize(Serial1.Stream,"astream_Newdata","astream_Error")
    astream.MaxBufferSize=512
    astream.WaitForMoreDataDelay=100
    Delay(2000)
    RunNative("SerialNative2",Null)
    This_DeviceId=112
End Sub

Sub Timer1_Tick
    Read_Serial2_Data
    Counter=Counter+1
    ledPin.DigitalWrite(Not(ledPin.DigitalRead))
End Sub





Sub Astream_NewData (Buffer() As Byte)
    Log(Buffer)
    SerialNative2.WriteBytes(Buffer,0,Buffer.Length)
End Sub

Sub AStream_Error
    Log("error")
End Sub

#if C
// Second Hardware Port
void SerialNative2(B4R::Object* unused)
{
::Serial2.begin(115200);
b4r_main::_serialnative2->wrappedStream = &::Serial2;
}
#End If

Sub Read_Serial2_Data
    Log("READING UART2---")
    Dim AvailableByte As Int
    AvailableByte=SerialNative2.BytesAvailable
    If AvailableByte>0 Then
        Dim Buff(AvailableByte) As Byte
        SerialNative2.ReadBytes(Buff,0,AvailableByte)
        Log(Buff)
    End If
End Sub
 
Upvote 0

Paradicsom

New Member
WORKING EXAMPLE OF TWO UART OF ESP32....THIRD UART IS NOT USED TILL NOW...


ESP32 SERIAL BRIDGE:
#Region Project Attributes
    #AutoFlushLogs: True
    #CheckArrayBounds: True
    #StackBufferSize: 2000
#End Region
'Ctrl+Click to open the C code folder: ide://run?File=%WINDIR%\System32\explorer.exe&Args=%PROJECT%\Objects\Src

Sub Process_Globals
    Public Serial1 As Serial
    Private wifi As ESP8266WiFi
    Private SerialNative2 As Stream
    Public Timer1 As Timer
    Dim Counter,This_DeviceId As Int
    Public mylcd As LiquidCrystal_I2C
    Dim bc As ByteConverter
    Dim ledPin,RelayPin,gsmON As Pin
    Public astream As AsyncStreams
    Dim bc As ByteConverter
    Dim bond_buffer(50) As Byte
    Dim bond_pointer As Byte=0
    Dim reyaxReset As Pin
End Sub

'this bunch of code make bridge between two UART Port of ESP32
'UART1 TX----Connected to---UART2---Tx
'UART2 Rx----Connected to---UART1---Rx
'with the help of this code PC and send data to a UART DEVICE
'Date-06/10/23
'TESTED WITH GSM MODEM WORKING OK----------HTTP POST DATA WORKING OK...
Private Sub AppStart
    Serial1.Initialize(115200)
    Log("AppStart")
  
    'example of connecting to a local network
    ledPin.Initialize(2,ledPin.MODE_OUTPUT)
    RelayPin.Initialize(5,ledPin.MODE_OUTPUT)
    gsmON.Initialize(32,gsmON.MODE_OUTPUT)
    gsmON.DigitalWrite(True)
    ledPin.DigitalWrite(False)
    RelayPin.DigitalWrite(False)
    reyaxReset.Initialize(33,reyaxReset.MODE_OUTPUT)
    reyaxReset.DigitalWrite(False)
    Delay(50)'appstart
    reyaxReset.DigitalWrite(True)
    Timer1.Initialize("Timer1_Tick",2000)
    Timer1.Enabled=True
    Counter=0
    astream.Initialize(Serial1.Stream,"astream_Newdata","astream_Error")
    astream.MaxBufferSize=512
    astream.WaitForMoreDataDelay=100
    Delay(2000)
    RunNative("SerialNative2",Null)
    This_DeviceId=112
End Sub

Sub Timer1_Tick
    Read_Serial2_Data
    Counter=Counter+1
    ledPin.DigitalWrite(Not(ledPin.DigitalRead))
End Sub





Sub Astream_NewData (Buffer() As Byte)
    Log(Buffer)
    SerialNative2.WriteBytes(Buffer,0,Buffer.Length)
End Sub

Sub AStream_Error
    Log("error")
End Sub

#if C
// Second Hardware Port
void SerialNative2(B4R::Object* unused)
{
::Serial2.begin(115200);
b4r_main::_serialnative2->wrappedStream = &::Serial2;
}
#End If

Sub Read_Serial2_Data
    Log("READING UART2---")
    Dim AvailableByte As Int
    AvailableByte=SerialNative2.BytesAvailable
    If AvailableByte>0 Then
        Dim Buff(AvailableByte) As Byte
        SerialNative2.ReadBytes(Buff,0,AvailableByte)
        Log(Buff)
    End If
End Sub
Thanks,
Beginner's Mistakes: forget to call SerialNative2,
Application now run,
but for send/receive data over the second port i must change ::Serial2.begin(9600); to ::Serial2.begin(9600, SERIAL_8N1, 16, 17);
why don't now, but it works.
 
Upvote 0

embedded

Active Member
Licensed User
Longtime User
Here I found something about 3rd serial port of ESP32...TRY it...https://www.b4x.com/android/forum/threads/solved-esp32-3rd-serial-port.134107/
 
Upvote 0
Top