문제

나는 SMS 를 전송하여서는 명령을 가진 GSM 휴대 전화입니다.나는 글을 보내는 대량의 메시지처럼 수 있습니다.내가 읽는 GSM 모바일에 우리는 보낼 수 있습니다 6-8sms 에 동의합니다.그러나 때 나는 메시지를 보내 그런 다음 누군가가 가고 있는 사람이 아닙니다.내가 정보를 얻기 excel 파일에서 즉시 및 메시지의 텍스트입니다.할 수 있는 이유를 말해 어떤 sms 가고 있는지 어떤지 않습니다.내 코드

        SmsFields smsObj = null;
        List<SmsFields> smsColl = null;
        SerialPort serialport = null;
        StringBuilder strbuild = new StringBuilder();
        try
        {
            //Validate the form 
            if (!Validation()) return;

            serialport = new SerialPort();

            ////Sets the properties of serial port object
            serialport.PortName = cboPort.SelectedItem.ToString();
            serialport.BaudRate = 9600;
            serialport.Parity = Parity.None;
            serialport.DataBits = 8;
            serialport.StopBits = StopBits.One;
            serialport.Handshake = Handshake.RequestToSend;
            serialport.DtrEnable = true;
            serialport.RtsEnable = true;

            //Open the port to send sms
            serialport.Open();

            //Check if port is opened or not
            if (!serialport.IsOpen)
            {
                MessageBox.Show("Serial port is not opened. Please try with other port");
                return;
            }

            //Create smsFields class's object and fill the data in the generic collection
            smsObj = SmsFields.Instance;
            smsColl = smsObj.FillData(txtFilePath.Text);

            if (smsColl == null)
            {
                MessageBox.Show("No data found in the excel table");
                return;
            }
            //Gets the single record from SmsFields class and sends the message
            foreach (SmsFields sms in smsColl)
            {

                //checks phone status
                serialport.WriteLine("AT" + Environment.NewLine);
                //Configures message as SMS (0 for PDU format) and (1 for text format)
                serialport.WriteLine("AT+CMGF=1" + Environment.NewLine);

                //Sets message center number
                serialport.WriteLine("AT+CSCA=\"" + txtServiceNo.Text + "\"" + Environment.NewLine);

                //Sets destination number
                serialport.WriteLine("AT+CMGS=\"" + sms.DestinationNo + "\"" + Environment.NewLine);

                //Specifies message and sends Ctrl+z
                serialport.WriteLine(sms.Message + (char)26);

                //Displays buffer containing output messages
                System.Threading.Thread.Sleep(4000);
   }
도움이 되었습니까?

해결책

귀하의 문제는 다음 명령을 보내기 전에 최종 결과 코드 (예 : OK, 오류 및 기타 몇 개)를 기다리지 않는다고 생각합니다. 그 문제는 새 명령이 끝나지 않으면 진행중인 명령을 중단한다는 것입니다. 인용합니다 v.250:

5.6.1 명령 중단

...

명령의 중단은 DTE에서 모든 문자의 DCE 로의 전송에 의해 달성됩니다.

그래서 언제나 명령을 보낼 때, 당신 해야 하다 다음 명령을 보내기 전에 최종 결과 코드를 기다립니다.

리팩토링을 제안 할 수 있습니다 serialport.WriteLine("ATxxx" + Environment.NewLine) a sendCommand(serialport, "ATxxx") 기능? 그런 다음 해당 기능의 끝에서 최종 결과 코드를 기다릴 수 있습니다.

다른 팁

보려고하는 경우 패턴이 있을 메시지가 전송되지 않습니다.기 때문에 그 문제가 있을 수 있습니다 숫자 형식이나 잘못된 문자 메시지입니다.

또한 일부 노트:

  1. 당신을 수행하지 않고 오류를 검사합니다.나는 것이 있는지 확인 내가 예상되는 답변를 호출한 후에는 각 명령입니다.

  2. 당신이 사용하는 환경입니다.줄 바꿈을 마무리도 있습니다.*******나는 가정이라는 속성을 변경하는 기본이 되는 운영 체제입니다.에서 표준이 그러나 매우 명확한에서 정확히 어떤 문자를 사용하여 종료하는 commandlines.

  3. 휴대폰은 실제 저장 됩니다.단지 때문에 따라 사양 또는 문서를 의미하지 않는다 그들은 않습니다.가정 각 동작하는 휴대 전화 모델에서 다른 다른 모든.보점 1.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top