B4R Question AsyncStreams + AnalogRead

Ilya G.

Active Member
Licensed User
Longtime User
When I try to send Astream.Write(Pin0.AnalogRead) or Astream.Write(bc.UIntsToBytes(Pin0.AnalogRead)) it appears error {Type=UInt,Rank=0, RemoteObject=True} to: {Type=UInt,Rank=1, RemoteObject=True}

What can I do?
 

Peter Simpson

Expert
Licensed User
Longtime User
Please do not delete your posts after you create them.

You deleted a post (which was post number #3) with your code and error message that I responded to. Now nobody can learn from your mistakes and it makes this current post of mine look like I'm answering to fresh air, when I was in fact rewriting the code that you posted in the original post #3. You obviously deleted the post as I was responding to your question completely wasting my precious time.


@GanjaKyp thank you for posting your code and log error message. I take it that you didn't use tab 'Tab' after typing Sub then a space to select the type?

Below is the code that you need.
B4X:
#Region Project Attributes
    #AutoFlushLogs: True
    #CheckArrayBounds: True
    #StackBufferSize: 300
#End Region

Sub Process_Globals
    Public Serial1 As Serial
    Public WiFi As ESP8266WiFi
    Public astream As AsyncStreams
    Public server As WiFiServerSocket
    Public bc As ByteConverter
    Public PinA0 As Pin
    Public timer1 As Timer
End Sub

Sub AppStart
    Serial1.Initialize(115200)
    Log(CRLF, "App started")

    PinA0.Initialize(PinA0.A0, PinA0.MODE_INPUT)

    WiFi.Connect2("*******", "*******")
    server.Initialize(12000,  "server_newnonnection")
    server.Listen

    timer1.Initialize("myTickSub", 1000)
    timer1.Enabled = True
End Sub

Sub myTickSub
    astream.Write(Array As Byte(PinA0.AnalogRead))
End Sub

Sub server_newnonnection (NewSocket As WiFiSocket)
    astream.Initialize(NewSocket.Stream, "astream_NewData", "astream_Error")
End Sub

Sub astream_NewData (Buffer() As Byte)

End Sub

Sub astream_Error

End Sub

Enjoy...
 
Last edited:
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
@GanjaKyp you will find it easier to type Sub followed by a space then hit the Tab key, you will see the following event declaration for AsyncStream.

1.png


2.png


3.png


Please watch this YouTube video, it will help you a lot. Actually I personally think that @Erel should in fact make this video more prominent (a sticky) on this forum somewhere, or make an updated video and post that prominently on this forum somewhere, it's a really helpful video but I'm more than sure that 99%+ of user do not know about it.



Enjoy...
 
Upvote 0
Top