B4R Question Log results to different streaming types

Mostez

Well-Known Member
Licensed User
Longtime User
Hello,
I have an arduino mega device with ethernet shield, user may send commands through USB or Ethernet connection then direct these commands to command handler, the problem is i want to direct results from command handler to its source(SendStreamMessage sub), for example how can I send this to both USB and ethernet.

Thanks

B4X:
Log(0x02,CMD_READ,REG_DATE_TIME,0x0C,Years - 2000,Months,DayOfMonth,DayOfWeek,Hours,Minutes,Seconds,0x04)

B4X:
private Sub GetUSBstream(Buffer() As Byte)
    CommandHandler(Buffer,SYS_STREAM_SOURCE_USB)
End Sub

Private Sub GetEthernetStream (Buffer() As Byte)
  CommandHandler(Buffer,SYS_STREAM_SOURCE_ETHERNET)
End Sub

private Sub CommandHandler(Buffer () As Byte, StreamSource As Byte)    
'execute command and send result to SendStreamMessage

End Sub

private Sub SendStreamMessage(Message As String, StreamSource As Byte)
 
    Select StreamSource
        Case SYS_STREAM_SOURCE_USB
         
        Case SYS_STREAM_SOURCE_ETHERNET '????
   End Select
End Sub
 

Mostez

Well-Known Member
Licensed User
Longtime User
Yes Erel, that's what I already have, the problem is, in what form should I pass this line to SendStreamMessage objects (USBstream and EthernetStream)

Thanks

(0x02,CMD_READ,REG_DATE_TIME,0x0C,Years - 2000,Months,DayOfMonth,DayOfWeek,Hours,Minutes,Seconds,0x04)


B4X:
private Sub SendStreamMessage(Message As String, StreamSource As Byte)
    Select StreamSource
        Case SYS_STREAM_SOURCE_USB
         USBstream.Write(...
        Case SYS_STREAM_SOURCE_ETHERNET
        EthernetStream.Write(...
   End Select
End Sub
 
Upvote 0

Mostez

Well-Known Member
Licensed User
Longtime User
I changed the variable type to byte array:

B4X:
private Sub SendStreamMessage(Message() As Byte , StreamSource As Byte)
    Select StreamSource
        Case SYS_STREAM_SOURCE_USB
             USBstream.Write(Message)
        Case SYS_STREAM_SOURCE_ETHERNET
            EthernetStream.Write(Message)
   End Select
End Sub

and passed data like this:

B4X:
SendStreamMessage(Array As Byte (0x02,CMD_READ,REG_DATE_TIME,0x0C,Years - 2000,Months,DayOfMonth,DayOfWeek,Hours,Minutes,Seconds,0x04),
SYS_STREAM_SOURCE_ETHERNET
)

the secret word is 'Array As Byte' , Thanks
 
Upvote 0
Top