B4R Question How to use global arrays from inline C

janderkan

Active Member
Licensed User
This code will get the Mac-addres from a Wemos D1 Mini.

I would like to use the MacArray directly from C using b4r_main::_macarray = MAC_array;
But gets this error 'cannot convert 'uint8_t [6] {aka unsigned char [6]}' to 'B4R::Array*' in assignment'

B4X:
sub Process_Globals  
    Dim MacArray(6) As Byte
    Dim M1,M2,M3,M4,M5,M6 As Byte            'ignore
End Sub

Sub MacAddress() As Byte()
    RunNative("getMac", Null)
    bc.ArrayCopy(Array As Byte(M1,M2,M3,M4,M5,M6),MacArray)
    Return MacArray
End Sub
#if C
    #include <ESP8266WiFi.h>
    uint8_t MAC_array[6];
    void getMac(B4R::Object* u) {
         WiFi.macAddress(MAC_array);
         b4r_main::_m1 = MAC_array[0];
         b4r_main::_m2 = MAC_array[1];
         b4r_main::_m3 = MAC_array[2];
         b4r_main::_m4 = MAC_array[3];
         b4r_main::_m5 = MAC_array[4];
         b4r_main::_m6 = MAC_array[5];
    }
#end if
 

Erel

Administrator
Staff member
Licensed User
Reading the Mac address:

B4X:
Sub Process_Globals  
    Public Serial1 As Serial
  Dim MacArray(6) As Byte
   Private bc As ByteConverter
End Sub


Private Sub AppStart
  Serial1.Initialize(115200)
  Log("AppStart")
  Log(bc.HexFromBytes(MacAddress))
End Sub

Sub MacAddress() As Byte()
  RunNative("getMac", Null)
  Return MacArray
End Sub
#if C
  #include <ESP8266WiFi.h>
  void getMac(B4R::Object* u) {
  WiFi.macAddress((Byte*)b4r_main::_macarray->data);
  }
#end if
 
Upvote 0
Top