#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