Android Question Astreams Question

Harris

Expert
Licensed User
Longtime User
Using the subs below, I am connecting to a weigh scale controller thru an AP from my app.
All works great. I get the weight value with no problem.

However, if a device is already connected to the scale controller, another attempt by another device will cause the "Successful" of Scalecontroller_Connected to return false. The second connection must enter the weight thru an input form since it can't get the weight automatically.

It seems to me the port (10001) can only handle one connection at a time..
Is this true - or any way to allow multiple connections?

Thanks


B4X:
Sub StartScale
    
    SetIPAddress   ' set the ip for ScaleIP
    
    sock.Initialize("Scalecontroller")
'    sock.Connect("10.131.199.50", 10001, 10000) - for testing
    sock.Connect(ScaleIP,   10001, 20000)
'    sock.Connect(IP,   port number, time out in ms)    
'    ToastMessageShow(" Connecting to Scale Controller... ",False)

End Sub

Sub Scalecontroller_Connected (Successful As Boolean)
    Log($"Scalecontroller_Connected: (${Successful})"$)
    If Successful Then
        AStreams.Initialize( sock.InputStream,  Null, "Scale")
    Else
        ToastMessageShow(" Connection to Scale Controller Failed! ",True)
        SetWeight       
    End If       
    
    
End Sub
 

Harris

Expert
Licensed User
Longtime User
I guess that your scale controller can only support a single client at a time.

Make sure to close the connection from the client when you are done reading the data.

Seems so, and I do close the connection each time for sure...

Actually, the users can see if another vehicle is on the scale - using the system - so they can wait their turn...
I guess this is the only practical solution:

B4X:
Sub Scalecontroller_Connected (Successful As Boolean)
    Log($"Scalecontroller_Connected: (${Successful})"$)
    If Successful Then
        AStreams.Initialize( sock.InputStream,  Null, "Scale")
    Else
Msgbox2Async("Seems Scale is Being Used By Another","Wait!","Try Again","Cancel","Manual Entry",Null,False)
Wait For Msgbox_Result (Result As Int)
If Result = DialogResponse.POSITIVE Then
    ' try again
Else if  Result = DialogResponse.NEGATIVE
        SetWeight    ' manual entry with input dialog   
End If
    End If       
    
    
End Sub
 
Upvote 0
Top