B4R Question bytes ans const

Hi everyone,

I am trying to do something in B4R with the code I post here but for some reason that I cant understand I have an error in the code.
Any help please?


Thank you


#Region Project Attributes
#AutoFlushLogs: True
#CheckArrayBounds: True
#StackBufferSize: 300
#End Region

Sub Process_Globals

Public astream As AsyncStreams
Public ReceivedCommand() As Byte
Public Serial1 As Serial
Public bc As ByteConverter
End Sub

Private Sub AppStart

Serial1.Initialize(115200)
astream.Initialize(Serial1.Stream, "Astream_NewData", "Astream_Error")
'

End Sub
Sub Astream_NewData (Buffer() As Byte)

ReceivedCommand = bc.SubString2(Buffer, 0,2) ' <<<<<< This line dont compile with
' Main - 25: Cannot modify Const variable. (global non-primitive variables are always constants.)



Log("ReceivedCommand: ", ReceivedCommand)

End Sub

Sub AStream_Error
Log("error")
End Sub
 

candide

Active Member
Licensed User
Public ReceivedCommand() As Byte => it is global variable without size and it is const

i didn't test but you can change in this way:
B4X:
Sub Astream_NewData (Buffer() As Byte)   
   dim ReceivedCommand() = bc.SubString2(Buffer, 0,2)                               
   Log("ReceivedCommand: ", ReceivedCommand)   
End Sub
 
Upvote 0
Top