B4J Question jserial and Asyncstreams no RX


New Member
Good Afternoon,

Quite new to B4X and VS6 and programming in general and have become stumped on a certain project using a PC's COM port to send and receive serial data

my code is below
#Region Project Attributes
    #MainFormWidth: 600
    #MainFormHeight: 600
#End Region

Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private freqReportLbl As Label
    Private pttOffLbl As Label
    Private pttOnLbl As Label
    Private sidebandReportLbl As Label
    Private sidebandToggleLbl As Label
    Private comportSelect As Button
    Private comportList As ChoiceBox
    Private freqReport As Button
    Private pttOff As Button
    Private pttOn As Button
    Private sidebandReport As Button
    Private sidebandToggle As Button
    Private serial As Serial
    Private AStream As AsyncStreams
    Private portList As List
    Private selectedPort As String
    Private comLbl As Label
    Private serialInText As TextArea
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("Main") 'Load the layout file.
    portList = serial.ListPorts
    comportList.SelectedIndex = 0
    selectedPort = "empty"
End Sub

'Return true to allow the default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
    Return True
End Sub

Sub pttOn_Click
    Dim msg = "0" As String
    pttOffLbl.Text = ""
    pttOnLbl.Text = "PTT On"
End Sub

Sub sidebandToggle_Click
End Sub

Sub sidebandReport_Click
End Sub

Sub pttOff_Click
    Dim msg = "1" As String
    pttOffLbl.Text = "PTT Off"
    pttOnLbl.Text = ""
End Sub

Sub freqReport_Click
End Sub

Sub AStream_NewData (msg() As Byte)
    Dim newMsg =  BytesToString(msg, 0, msg.Length, "UTF8") As String
    serialInText.Text = serialInText.Text & newMsg
End Sub

Sub AStream_Error
End Sub

Sub comportSelect_Click
    If selectedPort = "empty" Then
        comLbl.Text = "Please connect a Serial cable"
        comLbl.Text = selectedPort & " selected"
    End If
End Sub

Sub comportList_SelectedIndexChanged(Index As Int, Value As Object)
    selectedPort = Value
End Sub

Now their is a fair amount of extra things in there that will be used in due course (I can cut that down if needed)

However, the problem is as follows

I can TX serial data, as typed in for example one of the sub routines
Sub pttOn_Click
    Dim msg = "0" As String
    pttOffLbl.Text = ""
    pttOnLbl.Text = "PTT On"
End Sub

and the 0 comes through fine, to another PC
I have changed this to all manner of text messages which have all worked as expected.

Now my RX side is a different matter.

Shorting pins 2+3 for a loop back test show nothing coming back through the RX pin, and putting a break whilst in debug mode shows that sub AStream_NewData is not called.

using the same loop back with for example Realterm or other serial terminal emulators also work correctly, so i believe the hardware is ok.
(usb to serial convertor using a prolific PL203 i think)

So I assume it is something i have missed in my code.

If I cannot crack this I will move on to use the ASyncStreamsText class, however as a learning exercise I'm hoping I can still get this way to work.

Any ideas ?

Any more information needed please let me know.

Many thanks in advance