0
함수에서 SoftwareSerial 변수를 사용하려고하지만 어떤 이유로 항상 사용할 수 없습니다. 다양한 코드가 아래에 나와 있습니다.arduino의 함수에서 SoftwareSerial 변수를 사용하는 방법
gsm.h
#ifndef GSM_H_
#define GSM_H_
#include <SoftwareSerial.h>
struct gsm{
char *message;
char phone_number[20];
void getText(SoftwareSerial serial, int index);
};
#endif
gsm.cpp
#include "gsm.h"
#include <string.h>
#include <arduino.h>
#include <SoftwareSerial.h>
void gsm::getText(SoftwareSerial serial, int index){
char str[100];
serial.print("AT+CMGR=1 \r");
delay(250);
if(serial.available()){
Serial.print("serial is available");
serial.readBytes(message, 100);
}
}
test.ino
#include "gsm.h"
#include <SoftwareSerial.h>
#include <string.h>
#include <stdio.h>
SoftwareSerial mySerial(10, 11); // RX, TX
gsm gm;
void setup(){
Serial.begin(9600);
mySerial.begin(9600);
gm.getText(mySerial,1);
Serial.print(gm.message);
}
void loop(){
}
Serial.print (gm.message)은 serial.readBytes (메시지, 100)에 의해 메시지에 복사 된 내용을 반환 할 예정이다. 그러나 (serial.available())이 실행되지 않으면 코드 내부에서 직렬 가용성 테스트가 실패한 것으로 보입니다. 제가 지금 당분간과 싸우면서 도움이 필요합니다.
는 사용할 수 없습니다 중 @ stackmalux –
그건 시리얼 [https://www.arduino.cc/en/Reference/SoftwareSerialExample] – stackmalux
와 SoftwareSerial을 테스트하는 간단한 예제를 시도 그런 식으로 구현 될 때 작동하지만, 그렇게하려는 것은 아닙니다. –