Beispiel #1
0
        public GSMModemDevice(string _PortName, int _BaudRate, int _DataBit, StopBits _stopbit, Parity _parity)
        {
            receiveNow           = new AutoResetEvent(false);
            receive_AutoResponse = new AutoResetEvent(false);

            this.PortName = _PortName;
            this.BaudRate = _BaudRate;
            this.DataBits = _DataBit;
            this.Stopbits = _stopbit;
            this.Parity   = _parity;

            //SerialPort
            SpGSM_Modem                = new SafeSerialPort();
            SpGSM_Modem.PortName       = _PortName;
            SpGSM_Modem.BaudRate       = this.BaudRate;
            SpGSM_Modem.DataBits       = this.DataBits;
            SpGSM_Modem.StopBits       = this.Stopbits;
            SpGSM_Modem.Parity         = this.Parity;
            SpGSM_Modem.WriteTimeout   = 500;
            SpGSM_Modem.Encoding       = Encoding.GetEncoding("iso-8859-1");
            SpGSM_Modem.DataReceived  += port_DataReceived;
            SpGSM_Modem.PinChanged    += SpGSM_Modem_PinChanged;
            SpGSM_Modem.ErrorReceived += SpGSM_Modem_ErrorReceived;
            SpGSM_Modem.DtrEnable      = true;
            SpGSM_Modem.RtsEnable      = true;
        }
Beispiel #2
0
        public bool OpenSpeechPort(string PortName)
        {
            try
            {
                _bufferedWaveProvider = new BufferedWaveProvider(new WaveFormat(16000, 1));
                _waveOut = new WaveOut();
                PlayAudio();

                //SerialPort
                SpGSM_Modem_Speech                 = new SafeSerialPort();
                SpGSM_Modem_Speech.BaudRate        = this.BaudRate;
                SpGSM_Modem_Speech.DataBits        = this.DataBits;
                SpGSM_Modem_Speech.StopBits        = this.Stopbits;
                SpGSM_Modem_Speech.Parity          = this.Parity;
                SpGSM_Modem_Speech.WriteTimeout    = 1000;
                SpGSM_Modem_Speech.Encoding        = Encoding.GetEncoding("iso-8859-1");
                SpGSM_Modem_Speech.DataReceived   += portSpeech_DataReceived;
                SpGSM_Modem_Speech.DtrEnable       = true;
                SpGSM_Modem_Speech.RtsEnable       = true;
                SpGSM_Modem_Speech.ReadBufferSize  = 100000;
                SpGSM_Modem_Speech.WriteBufferSize = 100000;

                if (SpGSM_Modem_Speech != null && SpGSM_Modem_Speech.IsOpen)
                {
                    SpGSM_Modem_Speech.Close();
                }
                SpGSM_Modem_Speech.PortName = PortName;
                SpGSM_Modem_Speech.Open();

                _waveIn                   = new WaveIn();
                _waveIn.WaveFormat        = new WaveFormat(16000, 1);
                _waveIn.DataAvailable    += new EventHandler <WaveInEventArgs>(waveSource_DataAvailable);
                _waveIn.RecordingStopped += new EventHandler <StoppedEventArgs>(waveSource_RecordingStopped);
                _waveIn.StartRecording();

                return(SpGSM_Modem_Speech.IsOpen);
            }
            catch (Exception ex)
            {
                LoggingData.WriteLog(ex);
                return(false);
            }
        }
Beispiel #3
0
        public bool OpenAutoResponsePort(string PortName)
        {
            try
            {
                //source = new CancellationTokenSource();
                //CancellationToken token = source.Token;
                //taskWaitResponse = Task.Factory.StartNew(() => {

                //}, token);

                //SerialPort
                SpGSM_Modem_AutoResponse               = new SafeSerialPort();
                SpGSM_Modem_AutoResponse.BaudRate      = this.BaudRate;
                SpGSM_Modem_AutoResponse.DataBits      = this.DataBits;
                SpGSM_Modem_AutoResponse.StopBits      = this.Stopbits;
                SpGSM_Modem_AutoResponse.Parity        = this.Parity;
                SpGSM_Modem_AutoResponse.WriteTimeout  = 500;
                SpGSM_Modem_AutoResponse.Encoding      = Encoding.GetEncoding("iso-8859-1");
                SpGSM_Modem_AutoResponse.DataReceived += portAutoResponse_DataReceived;
                SpGSM_Modem_AutoResponse.DtrEnable     = true;
                SpGSM_Modem_AutoResponse.RtsEnable     = true;

                if (SpGSM_Modem_AutoResponse != null && SpGSM_Modem_AutoResponse.IsOpen)
                {
                    SpGSM_Modem_AutoResponse.Close();
                }
                SpGSM_Modem_AutoResponse.PortName = PortName;
                SpGSM_Modem_AutoResponse.Open();
                return(SpGSM_Modem_AutoResponse.IsOpen);
            }
            catch (Exception ex)
            {
                LoggingData.WriteLog(ex);
                return(false);
            }
        }