Example #1
0
        /// <summary>
        /// Send Data to Socket while in IDLE state
        /// </summary>
        /// <param name="SocketNo">Socket Number (1-6)</param>
        /// <param name="DataToSend">Data to send, max 1024 bytes</param>
        /// <returns>True on succes</returns>
        public bool SocketSendData(int SocketNo, byte[] DataToSend)
        {
            // Check if GPRS functions has been initialized
            if (!_gprs_initialized)
            {
                throw new GM862Exception(GM862Exception.WRONGARGUMENT);
            }

            // Check data to send
            if (DataToSend == null)
            {
                throw new GM862Exception(GM862Exception.WRONGARGUMENT);
            }
            if (DataToSend.Length > 1024)
            {
                throw new GM862Exception(GM862Exception.WRONGARGUMENT);
            }

            // Used when executing commands
            string responseBody;

            // Say we want to send data
            if (_device.ExecuteCommand("AT#SSEND=" + SocketNo.ToString(), out responseBody, 15000) != AT_Interface.ResponseCodes.SEND_SMS_DATA)
            {
                return(false);
            }

            // Wait a little before sending the message
            System.Threading.Thread.Sleep(20);


            // Send Data
            _device.SendRawData(DataToSend, 0, DataToSend.Length);

            // End data
            _device.SendRawData(new byte[] { 0x1A }, 0, 1);

            // Wait for response
            if (_device.WaitForResponse(out responseBody, 15000) != AT_Interface.ResponseCodes.OK)
            {
                return(false);
            }

            // Succes
            return(true);
        }
Example #2
0
        /// <summary>
        /// Send Text Message
        /// </summary>
        /// <param name="Destination">Destination for SMS</param>
        /// <param name="Message">Message to Send</param>
        public void SendTextMessage(String Destination, String Message)
        {
            // Check if Text Messaging was initialized correctly
            if (!_textmessage_initialized)
            {
                throw new GM862Exception(GM862Exception.WRONGARGUMENT);
            }

            // String used to store response body when executing functions
            string responseBody;

            // Add format identification to destination
            if (Destination.IndexOf('+') != -1)
            {
                Destination = "\"" + Destination + "\",157"; // Internation format
            }
            else
            {
                Destination = "\"" + Destination + "\",129"; // National format
            }
            // Say we want to send message
            if (_device.ExecuteCommand("AT+CMGS=" + Destination, out responseBody, 15000) != AT_Interface.ResponseCodes.SEND_SMS_DATA)
            {
                throw new GM862Exception(GM862Exception.BAD_RESPONSEBODY);
            }

            // Wait a little before sending the message
            System.Threading.Thread.Sleep(20);

            // Send Message, End with ^Z
            byte[] OutBuffer = System.Text.Encoding.UTF8.GetBytes(Message + "\x1A");
            _device.SendRawData(OutBuffer, 0, OutBuffer.Length);

            // Wait for response
            if (_device.WaitForResponse(out responseBody, 15000) != AT_Interface.ResponseCodes.OK)
            {
                throw new GM862Exception(GM862Exception.BAD_RESPONSEBODY);
            }
        }