ATM_Tester.ino 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #define CHARCMD 128
  2. #define ENTER 13
  3. #include <SoftwareSerial.h>
  4. SoftwareSerial GSM(3, 2);
  5. void send_AT_cmd(const char *at_cmd);
  6. void setup()
  7. {
  8. GSM.begin(19200);
  9. Serial.begin(19200);
  10. delay(500);
  11. Serial.println("ATM Command tester for Arduino & SIM900 Modules");
  12. Serial.println("");
  13. Serial.print(">");
  14. }
  15. void loop()
  16. {
  17. char inStr[CHARCMD] = "";
  18. int ByteCMD = 0;
  19. int strCount = 0;
  20. while(1) {
  21. if(Serial.available()) {
  22. ByteCMD = Serial.read();
  23. Serial.print(char(ByteCMD));
  24. if(ByteCMD != ENTER) {
  25. inStr[strCount] = char(ByteCMD);
  26. strCount++;
  27. }
  28. }
  29. if(ByteCMD == ENTER) { // Detection de la touche entree
  30. //inStr[strCount+1] = char(ENTER);
  31. Serial.println("");
  32. send_AT_cmd(inStr);
  33. delay(100);
  34. strCount = 0;
  35. ByteCMD = 0;
  36. //Flush de la variable
  37. for(int i = 0; inStr[i] != '\0'; i++) {
  38. inStr[i] = '\0';
  39. }
  40. Serial.print(">");
  41. }
  42. }
  43. }
  44. void send_AT_cmd(const char *at_cmd)
  45. {
  46. GSM.println(at_cmd);
  47. delay(150);
  48. while(GSM.available()!=0)
  49. Serial.write(GSM.read());
  50. }