B4R Question How to use global arrays from inline C

janderkan

Well-Known Member
Licensed User
Longtime 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

B4X founder
Staff member
Licensed User
Longtime 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

candide

Active Member
Licensed User
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
but if we want to make a return from inlineC to B4R with an arraybyte in an object, how can we process ?
i did some tests but without success....
 
Upvote 0
Top