Responding to incomming commands

djsoftlayer

New Member
When you send a command with a serial interface from the picaxe to an other device, like a modem for example, all the time you recive a response, for example sending the command ATDnumber it retourn CONNECT or NO DIALTOME etc... somobody can recomend me a set of instruction to recive this answer and compare it to a word??? for example i send with the picaxe the commands ATI to a moden, and if the answer is ENFORA do something or other if another answer comes.... Thanks
 

hippy

Ex-Staff (retired)
The reason there's been no response is most likely that there's no simple set of instructions already written to do what you want.

One technique is read in each character sent back, buffer them up in Ram (SFR) until the end of response ( CR or LF ) then compare that response to a pre-stored list of expected responses in your program ( probably held in Data Eprom ). It's not overly difficult but it's still not a ten second job to write the code. Forum readers don't always have the time to write code for others, and not always immediately after someone posts a question.

If you are only interested in whether the modem sent the expected response or not it could be as simple as -

- SerOut TX_PIN,N4800,("ATD0800xxxxxxxx"CR,)
- SerIn RX_PIN,N4800,b0,b1,b2
- If b0 = "E" And b1 = "N" And b2 = "F" Then
--- Gosub Okay
- Else
--- Gosub Failed
- End If

This code might not work if the modem sends another comand starting "ENF" so you'd need to read more characters, but then you have problems if there are modem responses which send less characters than you are reading.

The simplest solution is to not receive verbose responses "OK", "ENFORA", "CONNECTED" but switch to numeric responses (ATV0) and use something like -

- SerOut TX_PIN,N4800,("ATD0800xxxxxxxx"CR,)
- SerIn RX_PIN,N4800,#w0
- If w0 = 12345 Then
--- Gosub Okay
- Else
--- Gosub Failed
- End If

You can handle all responses individually by replacing the If-Then-Else with a Select-Case. You'll need to check your modem manual or experiment to discover whet the various numeric response codes were.

You need to be executing the SerIn soon enough after the SerOut so as to not miss any response. You'd need to experiment there; run at 8MHz ( SETFREQ M8 ) and use a slower baud rate to start with (N600).
 
Top