| ??? 12/15/03 08:16 Read: times |
#60610 - RE: Previously Unsolved problem. Using Modem Responding to: ???'s previous message |
I decided to look at the code. Apart from gems like:
" The purpose of this function is defining the modem functions" Well that tells us a lot! What are the modem functions and what are you trying to achieve??? Read a book called 'code complete' to advise how to comment code. In the main procedure, you test port1== 0x7f to decide whether to hang up. I dare say you want to test the transition of p1.7 to determine when to hang up. A generic solution here would be to use a 'finite state machine'. If you don't know what one is - find out! put simply: char modem_state = 0; //to be really slick - use enums switch(modem_state) { case 0: //send modem init send_modem("AT.........."); // or whatever modem_state = 1; break; case 1: //test p1.7 high for hangup if (port1 & 0x80) { send_modem("ATH"); modem_state = 2; } break; case 2: //test for p1.7 low to continue if (!(port1 & 0x80)) modem_state = 1; break; } //end switch Each 'state' or case does a particular operation and depending on inputs, selects the next state. Add your own meat and vegetables to my flavour sachet for a wonderful meal. Also, remember that the modem doesn't respond instantaneously - some delays will be required. After sending the ATH the modem will need a few hundred milliseconds to do what you want. If after this time the modem hasn't responded you can either retry or fail the operation. Thus the beauty of the state machine. To get really smart you could execute the state machine every 100mS. Try doing a bit of thinking to solve your problem in future and don't expect the internet to save your lazy ass. Merry Christmas! |



