B4R Question How to use global arrays from inline C

Discussion in 'B4R Questions' started by janderkan, Jul 7, 2016.

Similar threads

B4R Tutorial Inline C / C++
B4R Tutorial HC 05 Classic Bluetooth
B4R Tutorial Additional Hardware Serial Ports
B4R Code Snippet GFX and Bitmaps
B4R Tutorial Big/Large Alphanumeric Characters(LCD1602)
  1. janderkan

    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'

    Code:
    sub Process_Globals  
        
    Dim MacArray(6As 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
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Reading the Mac address:

    Code:
    Sub Process_Globals  
        
    Public Serial1 As Serial
      
    Dim MacArray(6As 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
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice