B4J Question Slow Serial Connection issue

Gaver Powers

Member
Licensed User
Longtime User
is AsyncStreamsText available in B4J?

I have an Ansyncstreams serial connection fetching values from a weight scale.

Periodically - once an hour or so... the data being obtained from the scale and displayed in a label begins pulsing or flashing and appears out of sequence.

I've tried increasing the baud rate from 9600 to 19200 - with no change or improvement.
Would AsnycStreamsText mode alleviate this problem? (hope so)

B4X:
Sub AStream_NewData (Buffer() As Byte)
    Dim s As String = BytesToString(Buffer, 0, Buffer.Length, "ASCII")   
    LogMessage(s)
End Sub

Sub LogMessage(Msg As String)
   
    lblScale.Text = Msg.Trim
   
End Sub
 

Gaver Powers

Member
Licensed User
Longtime User
Nevermind - found a subroutine was missing in AsyncStreamsText

I'm trying to add the ability to send a text string to the scale.
I added the line
B4X:
ast.Write("P " & Chr(10) & Chr(13))

and the IDE is generating a warning message "Unknown Member: Write"

ast is defined in the Sub Process Globals as

Private ast As AsyncStreamsText

The AsynStreamsText example shows a subroutine in the main page that reads:
B4X:
Sub Activity_Click
  ast.Write("this is an example..." & Chr(10) & Chr(13))
End Sub

How do I write a string to the serial port using AsycStreamsText ?

G
 
Last edited:
Upvote 0

positrom2

Active Member
Licensed User
Longtime User
This works for Me.
B4X:
Private astream1 As AsyncSteamsText 'In Process Globals

' In AppStart:
sp1.Open("COM6")
sp1.Initialize("")
sp1.SetParams(921600,8,1,0)
astream1.Initialize(Me, "astream1",sp1.GetInputStream, sp1.GetOutputStream)

'somewhere:
s1 As String
s1="x"&Chr(13)&Chr(10)
astream1.Write(s1)
 
Upvote 0
Top