News:

;) This forum is the property of Proton software developers

Main Menu

Procedure for talking to a modem

Started by Peter Truman, Jul 02, 2023, 07:24 AM

Previous topic - Next topic

Peter Truman

Hi - I'm writing a procedure to communicate with a Telit ME910 modem module

It works ok for far but I find myself wondering if I have approached this problem properly, or in the most efficient manner.

This is what I have so far - I have my serial buffer setup to flag when the modem returns the third /r (which marks the end of the msg)

' Procedure to talk to the modem and wait for a response. Then process the response for analysis in the main program
Proc P_Modem(S_Mod_String As String * 20),String * 20                                       'Send a String to the Modem - return filtered response
Dim B_Len As Byte                                                                           '
Dim B_Len2 As Byte                                                                          'internal vars
Dim B_Timer As Byte                                                                         '

B_Len=Len(S_Mod_String)                                                                     'This is the length of my msg out
B_Len=B_Len+3                                                                               'account for the extrainious /r/r/n
S_Response=""                                                                               'clear the response string
HRSOut S_Mod_String,13                                                                      'send my string to the modem
DelayMS 20                                                                                  'give the modem time to respond
Clear B_Timer                                                                               'start from scratch
While b_Data_Rx=0                                                                           'check if we have data in our buffer                                                                           
    DelayMS 1   
    Inc B_Timer
    If B_Timer>200 Then Break
Wend                                                                                        'S_response = contents of the buffer
Clear b_Data_Rx                                                                             'clear the flag for next time
B_Len2=Len(S_Response)                                                                      'how many chrs is the response?
If B_Len2<B_Len+1 Then Return                                                               'not enough chrs for a valid response
'now - we need (b_len2 - B_Len) chars from the right hand end of the response
S_Response=Right$(S_Response,B_Len2-B_Len)                                                  'remove unwanted chars from the start of the response
B_Len=Len(S_Response)                                                                       'leaves us with n chrs + the extra /r/n from the modem
S_Response=Left$(S_Response,B_Len-2)                                                        'remove the /r/n from the end of the response       
Result = S_Response                                                                         'load the result
EndProc

And here is my calling routine - I have initialised the modem module by this point so I know it will respond with something.

loop_here:
                                                                                            'call the procedure
S_Response=P_Modem("AT")

If S_Response<>"OK" Then
    DelayMS 500
    HRSOut2 "No valid response",13
    GoTo loop_here
Else
    HRSOut2 "Result = >",S_Response,"<",13
    HRSOut2 "Sucess",13
EndIf
Stop

I'm sure there are people on this forum with a huge amount of experience talking to modem modules so I wanted to run this past the group and ask for any ideas or comments

(I'm sure I remember way back someone posted their code for this purpose - which was described as being designed to work with basically any modem out there - but I can find no reference to it on the new forum)

Thanks in advance - Peter, from Sunny Tasmania