public bool OpenPort(bool ResetConfig = false) { try { if (ResetConfig) { if (SpGSM_Modem != null && SpGSM_Modem.IsOpen) { SpGSM_Modem.Close(); } SpGSM_Modem.PortName = this.PortName; SpGSM_Modem.Open(); return(SpGSM_Modem.IsOpen); } else { if (!SpGSM_Modem.IsOpen) { SpGSM_Modem.Open(); } return(SpGSM_Modem.IsOpen); } } catch (Exception ex) { LoggingData.WriteLog(ex); return(false); } }
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); } }
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); } }