B4R Question Set Int Array from Inline C

hatzisn

Expert
Licensed User
Longtime User
This code fails. Can anyone tell me why:

The highlighed lines fail:
#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
    Dim b(8) As Int
    Dim tim As Timer
    
End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
    Log("AppStart")
    SetBArray
    Log(b(0))
    Log(b(1))
    Log(b(2))
    tim.Initialize("tim_Tick", 1000)
End Sub

Sub tim_Tick
    
End Sub

Sub SetBArray
    RunNative("setb", Null)
End Sub

#if C
void setb (B4R::Object* o) { 
    b4r_main::_b[0] = B11111100;
    b4r_main::_b[1] = B01100000;
    b4r_main::_b[2] = B11111111;
}
#End If

B4R Version: 3.30
Parsing code. (0.01s)
Building folders structure. (0.12s)
Compiling code. (0.03s)
Building project (0.04s)
Compiling & deploying Ino project (Arduino/Genuino Mega or Mega 2560 - COM3) Error
Loading configuration...
Initializing packages...
Preparing boards...
Verifying...
C:\Users\dhqin\Dropbox\DOCS\B4X\b4r\MyCode\TestApps\7BITDI~1\Objects\bin\sketch\b4r_main.cpp: In function 'void setb(B4R::Object*)':
b4r_main.cpp:13:18: error: no match for 'operator=' (operand types are 'B4R::Array' and 'int')
b4r_main::_b[0] = B11111100;
^
In file included from C:\Users\dhqin\Dropbox\DOCS\B4X\b4r\MyCode\TestApps\7BITDI~1\Objects\bin\sketch\B4RDefines.h:24:0,
from C:\Users\dhqin\Dropbox\DOCS\B4X\b4r\MyCode\TestApps\7BITDI~1\Objects\bin\sketch\b4r_main.cpp:1:
C:\Users\dhqin\Dropbox\DOCS\B4X\b4r\MyCode\TestApps\7BITDI~1\Objects\bin\sketch\rCore.h:39:8: note: candidate: B4R::Array& B4R::Array::eek:perator=(const B4R::Array&)
class Array {
^
C:\Users\dhqin\Dropbox\DOCS\B4X\b4r\MyCode\TestApps\7BITDI~1\Objects\bin\sketch\rCore.h:39:8: note: no known conversion for argument 1 from 'int' to 'const B4R::Array&'
C:\Users\dhqin\Dropbox\DOCS\B4X\b4r\MyCode\TestApps\7BITDI~1\Objects\bin\sketch\rCore.h:39:8: note: candidate: B4R::Array& B4R::Array::eek:perator=(B4R::Array&&)
C:\Users\dhqin\Dropbox\DOCS\B4X\b4r\MyCode\TestApps\7BITDI~1\Objects\bin\sketch\rCore.h:39:8: note: no known conversion for argument 1 from 'int' to 'B4R::Array&&'
b4r_main.cpp:14:18: error: no match for 'operator=' (operand types are 'B4R::Array' and 'int')
b4r_main::_b[1] = B01100000;
^
In file included from C:\Users\dhqin\Dropbox\DOCS\B4X\b4r\MyCode\TestApps\7BITDI~1\Objects\bin\sketch\B4RDefines.h:24:0,
from C:\Users\dhqin\Dropbox\DOCS\B4X\b4r\MyCode\TestApps\7BITDI~1\Objects\bin\sketch\b4r_main.cpp:1:
C:\Users\dhqin\Dropbox\DOCS\B4X\b4r\MyCode\TestApps\7BITDI~1\Objects\bin\sketch\rCore.h:39:8: note: candidate: B4R::Array& B4R::Array::eek:perator=(const B4R::Array&)
class Array {
^
C:\Users\dhqin\Dropbox\DOCS\B4X\b4r\MyCode\TestApps\7BITDI~1\Objects\bin\sketch\rCore.h:39:8: note: no known conversion for argument 1 from 'int' to 'const B4R::Array&'
C:\Users\dhqin\Dropbox\DOCS\B4X\b4r\MyCode\TestApps\7BITDI~1\Objects\bin\sketch\rCore.h:39:8: note: candidate: B4R::Array& B4R::Array::eek:perator=(B4R::Array&&)
C:\Users\dhqin\Dropbox\DOCS\B4X\b4r\MyCode\TestApps\7BITDI~1\Objects\bin\sketch\rCore.h:39:8: note: no known conversion for argument 1 from 'int' to 'B4R::Array&&'
b4r_main.cpp:15:18: error: no match for 'operator=' (operand types are 'B4R::Array' and 'int')
b4r_main::_b[2] = B11111111;
^
In file included from C:\Users\dhqin\Dropbox\DOCS\B4X\b4r\MyCode\TestApps\7BITDI~1\Objects\bin\sketch\B4RDefines.h:24:0,
from C:\Users\dhqin\Dropbox\DOCS\B4X\b4r\MyCode\TestApps\7BITDI~1\Objects\bin\sketch\b4r_main.cpp:1:
C:\Users\dhqin\Dropbox\DOCS\B4X\b4r\MyCode\TestApps\7BITDI~1\Objects\bin\sketch\rCore.h:39:8: note: candidate: B4R::Array& B4R::Array::eek:perator=(const B4R::Array&)
class Array {
^
C:\Users\dhqin\Dropbox\DOCS\B4X\b4r\MyCode\TestApps\7BITDI~1\Objects\bin\sketch\rCore.h:39:8: note: no known conversion for argument 1 from 'int' to 'const B4R::Array&'
C:\Users\dhqin\Dropbox\DOCS\B4X\b4r\MyCode\TestApps\7BITDI~1\Objects\bin\sketch\rCore.h:39:8: note: candidate: B4R::Array& B4R::Array::eek:perator=(B4R::Array&&)
C:\Users\dhqin\Dropbox\DOCS\B4X\b4r\MyCode\TestApps\7BITDI~1\Objects\bin\sketch\rCore.h:39:8: note: no known conversion for argument 1 from 'int' to 'B4R::Array&&'
exit status 1
 

thetahsk

Active Member
Licensed User
Longtime User

Try this:
B4X:
#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
    Dim b(8) As Byte
    Dim tim As Timer
   
End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
    Log("AppStart")
    SetBArray
    Log(b(0))
    Log(b(1))
    Log(b(2))
    tim.Initialize("tim_Tick", 1000)
End Sub

Sub tim_Tick
   
End Sub

Sub SetBArray
    RunNative("setb", Null)
End Sub

#if C
void setb (B4R::Object* o) {
    ((byte*)b4r_main::_b->data)[0]=B11111111;
    ((byte*)b4r_main::_b->data)[1]=B1111111;
    ((byte*)b4r_main::_b->data)[2]=B111111;
   
   
}
#End If
 
Upvote 0

hatzisn

Expert
Licensed User
Longtime User
Try this:
B4X:
#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
    Dim b(8) As Byte
    Dim tim As Timer
   
End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
    Log("AppStart")
    SetBArray
    Log(b(0))
    Log(b(1))
    Log(b(2))
    tim.Initialize("tim_Tick", 1000)
End Sub

Sub tim_Tick
   
End Sub

Sub SetBArray
    RunNative("setb", Null)
End Sub

#if C
void setb (B4R::Object* o) {
    ((byte*)b4r_main::_b->data)[0]=B11111111;
    ((byte*)b4r_main::_b->data)[1]=B1111111;
    ((byte*)b4r_main::_b->data)[2]=B111111;
   
   
}
#End If

Thank you thetahsk for your answer. I will try that a.s.a.p. Meanwhile I am wondering about this piece of code:

((byte*)b4r_main::_b->data)

I understand (I think) what It does partially. I think it casts the b4rmain::_b to byte but I cannot understand the "->data" part. What does it do?
 
Upvote 0
Top