private static void SaveComSetting(XmlDocument config, UserOperation operation, XmlNode operationSetting) { ComSetting cs = operation.Setting as ComSetting; XmlNode comNumber = config.CreateNode(XmlNodeType.Element, "ComNumber", null); comNumber.InnerText = cs.ComNumber; XmlNode baudRate = config.CreateNode(XmlNodeType.Element, "BaudRate", null); baudRate.InnerText = cs.BaudRate.ToString(); XmlNode dataBit = config.CreateNode(XmlNodeType.Element, "DataBit", null); dataBit.InnerText = cs.DataBits.ToString(); XmlNode stopBit = config.CreateNode(XmlNodeType.Element, "StopBit", null); stopBit.InnerText = cs.StopBits.ToString(); XmlNode parity = config.CreateNode(XmlNodeType.Element, "Parity", null); parity.InnerText = cs.Parity.ToString(); operationSetting.AppendChild(comNumber); operationSetting.AppendChild(baudRate); operationSetting.AppendChild(dataBit); operationSetting.AppendChild(stopBit); operationSetting.AppendChild(parity); }
public JsonResult Index() { TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0); string timestamp = Convert.ToInt64(ts.TotalSeconds).ToString(); string sign = MD5Encrypt(MD5Encrypt(appkey + timestamp) + appsecret); JavaScriptSerializer json = new JavaScriptSerializer(); ComSetting cs = new ComSetting(); cs.timestamp = timestamp; cs.appkey = appkey; cs.sign = sign; cs.apiUrl = host; cs.type = "courseware"; if (CookieHelper.GetCookieValue("UserId") != null && CookieHelper.GetCookieValue("UserId") != string.Empty) { cs.userId = CookieHelper.GetCookieValue("UserId"); if (CookieHelper.GetCookieValue("DisplayUserName") != null) { cs.userName = CookieHelper.GetCookieValue("DisplayUserName"); } if (CookieHelper.GetCookieValue("DepartId") != null) { cs.departId = CookieHelper.GetCookieValue("DepartId"); } } return(Json(cs, JsonRequestBehavior.AllowGet)); }
public void Add(ComSetting entity) { using (var context = new AISContext <ComSetting>()) { context.DBEntities.Add(entity); context.SaveChanges(); } }
//加载继电器配置文件 public List <UserRelayArray> LoadRelayConfig() { try { XmlDocument relayConfig = new XmlDocument(); relayConfig.Load(_relayConfigFile); XmlNode root = relayConfig.SelectSingleNode("Root"); XmlNodeList relays = root.SelectNodes("Relay"); _relays.Clear(); foreach (XmlNode relay in relays) { string name = relay.SelectSingleNode("Name").InnerText; int _totoalApproachCount = int.Parse(relay.SelectSingleNode("TotoalApproach").InnerText); ComSetting cs = new ComSetting(); XmlNode operationSetting = relay.SelectSingleNode("OperationSetting"); cs.ComNumber = operationSetting.SelectSingleNode("ComNumber").InnerText; cs.BaudRate = int.Parse(operationSetting.SelectSingleNode("BaudRate").InnerText); cs.DataBits = int.Parse(operationSetting.SelectSingleNode("DataBit").InnerText); cs.StopBits = int.Parse(operationSetting.SelectSingleNode("StopBit").InnerText); cs.Parity = (Parity)Enum.Parse(typeof(Parity), operationSetting.SelectSingleNode("Parity").InnerText); UserRelayArray _userRelayModule = new UserRelayArray(name, cs, _totoalApproachCount); XmlNode _relaydata = relay.SelectSingleNode("RelayData"); XmlNodeList _relayapproachs = _relaydata.SelectNodes("Approach"); foreach (XmlNode _relayapproach in _relayapproachs) { int id = int.Parse(_relayapproach.Attributes["Id"].Value); UserRelaySetting _userRelaySetting = new UserRelaySetting(id, _totoalApproachCount); XmlNodeList temps = _relayapproach.SelectNodes("Mode"); RelayOperationDataList _relayOperationList = new RelayOperationDataList(); foreach (XmlNode temp in temps) { string _relayOperationType = temp.Attributes["Name"].Value; string _data = temp.Attributes["Data"].Value; _relayOperationList.SetOperationData((RelayOperationType)Enum.Parse(typeof(RelayOperationType), _relayOperationType), _data); } _userRelaySetting.AddRelayOperationData(_relayOperationList); _userRelayModule.AddRelayData(_userRelaySetting); } _relays.Add(_userRelayModule); } return(_relays); } catch { Helper.ShowMessageBox("提示", "未找到继电器配置文件"); return(null); } }
public Site(uint num, string name, ComSetting comSetting) { this.num = num; this.name = name; this.ip = ""; this.port = 12345; this.com = comSetting.com; this.baudRate = comSetting.baudRate; this.dataBits = comSetting.dataBits; this.stopBits = comSetting.stopBits; this.parity = comSetting.parity; commType = CommType.Serial; }
private void btnOk_Click(object sender, EventArgs e) { _prjName = tbName.Text; _deviceComSetting = new ComSetting(); _baudRate = int.Parse(cbBaudrate.Text); _dataBit = int.Parse(cbDatabit.Text); _stopBit = int.Parse(cbStopbit.Text); _parity = (Parity)cbParity.SelectedIndex; _deviceComSetting.BaudRate = _baudRate; _deviceComSetting.StopBits = _stopBit; _deviceComSetting.DataBits = _dataBit; _deviceComSetting.Parity = _parity; DialogResult = DialogResult.OK; }
private void btnSetting_Click(object sender, EventArgs e) { if (cbOprationType.Text == "TCP" || cbOprationType.Text == "UDP") { IpSetting settingForm = new IpSetting(); if (Setting != null && (Setting as NetworkSetting) != null) { NetworkSetting ns = (NetworkSetting)Setting; settingForm.Ip = ns.Ip; settingForm.Port = ns.Port; } if (settingForm.ShowDialog() == System.Windows.Forms.DialogResult.OK) { NetworkSetting ns = new NetworkSetting(); ns.Ip = settingForm.Ip; ns.Port = settingForm.Port; Setting = ns; } } else if (cbOprationType.Text == "串口") { SerialPortSetting settingForm = new SerialPortSetting(); if (Setting != null && (Setting as ComSetting) != null) { ComSetting cs = (ComSetting)Setting; settingForm.ComNumber = cs.ComNumber; settingForm.BaudRate = cs.BaudRate; settingForm.Databit = cs.DataBits; settingForm.StopBit = cs.StopBits; settingForm.Parity = cs.Parity; } if (settingForm.ShowDialog() == System.Windows.Forms.DialogResult.OK) { ComSetting cs = new ComSetting(); cs.ComNumber = settingForm.ComNumber; cs.BaudRate = settingForm.BaudRate; cs.StopBits = settingForm.StopBit; cs.DataBits = settingForm.Databit; cs.Parity = settingForm.Parity; Setting = cs; } } }
public EVOTestForm() { InitializeComponent(); Microsoft.VisualBasic.Devices.Computer pc = new Microsoft.VisualBasic.Devices.Computer(); if (pc.Ports.SerialPortNames.Count == 0) { this.comport.Items.Add("No Com Port Use!!!"); return; } foreach (string s in pc.Ports.SerialPortNames) { this.comport.Items.Add(s); } _ComSetting = new ComSetting(); LoadComSet(); this.DataContext = _ComSetting; }
public List <UserPrjSetting> LoadPrjData() { try { XmlDocument prjConfig = new XmlDocument(); prjConfig.Load(_prjConfigFile); XmlNode prjroot = prjConfig.SelectSingleNode("ProjectorData"); _prjSettings.Clear(); foreach (XmlNode prjector in prjroot) { string _prjName = prjector.Name; XmlNodeList _prjCommsetting = prjector.SelectNodes("OperationSetting"); ComSetting pcs = new ComSetting(); foreach (XmlNode comsetting in _prjCommsetting) { int _baudRate = int.Parse(comsetting.SelectSingleNode("BaudRate").InnerText); int _dataBits = int.Parse(comsetting.SelectSingleNode("DataBit").InnerText); int _stopBits = int.Parse(comsetting.SelectSingleNode("StopBit").InnerText); Parity _parity = (Parity)Enum.Parse(typeof(Parity), comsetting.SelectSingleNode("Parity").InnerText); pcs.BaudRate = _baudRate; pcs.DataBits = _dataBits; pcs.StopBits = _stopBits; pcs.Parity = _parity; } UserPrjSetting _ups = new UserPrjSetting(_prjName, pcs); XmlNodeList _tempprjStates = prjector.SelectNodes("Mode"); _prjSettings.Add(_ups); foreach (XmlNode _prjState in _tempprjStates) { string _statename = _prjState.Attributes["Name"].Value; string _statedata = _prjState.Attributes["Data"].Value; PrjOperationType _mode = (PrjOperationType)Enum.Parse(typeof(PrjOperationType), _statename); UserPrjOperation uds = new UserPrjOperation(_mode, _statedata); _ups.DeviceStates.Add(uds); } } return(_prjSettings); } catch { Helper.ShowMessageBox("提示", "未找到投影机配置文件!"); return(null); } }
private void btnOk_Click(object sender, EventArgs e) { try { ComSetting cs = new ComSetting(); cs.ComNumber = _comNumber; cs.BaudRate = _baudRate; cs.DataBits = _dataBits; cs.StopBits = _stopBits; cs.Parity = _parity; _setting = cs; if (Setting == null) { Helper.ShowMessageBox("设置", "先进行数据配置"); return; } if (tbName.Text == "") { _operationName = cbRelayName.SelectedItem.ToString() + cbState.SelectedItem.ToString() + cbId.SelectedItem.ToString(); } else { _operationName = tbName.Text; } _time = int.Parse(tbTime.Text); if (Data.Length <= 0) { Helper.ShowMessageBox("提示", "数据不为空!"); return; } if (CheckTime(_time) && CheckData(Data)) { DialogResult = System.Windows.Forms.DialogResult.OK; } } catch { Helper.ShowMessageBox("提示", "数据格式不对!"); } }
public void Update(ComSetting entity) { using (var context = new AISContext <ComSetting>()) { ComSetting data = context.DBEntities.Where(i => i.CompanyID == entity.CompanyID).FirstOrDefault(); if (data == null) { //TBD for error exception data not exist throw new Exception("Data Not Exist"); } else { data.CompanyName = entity.CompanyName; data.CompanyAddress = entity.CompanyAddress; data.TokenServiceID = entity.TokenServiceID; context.SaveChanges(); } } }
private void Fill() { textBoxNum.Text = site.num.ToString(); textBoxName.Text = site.name; textBoxIP.Text = site.ip; textBoxPort.Text = site.port.ToString(); radioTcp.Checked = site.commType == ShuiwenLib.Site.CommType.Tcp; radioSerial.Checked = site.commType == ShuiwenLib.Site.CommType.Serial; radioSMS.Checked = site.commType == ShuiwenLib.Site.CommType.SMS; radioGPRS.Checked = site.commType == ShuiwenLib.Site.CommType.GPRS; ComSetting cs = new ComSetting() { com = site.com, dataBits = site.dataBits, baudRate = site.baudRate, stopBits = site.stopBits, parity = site.parity, }; comConfigControl1.SetCom(cs); }
public void Delete(ComSetting entity) { throw new NotImplementedException(); }
private void LoadComSet() { _ComSetting = (ComSetting)Function.XmlSerializer.LoadFromXml("EVO.com.xml", typeof(ComSetting)); }
/// <summary> /// 加载配置文件 /// </summary> private void LoadConfig() { try { XmlDocument config = new XmlDocument(); config.Load(_configFile); XmlNode root = config.SelectSingleNode("Root"); #region LoadNormalCommand XmlNodeList areas = root.SelectNodes("Area"); _areas.Clear(); foreach (XmlNode area in areas) { string areaName = area.SelectSingleNode("AreaName").InnerText; Area tempArea = new Area(areaName); _areas.Add(tempArea); XmlNodeList actions = area.SelectNodes("Action"); foreach (XmlNode action in actions) { string actionName = action.SelectSingleNode("ActionName").InnerText; string actionReceiveData = action.SelectSingleNode("ActionReceiveData").InnerText; UserAction useraction = new UserAction(actionName, actionReceiveData); //tempArea.Actions.Add(useraction); _userAction.Add(useraction); XmlNodeList oprations = action.SelectNodes("Operation"); foreach (XmlNode operation in oprations) { string operationName = operation.SelectSingleNode("OperationName").InnerText; string operationTypeString = operation.SelectSingleNode("OperationType").InnerText; OprationType operationType = (OprationType)Enum.Parse(typeof(OprationType), operationTypeString, true); XmlNode operationSetting = operation.SelectSingleNode("OperationSetting"); object setting = null; if (operationType == OprationType.Com) { ComSetting cs = new ComSetting(); cs.ComNumber = operationSetting.SelectSingleNode("ComNumber").InnerText; cs.BaudRate = int.Parse(operationSetting.SelectSingleNode("BaudRate").InnerText); cs.DataBits = int.Parse(operationSetting.SelectSingleNode("DataBit").InnerText); cs.StopBits = int.Parse(operationSetting.SelectSingleNode("StopBit").InnerText); cs.Parity = (Parity)Enum.Parse(typeof(Parity), operationSetting.SelectSingleNode("Parity").InnerText); setting = cs; } else if (operationType == OprationType.TCP || operationType == OprationType.UDP) { NetworkSetting ns = new NetworkSetting(); ns.Ip = operationSetting.SelectSingleNode("IP").InnerText; ns.Port = int.Parse(operationSetting.SelectSingleNode("Port").InnerText); setting = ns; } string dataTypeString = operation.SelectSingleNode("OperationDataType").InnerText; DataType dataType = (DataType)Enum.Parse(typeof(DataType), dataTypeString, true); string data = operation.SelectSingleNode("OperationData").InnerText; int time = int.Parse(operation.SelectSingleNode("OperationTime").InnerText); UserOperation userOperation = new UserOperation(operationName, operationType, dataType, setting, data, time); _userOperation.Add(userOperation); } } } _arealist.Refresh(); #endregion } catch (Exception ex) { MessageBox.Show("未找到配置命令!"); } }
//加载时间轴配置 public List <UserAction> LoadTimeShaft() { try { XmlDocument config = new XmlDocument(); config.Load(_configFile); XmlNode root = config.SelectSingleNode("Root"); #region LoadTimeShaft XmlNode timeShafts = root.SelectSingleNode("TimeShaft"); XmlNodeList timeActions = timeShafts.SelectNodes("Action"); _shaft_actions.Clear(); foreach (XmlNode action in timeActions) { string actionName = action.SelectSingleNode("ActionName").InnerText; string actionReceiveData = action.SelectSingleNode("ActionReceiveData").InnerText; UserAction userAction = new UserAction(actionName, actionReceiveData); _shaft_actions.Add(userAction); XmlNodeList operations = action.SelectNodes("Operation"); foreach (XmlNode operation in operations) { string operationName = operation.SelectSingleNode("OperationName").InnerText; string operationTypeString = operation.SelectSingleNode("OperationType").InnerText; CommunicationType operationType = (CommunicationType)Enum.Parse(typeof(CommunicationType), operationTypeString, true); XmlNode operationSetting = operation.SelectSingleNode("OperationSetting"); object setting = null; if (operationType == CommunicationType.Com) { ComSetting cs = new ComSetting(); cs.ComNumber = operationSetting.SelectSingleNode("ComNumber").InnerText; cs.BaudRate = int.Parse(operationSetting.SelectSingleNode("BaudRate").InnerText); cs.DataBits = int.Parse(operationSetting.SelectSingleNode("DataBit").InnerText); cs.StopBits = int.Parse(operationSetting.SelectSingleNode("StopBit").InnerText); cs.Parity = (Parity)Enum.Parse(typeof(Parity), operationSetting.SelectSingleNode("Parity").InnerText); setting = cs; } else if (operationType == CommunicationType.TCP || operationType == CommunicationType.UDP) { NetworkSetting ns = new NetworkSetting(); ns.Ip = operationSetting.SelectSingleNode("IP").InnerText; ns.Port = int.Parse(operationSetting.SelectSingleNode("Port").InnerText); setting = ns; } string dataTypeString = operation.SelectSingleNode("OperationDataType").InnerText; DataType dataType = (DataType)Enum.Parse(typeof(DataType), dataTypeString, true); string data = operation.SelectSingleNode("OperationData").InnerText; int time = int.Parse(operation.SelectSingleNode("OperationTime").InnerText); UserOperation userOperation = new UserOperation(operationName, operationType, dataType, setting, data, time); userAction.Operations.Add(userOperation); } } return(_shaft_actions); #endregion } catch (Exception ex) { Helper.ShowMessageBox("提示", "未找到配置命令!"); return(null); } }
public SerialComm(uint num, ComSetting comSetting, Sites sites) { this.siteNum = num; this.comSetting = comSetting; this.sites = sites; }
public List <UserDefinedOperation> LoadUserDefinedData() { try { #region LoadUserDefinedData XmlDocument config = new XmlDocument(); config.Load(_userdefinedConfigFile); XmlNode root = config.SelectSingleNode("Root"); XmlNodeList actions = root.SelectNodes("Action"); _userdefineNames.Clear(); foreach (XmlNode action in actions) { string _actionName = action.Attributes["Name"].Value; UserDefinedOperation _deName = new UserDefinedOperation(_actionName); XmlNodeList operations = action.SelectNodes("Operation"); foreach (XmlNode operation in operations) { string operationName = operation.SelectSingleNode("OperationName").InnerText; string operationTypeString = operation.SelectSingleNode("OperationType").InnerText; CommunicationType operationType = (CommunicationType)Enum.Parse(typeof(CommunicationType), operationTypeString, true); XmlNode operationSetting = operation.SelectSingleNode("OperationSetting"); object setting = null; if (operationType == CommunicationType.Com) { ComSetting cs = new ComSetting(); cs.ComNumber = operationSetting.SelectSingleNode("ComNumber").InnerText; cs.BaudRate = int.Parse(operationSetting.SelectSingleNode("BaudRate").InnerText); cs.DataBits = int.Parse(operationSetting.SelectSingleNode("DataBit").InnerText); cs.StopBits = int.Parse(operationSetting.SelectSingleNode("StopBit").InnerText); cs.Parity = (Parity)Enum.Parse(typeof(Parity), operationSetting.SelectSingleNode("Parity").InnerText); setting = cs; } else if (operationType == CommunicationType.TCP || operationType == CommunicationType.UDP) { NetworkSetting ns = new NetworkSetting(); ns.Ip = operationSetting.SelectSingleNode("IP").InnerText; ns.Port = int.Parse(operationSetting.SelectSingleNode("Port").InnerText); setting = ns; } string dataTypeString = operation.SelectSingleNode("OperationDataType").InnerText; DataType dataType = (DataType)Enum.Parse(typeof(DataType), dataTypeString, true); string data = operation.SelectSingleNode("OperationData").InnerText; int time = int.Parse(operation.SelectSingleNode("OperationTime").InnerText); UserOperation userOperation = new UserOperation(operationName, operationType, dataType, setting, data, time); _deName.AddOperation(userOperation); } _userdefineNames.Add(_deName); } return(_userdefineNames); #endregion } catch (Exception ex) { Helper.ShowMessageBox("提示", "未找到自定义配置文件"); return(null); } }
//加载预约配置 public List <UserOrder> LoadOrderConfig() { try { XmlDocument config = new XmlDocument(); config.Load(_timelineConfig); XmlNode root = config.SelectSingleNode("Root"); XmlNodeList areas = root.SelectNodes("DelayTime"); _orders.Clear(); foreach (XmlNode area in areas) { string areaName = area.SelectSingleNode("TimeValue").InnerText; UserOrder order = new UserOrder(0, 0); order.SetValue(areaName); _orders.Add(order); XmlNodeList operations = area.SelectNodes("Operation"); foreach (XmlNode operation in operations) { string operationName = operation.SelectSingleNode("OperationName").InnerText; string operationTypeString = operation.SelectSingleNode("OperationType").InnerText; CommunicationType operationType = (CommunicationType)Enum.Parse(typeof(CommunicationType), operationTypeString, true); XmlNode operationSetting = operation.SelectSingleNode("OperationSetting"); object setting = null; if (operationType == CommunicationType.Com) { ComSetting cs = new ComSetting(); cs.ComNumber = operationSetting.SelectSingleNode("ComNumber").InnerText; cs.BaudRate = int.Parse(operationSetting.SelectSingleNode("BaudRate").InnerText); cs.DataBits = int.Parse(operationSetting.SelectSingleNode("DataBit").InnerText); cs.StopBits = int.Parse(operationSetting.SelectSingleNode("StopBit").InnerText); cs.Parity = (Parity)Enum.Parse(typeof(Parity), operationSetting.SelectSingleNode("Parity").InnerText); setting = cs; } else if (operationType == CommunicationType.TCP || operationType == CommunicationType.UDP) { NetworkSetting ns = new NetworkSetting(); ns.Ip = operationSetting.SelectSingleNode("IP").InnerText; ns.Port = int.Parse(operationSetting.SelectSingleNode("Port").InnerText); setting = ns; } string dataTypeString = operation.SelectSingleNode("OperationDataType").InnerText; DataType dataType = (DataType)Enum.Parse(typeof(DataType), dataTypeString, true); string data = operation.SelectSingleNode("OperationData").InnerText; int time = int.Parse(operation.SelectSingleNode("OperationTime").InnerText); UserOperation userOperation = new UserOperation(operationName, operationType, dataType, setting, data, time); order.Operations.Add(userOperation); } } return(_orders); } catch (Exception ex) { Helper.ShowMessageBox("提示", "未找到配置文件!"); return(null); } }