B4J Question 3g usb modem and AT commands

linuxmentana

Member
Licensed User
Hi,
I’m trying to port a software of mine (vb6) to b4j
but I don’t understand how to send AT commands to my 3g modem (I see it in com3 in Windows)
Could you please help me?
 

linuxmentana

Member
Licensed User
Thank you very Much 😃
Today I was able to command my gsm modem!

now I’d like to handle the code to wait the modem answers , read them and then reply.

suggestions ? 🙏
 
Upvote 0

bdunkleysmith

Active Member
Licensed User
Longtime User
To send AT commands and handle modem responses I suggest you look at the AsyncStreamsText class. I have found it very good and easy to implement when you just need to send and receive strings (text).

Here's a skeleton of some B4J code which you could use to send AT commands and then process the responses:

B4X:
Sub Process_Globals

    Private sp As Serial
    Private ast As AsyncStreamsText   

End Sub

Sub AppStart (Form1 As Form, Args() As String)

    sp.SetParams(115200,8,1,0)    ' Set speed, etc.
    ast.Initialize(Me, "ast", sp.GetInputStream, sp.GetOutputStream)
    
End Sub

Sub ast_NewText(Text As String)
    
    Log (Text)    ' Process received string here

End Sub

Sub btnAT_Click

   ast.Write("AT..." & Chr(10) & Chr(13))    ' Send AT command as a string here

End Sub
 
Upvote 0
Top