public PortMonitorControl(PortSettings setting) { InitializeComponent(); // 设置事件入口 m_wndSaveDataWorker.DoWork += new DoWorkEventHandler(m_wndSaveDataWorker_DoWork); m_wndSaveDataWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(m_wndSaveDataWorker_RunWorkerCompleted); // 绑定消息 m_SerialPort.PortName = setting.PortName; m_SerialPort.BaudRate = setting.BaudRate; m_SerialPort.DataBits = setting.DataSize; m_SerialPort.StopBits = setting.StopBits; m_SerialPort.Parity = setting.Parity; m_SerialPort.DataReceived += new SerialDataReceivedEventHandler(m_SerialPort_DataReceived); m_AISParser.DynamicInformationReceived += new DynamicInformationReceivedHandler(m_AISParser_DynamicInformationReceived); m_AISParser.StaticInformationReceived += new StaticInformationReceivedHandler(m_AISParser_StaticInformationReceived); m_AISParser.NMEAStringReceived += new DataReceivedHandler(m_AISParser_NMEAStringReceived); m_AISParser.RawStringReceived += new DataReceivedHandler(m_AISParser_RawStringReceived); try { // 打开串口 m_SerialPort.Open(); } catch (System.Exception ex) { MessageBox.Show("打开串口失败, 串口名称:" + setting.PortName + "\n详细信息:\n" + ex.Message); } }
private void settingsToolStripMenuItem_Click(object sender, EventArgs e) { // Make sure the port isnt already open if (serialPort1.IsOpen) { MessageBox.Show("The port must be closed before changing the settings."); return; } else { // Create an instance of the settings form PortSettings settings = new PortSettings(); if (settings.ShowDialog() == DialogResult.OK) { if (settings.selectedPort != "") { // Set the serial port to the new settings serialPort1.PortName = settings.selectedPort; serialPort1.BaudRate = settings.selectedBaudrate; serialPort1.DataBits = settings.selectedDataBits; serialPort1.Parity = settings.selectedParity; serialPort1.StopBits = settings.selectedStopBits; // Show the new settings in the form text line showSettings(); } else { MessageBox.Show("Error: Settings form returned with no seiral port selected"); return; // Bail out } } else { MessageBox.Show("Error: buttonSetup_Click - Settings dialog box did not return Okay."); return; // bail out } // Open the port try { serialPort1.Close(); serialPort1.Open(); menuStrip1.Items[1].Text = "Close Port"; showSettings(); } catch (System.Exception ex) { MessageBox.Show("Error - setupToolStripMenuItem_Click Exception: " + ex); } } }
/// <summary>Constructor.</summary> /// <param name="portName">Name of serial port.</param> /// <param name="baudRate">Initial communications baud rate.</param> /// <param name="dataBits">Initial communications data bits.</param> /// <param name="parity">Initial communications parity.</param> /// <param name="stopBits">Initial communications stop bits.</param> public SerialPrinter(string portName, int baudRate, int dataBits, Parity parity, StopBits stopBits) : base(portName, baudRate, parity, dataBits, stopBits) { //Constructor try { this.mSettings = new PortSettings(portName, baudRate, dataBits, parity, stopBits, PortSettings.DEFAULT_HANDSHAKE); //base.DataReceived += new SerialDataReceivedEventHandler(OnDataReceived); base.PinChanged += new SerialPinChangedEventHandler(OnPinChanged); base.ErrorReceived += new SerialErrorReceivedEventHandler(OnErrorReceived); } catch (Exception ex) { throw new ApplicationException("Unexpected error while creating new SerialPrinter instance.", ex); } }
public void ChangePrinter(string printerType, string portName) { //Change station printer try { if (printerType != "" && portName != "") { ILabelPrinter oPrinter = DeviceFactory.CreatePrinter(printerType, portName); PortSettings oSettings = oPrinter.DefaultSettings; NameValueCollection nvcPrinter = (NameValueCollection)ConfigurationManager.GetSection("station/printer"); oSettings.PortName = portName; oSettings.BaudRate = Convert.ToInt32(nvcPrinter["BaudRate"]); oSettings.DataBits = Convert.ToInt32(nvcPrinter["DataBits"]); switch (nvcPrinter["Parity"].ToString().ToLower()) { case "none": oSettings.Parity = Parity.None; break; case "even": oSettings.Parity = Parity.Even; break; case "odd": oSettings.Parity = Parity.Odd; break; } switch (Convert.ToInt32(nvcPrinter["StopBits"])) { case 1: oSettings.StopBits = StopBits.One; break; case 2: oSettings.StopBits = StopBits.Two; break; } switch (nvcPrinter["Handshake"].ToString().ToLower()) { case "none": oSettings.Handshake = Handshake.None; break; case "rts/cts": oSettings.Handshake = Handshake.RequestToSend; break; case "xon/xoff": oSettings.Handshake = Handshake.XOnXOff; break; } oPrinter.Settings = oSettings; //Atach printer to sort station and turn-on if (this.mLabelPrinter != null) { this.mLabelPrinter.TurnOff(); } this.mLabelPrinter = oPrinter; this.mLabelPrinter.TurnOn(); } } catch (System.IO.IOException) { } catch (ApplicationException ex) { throw ex; } catch (Exception ex) { throw new ApplicationException("Unexpected error while setting the printer.", ex); } finally { if (this.PrinterChanged != null) { this.PrinterChanged(this, new EventArgs()); } } }
public PortSettings GetSettings() { PortSettings settings = new PortSettings(); try { settings.PortName = this.mSerialPort.PortName; settings.BaudRate = this.mSerialPort.BaudRate; settings.DataBits = this.mSerialPort.DataBits; settings.Parity = this.mSerialPort.Parity; settings.StopBits = this.mSerialPort.StopBits; settings.Handshake = this.mSerialPort.Handshake; } catch (Exception ex) { throw new FaultException <ScaleFault>(new ScaleFault(ex)); } return(settings); }
private void OnPortDataBitsChanged(object sender, System.EventArgs e) { //Event handler for change in data bits try { if (this.mPrinter != null && this.mPrinter.On) { PortSettings settings = this.mPrinter.Settings; settings.DataBits = Convert.ToInt32(this.cboDataBits.Text); this.mPrinter.Settings = settings; //LogEvent(LOG_ID_PORT + ": DataBits= " + this.mPrinter.Settings.DataBits.ToString() + "\n"); } } catch (Exception ex) { reportError(ex); } finally { setUserServices(); } }
private void OnPortNameChanged(object sender, System.EventArgs e) { //Event handler for change in port try { if (this.mPrinter != null && !this.mPrinter.On) { PortSettings settings = this.mPrinter.Settings; settings.PortName = this.cboPort.Text; this.mPrinter.Settings = settings; //LogEvent(LOG_ID_PORT + ": Name= " + this.mPrinter.Settings.PortName + "\n"); } } catch (Exception ex) { reportError(ex); } finally { setUserServices(); } }
// protected void Page_Load(object sender, EventArgs e) { // ScaleClient scale = null; if (!Page.IsPostBack) { scale = new ScaleClient(new InstanceContext(new ScaleCallbacks()), "WSDualHttpBinding_IScale"); Session["Scale"] = scale; try { //Service this.lblService.Text = scale.Endpoint.Address.Uri.ToString(); this.lblIsOn.Text = scale.IsOn().ToString(); //Settings this.lblBornOn.Text = scale.BornOn().ToLongTimeString(); PortSettings ps = scale.GetSettings(); this.lblPort.Text = ps.PortName; this.lblBaud.Text = ps.BaudRate.ToString(); this.lblData.Text = ps.DataBits.ToString(); this.lblStop.Text = ps.StopBits.ToString(); this.lblParity.Text = ps.Parity.ToString(); this.lblHandshake.Text = ps.Handshake.ToString(); this.btnStart.Enabled = true; this.btnStop.Enabled = false; this.btnWeight.Enabled = false; this.btnZero.Enabled = false; } catch (TimeoutException ex) { reportError(new ApplicationException("The service operation timed out.", ex)); scale.Abort(); } catch (FaultException <Devices.ScaleFault> f) { reportError(new ApplicationException("There was a scale fault- " + f.ToString())); scale.Abort(); } catch (CommunicationException ex) { reportError(new ApplicationException("There was a communication problem.", ex)); scale.Abort(); } } }
private void OnPortStopBitsChanged(object sender, System.EventArgs e) { //Event handler for change in stop bits try { if (this.mPrinter != null && this.mPrinter.On) { PortSettings settings = this.mPrinter.Settings; switch (Convert.ToInt32(this.cboStopBits.Text)) { case 1: settings.StopBits = System.IO.Ports.StopBits.One; break; case 2: settings.StopBits = System.IO.Ports.StopBits.Two; break; } this.mPrinter.Settings = settings; //LogEvent(LOG_ID_PORT + ": StopBits= " + this.mPrinter.Settings.StopBits.ToString() + "\n"); } } catch (Exception ex) { reportError(ex); } finally { setUserServices(); } }
public void ChangeScale(string scaleType, string portName) { //Change station scale try { if (scaleType != "" && portName != "") { //Create and configure a scale IScale oScale = DeviceFactory.CreateScale(scaleType, portName); PortSettings oSettings = oScale.DefaultSettings; NameValueCollection nvcScale = (NameValueCollection)ConfigurationManager.GetSection("station/scale"); oSettings.PortName = portName; oSettings.BaudRate = Convert.ToInt32(nvcScale["BaudRate"]); switch (nvcScale["Parity"].ToString().ToLower()) { case "none": oSettings.Parity = Parity.None; break; case "even": oSettings.Parity = Parity.Even; break; case "odd": oSettings.Parity = Parity.Odd; break; } oScale.Settings = oSettings; //Atach scale to sort station and turn-on if (this.mScale != null) { this.mScale.TurnOff(); } this.mScale = oScale; this.mScale.TurnOn(); } } catch (System.IO.IOException) { } catch (ApplicationException ex) { throw ex; } catch (Exception ex) { throw new ApplicationException("Unexpected error while setting the scale.", ex); } finally { if (this.ScaleChanged != null) { this.ScaleChanged(this, new EventArgs()); } } }
//========================================================================= //========================================================================= protected PortSettings GetChanges() { //---- declare vars PortSettings portSettings = new PortSettings(); portSettings.PortName = this.lstSerialPorts.SelectedValue.ToString(); portSettings.Parity = (Parity)this.lstParity.SelectedItem; portSettings.StopBits = (StopBits)this.lstStopBits.SelectedItem; portSettings.Handshake = (Handshake)this.lstHandshake.SelectedItem; if (this.lstBaudRates.SelectedValue == "Other") { int baudRate; if (int.TryParse(this.txtOtherBaudRate.Text, out baudRate)) { portSettings.BaudRate = baudRate; } else { throw new Exception("Invalid Baud Rate."); } } else { portSettings.BaudRate = (int)(Enum.Parse(typeof(BaudRate), this.lstBaudRates.SelectedItem.ToString())); } int dataBits; if (int.TryParse(this.txtDataBits.Text, out dataBits)) { portSettings.DataBits = dataBits; } else { throw new Exception("Invalid Data Bits Value."); } return(portSettings); }
/// <summary> /// Constructor /// </summary> public OutputWindowViewModel() { _logger = LogManager.GetCurrentClassLogger(); _contactIdDataMap = AppManager.Instance.CurrentContactIdDataObject; _serialDataBuffer = new StringBuilder(); AppManager.Instance.OnContactIdXmlLoaded += (obj, e) => { _isPaused = true; _contactIdDataMap = e; _isPaused = false; }; SerialPortManager.Instance.OnSerialPortOpened += (obj, e) => { if (e == true) { _currentPortSettings = AppManager.Instance.CurrentPortSettings; } }; SerialPortManager.Instance.OnDataReceived += Handler_OnDataReceived; }
private void OnPortParityChanged(object sender, System.EventArgs e) { //Event handler for change in parity try { if (this.mPrinter != null && this.mPrinter.On) { PortSettings settings = this.mPrinter.Settings; switch (this.cboParity.Text.ToLower()) { case "none": settings.Parity = System.IO.Ports.Parity.None; break; case "even": settings.Parity = System.IO.Ports.Parity.Even; break; case "odd": settings.Parity = System.IO.Ports.Parity.Odd; break; } this.mPrinter.Settings = settings; //LogEvent(LOG_ID_PORT + ": Parity= " + this.mPrinter.Settings.Parity.ToString() + "\n"); } } catch (Exception ex) { reportError(ex); } finally { setUserServices(); } }
public void ChangeScale(string scaleType, string portName) { //Change station scale try { if (scaleType != "" && portName != "") { //Create and configure a scale IScale oScale = DeviceFactory.CreateScale(scaleType, portName); PortSettings oSettings = oScale.DefaultSettings; NameValueCollection nvcScale = (NameValueCollection)ConfigurationSettings.GetConfig("station/scale"); oSettings.PortName = portName; oSettings.BaudRate = Convert.ToInt32(nvcScale["BaudRate"]); switch (nvcScale["Parity"].ToString().ToLower()) { case "none": oSettings.Parity = RS232Parity.None; break; case "even": oSettings.Parity = RS232Parity.Even; break; case "odd": oSettings.Parity = RS232Parity.Odd; break; } oScale.Settings = oSettings; //Atach scale to sort station and turn-on if (this.mScale != null) { this.mScale.TurnOff(); } this.mScale = oScale; this.mScale.TurnOn(500); //Notify clients if (this.ScaleChanged != null) { this.ScaleChanged(this, new EventArgs()); } } } catch (Exception ex) { throw ex; } }
public void Init() { _logger = LogManager.GetCurrentClassLogger(); ExportToFileEnabled = true; //TerminationChar = "¶"; CurrentAppSettings = LoadAppSettings(); if (CurrentAppSettings != null) { OutputDataDirectory = CurrentAppSettings.OutputDataDirectory; var portSettings = new PortSettings(); var defaultList = portSettings.GetDefaultValues(); portSettings.IsSerialPortEnabled = CurrentAppSettings.IsSerialPortEnabled; portSettings.ReceiverName = CurrentAppSettings.ReceiverName; portSettings.Description = CurrentAppSettings.Description; portSettings.PortName = CurrentAppSettings.PortName; portSettings.BaudRate = CurrentAppSettings.BaudRate; portSettings.Parity = CurrentAppSettings.Parity; portSettings.DataBits = CurrentAppSettings.DataBits; portSettings.StopBits = CurrentAppSettings.StopBits; portSettings.Handshake = CurrentAppSettings.Handshake; portSettings.PortNameList = defaultList.PortNameList; portSettings.BaudRateList = defaultList.BaudRateList; portSettings.ParityList = defaultList.ParityList; portSettings.DataBitsList = defaultList.DataBitsList; portSettings.StopBitsList = defaultList.StopBitsList; portSettings.HandshakeList = defaultList.HandshakeList; CurrentPortSettings = portSettings; } else { OutputDataDirectory = GetAppDirectory; var portSettings = new PortSettings(); CurrentPortSettings = portSettings.GetDefaultValues(); } }
//========================================================================= //========================================================================= /// <summary> /// Instantiates a new BasicRobot class with the passed in PortSettings. /// </summary> /// <param name="portSettings">The PortSettings for the underlying port.</param> public BasicArduinoRobot(PortSettings portSettings) : base(portSettings) { this.CommonInit(); }
public void Open(PortSettings portSettings) { if (portSettings == null) { return; } if (!portSettings.IsSerialPortEnabled) { if (OnStatusChanged != null) { OnStatusChanged(this, "Unable to start, port is not enabled."); } return; } Close(); try { CurrentPortSettings = portSettings; _serialPort.PortName = CurrentPortSettings.PortName; _serialPort.BaudRate = CurrentPortSettings.BaudRate; _serialPort.Parity = CurrentPortSettings.Parity; _serialPort.DataBits = CurrentPortSettings.DataBits; _serialPort.StopBits = CurrentPortSettings.StopBits; _serialPort.Handshake = CurrentPortSettings.Handshake; _serialPort.ReadTimeout = 500; _serialPort.WriteTimeout = 500; _logger.Info(string.Format( "SerialPort settings: PortName={0}, BaudRate={1}, DataBits={2}, Parity={3}, StopBits={4}, Handshake={5}, ReadTimeout={6}, WriteTimeout={7}", _serialPort.PortName, _serialPort.BaudRate, _serialPort.DataBits, _serialPort.Parity, _serialPort.StopBits, _serialPort.Handshake, _serialPort.ReadTimeout, _serialPort.WriteTimeout)); _serialPort.Open(); StartReading(); _serialPort.DataReceived += _serialPort_DataReceived; } catch (IOException) { if (OnStatusChanged != null) { OnStatusChanged(this, string.Format("{0} does not exist.", CurrentPortSettings.PortName)); } _logger.Error(string.Format("SerialPort: {0} does not exist.", CurrentPortSettings.PortName)); } catch (UnauthorizedAccessException) { if (OnStatusChanged != null) { OnStatusChanged(this, string.Format("{0} already in use.", CurrentPortSettings.PortName)); } _logger.Error(string.Format("SerialPort: {0} already in use.", CurrentPortSettings.PortName)); } catch (Exception ex) { if (OnStatusChanged != null) { OnStatusChanged(this, "Exception: " + ex.Message); } _logger.Error("[Generic Exception] SerialPort: " + ex.ToString()); } if (_serialPort.IsOpen) { string sb = StopBits.None.ToString().Substring(0, 1); switch (_serialPort.StopBits) { case StopBits.One: sb = "1"; break; case StopBits.OnePointFive: sb = "1.5"; break; case StopBits.Two: sb = "2"; break; default: break; } string p = _serialPort.Parity.ToString().Substring(0, 1); string hs = _serialPort.Handshake == Handshake.None ? "No Handshake" : _serialPort.Handshake.ToString(); if (OnStatusChanged != null) { OnStatusChanged(this, string.Format( "Connected to {0}: {1} bps, {2}{3}{4}, {5}.", _serialPort.PortName, _serialPort.BaudRate, _serialPort.DataBits, p, sb, hs)); } if (OnSerialPortOpened != null) { OnSerialPortOpened(this, true); } _logger.Info(string.Format( "SerialPort: Connected to {0}: {1} bps, {2}{3}{4}, {5}.", _serialPort.PortName, _serialPort.BaudRate, _serialPort.DataBits, p, sb, hs)); } else { if (OnStatusChanged != null) { OnStatusChanged(this, string.Format( "{0} already in use.", CurrentPortSettings.PortName)); } if (OnSerialPortOpened != null) { OnSerialPortOpened(this, false); } _logger.Error(string.Format( "SerialPort: {0} already in use.", CurrentPortSettings.PortName)); } }
//========================================================================= //========================================================================= /// <summary> /// Instantiates a new BasicRobot class with the passed in PortSettings. /// </summary> /// <param name="portSettings">The PortSettings for the underlying port.</param> public LEDCounter01(PortSettings portSettings) : base(portSettings) { }
//========================================================================= //========================================================================= /// <summary> /// Instantiates a new BasicRobot class with the passed in PortSettings. /// </summary> /// <param name="portSettings">The PortSettings for the underlying port.</param> public BasicParallaxRobot(PortSettings portSettings) : base(portSettings) { this.CommonInit(); }
public static void UpdateCallDetails(string message) { try { UpdateData calldata = new UpdateData(); calldata.CallDetails = new CallDetails(); foreach (string data in message.Split(PortSettings.GetInstance().ReceiveDataDelimiter.ToCharArray())) { string[] keyvalue = data.Split('='); if (keyvalue[0].ToLower().Equals(Settings.GetInstance().PortSetting.ReceiveConnectionIdName)) { calldata.CallDetails.ConnID = keyvalue[1]; } else if (PortSettings.GetInstance().ReceiveDatakey.Contains(keyvalue[0])) { switch (PortSettings.GetInstance().ReceiveDatakey.IndexOf(keyvalue[0])) { case 0: calldata.CallDetails.Ad1 = keyvalue[1]; break; case 1: calldata.CallDetails.Ad2 = keyvalue[1]; break; case 2: calldata.CallDetails.Ad3 = keyvalue[1]; break; case 3: calldata.CallDetails.Ad4 = keyvalue[1]; break; case 4: calldata.CallDetails.Ad5 = keyvalue[1]; break; case 5: calldata.CallDetails.Ad6 = keyvalue[1]; break; case 6: calldata.CallDetails.Ad7 = keyvalue[1]; break; case 7: calldata.CallDetails.Ad8 = keyvalue[1]; break; case 8: calldata.CallDetails.Ad9 = keyvalue[1]; break; case 9: calldata.CallDetails.Ad10 = keyvalue[1]; break; } } } BasicService serviceClient = new BasicService(Settings.GetInstance().PortSetting.WebServiceURL); ServiceResult serviceResult = serviceClient.UpdateCallDetailsAsyc(calldata); //logger.Info("Data received from web service while update call details, Code: " + serviceResult.ResultCode + ", Description: " + serviceResult.ResultDescription); } catch //(Exception ex) { //logger.Error("Error occurred as " + ex.Message); } }
public void SetLabelPrinter(string printerType, string portName) { // try { //Validate printer type and port name if (!DeviceFactory.PrinterTypeExists(printerType)) { throw new ArgumentException("'" + printerType + "' is an invalid printer type."); } if (portName.Length <= 0) { throw new ArgumentException("'" + portName + "' is an invalid port name."); } //Create/change the attached label printer if (this.mPrinter != null) { //A current printer exists: check for change to printer type if (printerType != this.mPrinter.Type) { //New printer type: disconnect current printer and attach a new one //with the same settings (except use the specified port name) bool bOn = this.mPrinter.On; if (bOn) { this.mPrinter.TurnOff(); } PortSettings settings = this.mPrinter.Settings; settings.PortName = portName; ILabelPrinter printer = DeviceFactory.CreatePrinter(printerType, portName); if (printer == null) { throw new ApplicationException("Printer " + printerType + " on port " + portName + " could not be created."); } printer.Settings = settings; this.mPrinter = printer; if (bOn) { this.mPrinter.TurnOn(); } } else { //Same printer type: check for change in printer port if (portName != this.mPrinter.Settings.PortName) { //Change port on existing printer PortSettings settings = this.mPrinter.Settings; settings.PortName = portName; this.mPrinter.Settings = settings; } } } else { //Create a new label printer this.mPrinter = DeviceFactory.CreatePrinter(printerType, portName); if (this.mPrinter == null) { throw new ApplicationException("Printer " + printerType + " on port " + portName + " could not be created."); } //Set printer configuration; start with printer's default settings PortSettings settings = this.mPrinter.DefaultSettings; NameValueCollection nvcPrinter = (NameValueCollection)ConfigurationManager.GetSection("station/printer"); settings.PortName = portName; settings.BaudRate = Convert.ToInt32(nvcPrinter["BaudRate"]); settings.DataBits = Convert.ToInt32(nvcPrinter["DataBits"]); switch (nvcPrinter["Parity"].ToString().ToLower()) { case "none": settings.Parity = System.IO.Ports.Parity.None; break; case "even": settings.Parity = System.IO.Ports.Parity.Even; break; case "odd": settings.Parity = System.IO.Ports.Parity.Odd; break; } switch (Convert.ToInt32(nvcPrinter["StopBits"])) { case 1: settings.StopBits = System.IO.Ports.StopBits.One; break; case 2: settings.StopBits = System.IO.Ports.StopBits.Two; break; } switch (nvcPrinter["Handshake"].ToString().ToLower()) { case "none": settings.Handshake = System.IO.Ports.Handshake.None; break; case "rts/cts": settings.Handshake = System.IO.Ports.Handshake.RequestToSend; break; case "xon/xoff": settings.Handshake = System.IO.Ports.Handshake.XOnXOff; break; } this.mPrinter.Settings = settings; } } catch (Exception ex) { throw new ApplicationException("Unexpected error setting the label printer.", ex); } finally { if (this.PrinterChanged != null) { this.PrinterChanged(this, new EventArgs()); } } }
//========================================================================= //========================================================================= protected PortSettings GetChanges() { //---- declare vars PortSettings portSettings = new PortSettings(); portSettings.PortName = this.lstSerialPorts.SelectedValue.ToString(); portSettings.Parity = (Parity)this.lstParity.SelectedItem; portSettings.StopBits = (StopBits)this.lstStopBits.SelectedItem; portSettings.Handshake = (Handshake)this.lstHandshake.SelectedItem; if (this.lstBaudRates.SelectedValue == "Other") { int baudRate; if (int.TryParse(this.txtOtherBaudRate.Text, out baudRate)) { portSettings.BaudRate = baudRate; } else { throw new Exception("Invalid Baud Rate."); } } else { portSettings.BaudRate = (int)(Enum.Parse(typeof(BaudRate), this.lstBaudRates.SelectedItem.ToString())); } int dataBits; if (int.TryParse(this.txtDataBits.Text, out dataBits)) { portSettings.DataBits = dataBits; } else { throw new Exception("Invalid Data Bits Value."); } return portSettings; }
//========================================================================= public void ResetToDefaults() { this._portSettings = new PortSettings(); this.SetValuesFromSettings(); }
public static void ProcessInsertCallDetails(Type objType, object obj) { try { Dictionary <string, string> filterKey = new Dictionary <string, string>(); InsertData calldata = new InsertData(); calldata.CallDetails = new CallDetails(); calldata.UserData = new UserData(); calldata.KeyTable = new KeyTable(); calldata.CallDetails.FirstName = Settings.GetInstance().FirstName; calldata.CallDetails.LastName = Settings.GetInstance().LastName; calldata.CallDetails.UserName = Settings.GetInstance().UserName; object value = null; value = GetValueFromObject(objType, obj, "ConnID"); if (value != null) { calldata.UserData.ConnID = calldata.UserData.ConnID = calldata.CallDetails.ConnID = value.ToString(); } value = GetValueFromObject(objType, obj, "ANI"); if (value != null) { calldata.CallDetails.Ani = value.ToString(); } value = GetValueFromObject(objType, obj, "DNIS"); if (value != null) { calldata.CallDetails.Dnis = value.ToString(); } value = GetValueFromObject(objType, obj, "Name"); if (value != null) { calldata.CallDetails.EventName = value.ToString(); } value = GetValueFromObject(objType, obj, "ThisDN"); if (value != null) { calldata.CallDetails.ThisDN = value.ToString(); } value = GetValueFromObject(objType, obj, "Place"); if (value != null) { calldata.CallDetails.AgentPlace = value.ToString(); } value = GetValueFromObject(objType, obj, "UserData"); if (value != null) { KeyValueCollection userData = value as KeyValueCollection; //Add All Keys and values in user data table. if (userData != null) { //Add Filter keys foreach (string key in Settings.GetInstance().VoiceFilterKey) { if (userData.ContainsKey(key)) { filterKey.Add(key, userData[key].ToString()); } } //the keys does not reach, then for add other keys if (filterKey.Count < 10) { foreach (string key in userData.AllKeys) { if (!filterKey.ContainsKey(key) && filterKey.Count < 10) { filterKey.Add(key, userData[key].ToString()); } else if (filterKey.Count == 10) { break; } } } if (userData.ContainsKey(Settings.GetInstance().VoiceDispositionCollectionName)) { KeyValueCollection dispositionCollection = userData[Settings.GetInstance().VoiceDispositionCollectionName] as KeyValueCollection; if (dispositionCollection != null) { foreach (string dispositionValue in dispositionCollection.AllValues) { if (string.IsNullOrEmpty(calldata.CallDetails.Disposition1)) { calldata.CallDetails.Disposition1 = dispositionValue; } else if (string.IsNullOrEmpty(calldata.CallDetails.Disposition2)) { calldata.CallDetails.Disposition2 = dispositionValue; } } } } //For Read Dispotion Key if (userData.ContainsKey(Settings.GetInstance().VoiceDispositionKeyName)) { if (string.IsNullOrEmpty(calldata.CallDetails.Disposition1)) { calldata.CallDetails.Disposition1 = userData[Settings.GetInstance().VoiceDispositionKeyName].ToString(); } else if (string.IsNullOrEmpty(calldata.CallDetails.Disposition2)) { calldata.CallDetails.Disposition2 = userData[Settings.GetInstance().VoiceDispositionKeyName].ToString(); } else if (string.IsNullOrEmpty(calldata.CallDetails.Disposition3)) { calldata.CallDetails.Disposition3 = userData[Settings.GetInstance().VoiceDispositionKeyName].ToString(); } } //For adding all keys in user data table calldata.UserData.UserDatas = new ArrayOfKeyValueOfstringstringKeyValueOfstringstring[userData.Count]; int index = 0; foreach (string key in userData.AllKeys) { //calldata.UserData.UserDatas[key] = userData[key].ToString(); calldata.UserData.UserDatas[index] = new ArrayOfKeyValueOfstringstringKeyValueOfstringstring(); calldata.UserData.UserDatas[index].Key = key; calldata.UserData.UserDatas[index].Value = userData[key].ToString(); index++; } if (string.IsNullOrEmpty(calldata.CallDetails.AgentPlace)) { if (userData.ContainsKey("RTargetPlaceSelected")) { calldata.CallDetails.AgentPlace = userData["RTargetPlaceSelected"].ToString(); } } } int count = 1; //For Store url key Action <string, string> MapValue; MapValue = delegate(string key, string Value) { //if (key.Equals("ReferenceId")) // return; switch (count) { case 1: calldata.CallDetails.Ad1 = Value; calldata.KeyTable.Key1 = key; break; case 2: calldata.CallDetails.Ad2 = Value; calldata.KeyTable.Key2 = key; break; case 3: calldata.CallDetails.Ad3 = Value; calldata.KeyTable.Key3 = key; break; case 4: calldata.CallDetails.Ad4 = Value; calldata.KeyTable.Key4 = key; break; case 5: calldata.CallDetails.Ad5 = Value; calldata.KeyTable.Key5 = key; break; case 6: calldata.CallDetails.Ad6 = Value; calldata.KeyTable.Key6 = key; break; case 7: calldata.CallDetails.Ad7 = Value; calldata.KeyTable.Key7 = key; break; case 8: calldata.CallDetails.Ad8 = Value; calldata.KeyTable.Key8 = key; break; case 9: calldata.CallDetails.Ad9 = Value; calldata.KeyTable.Key9 = key; break; case 10: calldata.CallDetails.Ad10 = Value; calldata.KeyTable.Key10 = key; break; } count++; }; foreach (string key in Settings.GetInstance().PortSetting.ReceiveDatakey) { if (count > 10) { break; } MapValue(key, string.Empty); } foreach (string key in filterKey.Keys) { if (count > 10) { break; } if (!PortSettings.GetInstance().ReceiveDatakey.Contains(key)) { MapValue(key, filterKey[key]); } } } BasicService serviceClient = new BasicService(Settings.GetInstance().PortSetting.WebServiceURL); ServiceResult serviceResult = serviceClient.InsertCallDetailsAsyc(calldata); //logger.Info("Data received from web service while insert call details, Code: " + serviceResult.ResultCode + ", Description: " + serviceResult.ResultDescription); } catch //(Exception ex) { //logger.Error("Error occurred as " + ex.Message); } }
public App() : base() { _connection = new Test.TestConnection(); _portSettings = new PortSettings(); _dataFormater = new HexDataFormater(); _dataFlowController = new DataFlowController(_connection.Send); _dataFlowController.OnEventuallyDataRecieved = DisplayEventuallyRecievedData; _connection.OnDataRecieved = _dataFlowController.OnDataRecieved; _window = new MainWindow(); _window.PortComboBox.ItemsSource = PortSettings.GetPortNames(); _window.PortComboBox.SelectedIndex = 0; _window.PortComboBox.SelectionChanged += (sender, args) => { var selected = _window.PortComboBox.SelectedItem; if (selected != null) { _portSettings.PortName = (string)selected; } }; _window.BaudRateComboBox.ItemsSource = PortSettings.GetCommonBaudRates(); _window.BaudRateComboBox.SelectedIndex = 0; _window.ParityComboBox.ItemsSource = Enum.GetValues(typeof(Parity)); _window.ParityComboBox.SelectedIndex = 0; _window.DataBitsComboBox.ItemsSource = new int[] { 1, 2, 4, 8, 16 }; _window.DataBitsComboBox.SelectedIndex = 0; _window.StopBitsComboBox.ItemsSource = Enum.GetValues(typeof(StopBits)); _window.StopBitsComboBox.SelectedIndex = 0; _window.TimeOutMSComboBox.ItemsSource = new int[] { 100, 200, 500, 1000 }; _window.TimeOutMSComboBox.SelectedIndex = 0; //Adding modules to modules menu foreach (var module in LoadModules()) { _window.ModulesMenu.AddModuleButton("module", () => { _window.ContentStackPanel.Children.Clear(); _window.ContentStackPanel.Children.Add(module.GetPanel()); }); module.Send = (data, length, onRecieved) => { var dataPair = new DataFlowPair(); dataPair.SetSent(_dataFormater.ToString(data, length)); if (onRecieved != null) { _dataFlowController.Send(data, length, (d, l) => { onRecieved(data, length); dataPair.SetRecieved(_dataFormater.ToString(d, l)); }); } else { _dataFlowController.Send(data, length); } _window.DataFlowPanel.Children.Add(dataPair); }; } _window.Show(); }
private void OnAutoFindPrinter(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e) { //Event handler for user selected to auto find printer bool found = false; try { this.cboPort.Enabled = false; this.cboBaud.Enabled = this.cboDataBits.Enabled = this.cboParity.Enabled = this.cboStopBits.Enabled = false; for (int i = 0; i < this.cboPort.Items.Count; i++) { //Open the printer on each port if (found) { break; } this.cboPort.SelectedIndex = i; try { if (this.mPrinter.On) { this.mPrinter.TurnOff(); } PortSettings settings = this.mPrinter.Settings; settings.PortName = this.cboPort.Text; this.mPrinter.Settings = settings; this.mPrinter.TurnOn(); } catch (Exception) { } if (this.mPrinter.On) { //Vary the port settings if the printer port is open for (int j = 0; j < this.cboBaud.Items.Count; j++) { if (found) { break; } this.cboBaud.SelectedIndex = j; for (int k = 0; k < this.cboDataBits.Items.Count; k++) { if (found) { break; } this.cboDataBits.SelectedIndex = k; for (int m = 0; m < this.cboParity.Items.Count; m++) { if (found) { break; } this.cboParity.SelectedIndex = m; for (int n = 0; n < this.cboStopBits.Items.Count; n++) { this.cboStopBits.SelectedIndex = n; PortSettings settings = this.mPrinter.Settings; settings.BaudRate = Convert.ToInt32(this.cboBaud.Text); settings.DataBits = Convert.ToInt32(this.cboDataBits.Text); switch (this.cboParity.Text.ToLower()) { case "none": settings.Parity = System.IO.Ports.Parity.None; break; case "even": settings.Parity = System.IO.Ports.Parity.Even; break; case "odd": settings.Parity = System.IO.Ports.Parity.Odd; break; } switch (Convert.ToInt32(this.cboStopBits.Text)) { case 1: settings.StopBits = System.IO.Ports.StopBits.One; break; case 2: settings.StopBits = System.IO.Ports.StopBits.Two; break; } this.mPrinter.Settings = settings; //LogEvent(LOG_ID_PORT + ": Auto Find Printer @" + this.mPrinter.Settings.PortName + "," + this.mPrinter.Settings.BaudRate.ToString() + "," + this.mPrinter.Settings.DataBits.ToString() + "," + this.mPrinter.Settings.Parity.ToString() + "," + this.mPrinter.Settings.StopBits.ToString() + "\n"); Application.DoEvents(); //refreshPrinterStatus(); //found = (this.lblModel.Text.Length > 7); if (found) { break; } } } } } } } //OnRS232DCEChanged(null,null); } catch (Exception) { } }
//========================================================================= #endregion //========================================================================= //========================================================================= #region -= public methods =- //========================================================================= public void ResetToDefaults() { this._portSettings = new PortSettings(); this.SetValuesFromSettings(); }
public AppSettings LoadAppSettings() { AppSettings _appConfig = null; if (!File.Exists(GetAppDirectory + @"\AppConfig.xml")) { if (CurrentPortSettings == null) { CurrentPortSettings = new PortSettings(); } CurrentPortSettings = CurrentPortSettings.GetDefaultValues(); _appConfig = new AppSettings() { IsSerialPortEnabled = CurrentPortSettings.IsSerialPortEnabled, ReceiverName = CurrentPortSettings.ReceiverName, Description = CurrentPortSettings.Description, PortName = CurrentPortSettings.PortName, BaudRate = CurrentPortSettings.BaudRate, Parity = CurrentPortSettings.Parity, DataBits = CurrentPortSettings.DataBits, StopBits = CurrentPortSettings.StopBits, Handshake = CurrentPortSettings.Handshake, OutputDataDirectory = GetAppDirectory }; try { XmlHelper.SerializeToXmlFile <AppSettings>(_appConfig, "AppConfig.xml"); } catch (Exception ex) { _logger.Error("[Generic Exception] LoadAppSettings->SerializeToXmlFile: " + ex.ToString()); return(null); } } try { var obj = XmlHelper.DeserializeFromXmlFile <AppSettings>(GetAppDirectory + @"\AppConfig.xml"); _appConfig = new AppSettings(); _appConfig.IsSerialPortEnabled = obj.IsSerialPortEnabled; _appConfig.ReceiverName = obj.ReceiverName; _appConfig.Description = obj.Description; _appConfig.PortName = obj.PortName; _appConfig.BaudRate = obj.BaudRate; _appConfig.Parity = obj.Parity; _appConfig.DataBits = obj.DataBits; _appConfig.StopBits = obj.StopBits; _appConfig.Handshake = obj.Handshake; _appConfig.OutputDataDirectory = obj.OutputDataDirectory; return(_appConfig); } catch (Exception ex) { _logger.Error("[Generic Exception] LoadAppSettings->DeserializeFromXmlFile: " + ex.ToString()); return(null); } }