B4J Question jserial and Asyncstreams no RX

LawrenceD

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
B4X:
#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.
    MainForm.Show
    serial.Initialize("")
    AStream.Initialize(serial.GetInputStream,serial.GetOutputStream,"AStream")
    portList = serial.ListPorts
    comportList.Items.AddAllAt(0,portList)
    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
    AStream.Write(msg.GetBytes("UTF8"))
    Log(msg)
    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
    AStream.Write(msg.GetBytes("UTF8"))
    Log(msg)
    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
    Log(serialInText.Text)
    serialInText.RequestFocus
End Sub

Sub AStream_Error
    Log("error")
End Sub

Sub comportSelect_Click
    serial.Close
    If selectedPort = "empty" Then
        comLbl.Text = "Please connect a Serial cable"
    Else
        serial.Open(selectedPort)
        serial.SetParams(9600,8,1,0)
        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
B4X:
Sub pttOn_Click
    Dim msg = "0" As String
    AStream.Write(msg.GetBytes("UTF8"))
    Log(msg)
    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
Lawrence
 
Top