void CraneServer_OnDataChanged(object sender, DataChangedEventArgs e) { try { if (e.State == null) { return; } PLC plc = new PLC(); string[] txt = e.ItemName.Split('_'); plc.ID = txt[0]; plc.PicName = "picCrane"; plc.ShowPic = "1"; plc.TextName = "txt" + txt[1]; if (e.ItemName.IndexOf("TaskNo") >= 0) { string TaskNo = Util.ConvertStringChar.BytesToString(e.States); plc.Text = TaskNo; plc.TaskType = ""; plc.TextTypeName = "txtTaskType"; if (TaskNo.Length > 0) { DataTable dtTask = bll.FillDataTable("WCS.SelectWCSTask", new DataParameter[] { new DataParameter("{0}", string.Format("TASKID='{0}'", TaskNo)) }); if (dtTask.Rows.Count > 0) { if (dtTask.Rows[0]["TASKTYPE"].ToString() == "IB") { plc.TaskType = "入库"; } else { plc.TaskType = "出库"; } } } } else if (e.ItemName.IndexOf("PalletCode") >= 0) { plc.Text = Util.ConvertStringChar.BytesToString(e.States); } else if (e.ItemName.IndexOf("CraneAction") >= 0) { int Action = int.Parse(ObjectUtil.GetObject(e.States).ToString()); plc.Text = dicCraneAction[Action]; } else if (e.ItemName.IndexOf("Column") >= 0) { plc.Text = ObjectUtil.GetObject(e.States).ToString(); } else if (e.ItemName.IndexOf("Row") >= 0) { int Row = int.Parse(ObjectUtil.GetObject(e.States).ToString()); if (Row >= 2) { Row = Row - 1; } plc.Text = Row.ToString(); } else { string strErrorNo = ObjectUtil.GetObject(e.States).ToString(); if (strErrorNo != "0") { DataRow[] drs = dtCraneError.Select(string.Format("warncode='{0}'", strErrorNo)); if (drs.Length > 0) { plc.Text = drs[0]["WARNDESC"].ToString(); } else { plc.Text = "未知错误!"; } plc.TextName = "txtErrorDesc"; plc.IsErr = "1"; plc.ErrCode = strErrorNo; plc.TextErrName = "txtErrorNo"; } else { plc.Text = ""; plc.TextName = "txtErrorDesc"; plc.IsErr = "0"; plc.ErrCode = strErrorNo; plc.TextErrName = "txtErrorNo"; } } PLCS.PLCInfo(plc); } catch (Exception ex) { MCP.Logger.Error("监控界面CraneServer_OnDataChanged中出现异常" + ex.Message); } }
// // GET: /Plc/Events/5 public ActionResult Events(object id, string from = null, string to = null, string numbers = null, string message = null, bool hideBreak = false, bool desc = false, bool groups = false) { PLC plc = null; try { int plcid = Convert.ToInt32(id); plc = _db.GetPLC(plcid); } catch (Exception) { } if (plc == null) { plc = _db.GetPLC(id.ToString()); } if (plc == null) { return(RedirectToAction("Index")); } //ViewBag.PlcFullName = plc.FullName; var plcEventListDTO = new PlcEventListDTO { Plc = plc, Numbers = numbers, Message = message, From = DateTime.Now.Date, To = DateTime.Now.Date, HideBreak = hideBreak, Desc = desc, Group = groups, }; if (!string.IsNullOrWhiteSpace(from)) { try { plcEventListDTO.From = DateTime.Parse(from); } catch { } } if (!string.IsNullOrWhiteSpace(to)) { try { plcEventListDTO.To = DateTime.Parse(to); } catch {} } plcEventListDTO.PlcEventDTOList = _db.GetPlcEventDTOList( plcEventListDTO.Plc, plcEventListDTO.From, plcEventListDTO.To.AddDays(1), plcEventListDTO.NumberList, plcEventListDTO.Message, plcEventListDTO.HideBreak, plcEventListDTO.Desc ); if (plcEventListDTO.PlcEventDTOList == null) { return(RedirectToAction("Index")); } return(View(plcEventListDTO)); }
/// <summary> /// Save PLC /// </summary> private void SavePLC() { using (PLC itemPLC = PLC.GetByKey(itemId, curCountryCode)) { if (itemPLC != null) { #region Bundles rule // public intro date for bundles cannot be before the latest public intro dates of all the components. // Obsolescence dates cannot be set later than the earliest obsolescence date of the components if (curItemType == (int)ItemTypesEnum.BUNDLE) { if (!itemPLC.CheckPLCforBundle(curCountryCode, (DateTime?)wdcPID.Value, (DateTime?)wdcObsoleteDate.Value)) { lError.Text = PLC.LastError; lError.Visible = true; return; } } #endregion // all PLC are unlock before changes, prevent API rules #region PID itemPLC.FullLocked = false; itemPLC.FullDate = (DateTime?)wdcPID.Value; itemPLC.FullDateType = cboxPID.Checked ? 'C' : 'R'; itemPLC.FullLocked = cbPIDL.Checked; #endregion #region Announcement date itemPLC.AnnouncementLocked = false; itemPLC.AnnouncementDate = (DateTime?)wdcAnnouncementDate.Value; itemPLC.AnnouncementDateType = cboxAnnouncementDate.Checked ? 'C' : 'R'; itemPLC.AnnouncementLocked = cbAnnL.Checked; #endregion #region Blind date itemPLC.BlindLocked = false; itemPLC.BlindDate = (DateTime?)wdcBlindDate.Value; itemPLC.BlindDateType = cboxBlindDate.Checked ? 'C' : 'R'; itemPLC.BlindLocked = cbBlindL.Checked; #endregion #region Obsolete date itemPLC.ObsoleteLocked = false; itemPLC.ObsoleteDate = (DateTime?)wdcObsoleteDate.Value; itemPLC.ObsoleteDateType = cboxObsoleteDate.Checked ? 'C' : 'R'; itemPLC.ObsoleteLocked = cbObsoL.Checked; #endregion #region Removal date itemPLC.RemovalLocked = false; itemPLC.RemovalDate = (DateTime?)wdcRemovalDate.Value; itemPLC.RemovalDateType = cboxRemovalDate.Checked ? 'C' : 'R'; itemPLC.RemovalLocked = cbRemovL.Checked; #endregion if (itemPLC.Save(SessionState.User.Id)) { //Sateesh -- Language Scope Management - ACQ 3.6 - 27/05/2009 Item.UpdateWorkingTables(itemPLC.ItemId, SessionState.Culture.Code, true); if (Request["dg"] == null) { Page.ClientScript.RegisterStartupScript(this.GetType(), "reloadParent", "<script>ReloadParent();</script>"); } else // We have been opened by another page that contains an Infragistics Grid // Call parent refresh function to reflect the changes. { if (Request["row"] != null && Request["col"] != null) { Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "reloadParent", "<script>top.window.close()</script>"); } } } else { lError.Text = PLC.LastError; lError.Visible = true; } } } }
public BoolArrayAccessor(PLC plc, int offset) : base(plc, offset, 1) { }
/// <summary> /// 断开连接 /// </summary> public void Disconnect() { PLC?.Disconnect(); NotifyOfPropertyChange(() => IsConnect); }
/// <summary> /// Retrieve PLC for the item and culture requested /// </summary> private void RetrievePLC() { #region Update PLC Label lbPID.Text = UITools.PIDLabel; lbPOD.Text = UITools.PODLabel; lbBlind.Text = UITools.BlindLabel; lbAnnouncement.Text = UITools.AnnouncementLabel; lbRemoval.Text = UITools.RemovalLabel; #endregion using (PLC itemPLC = PLC.GetByKey(itemId, curCountryCode)) { if (itemPLC != null) { using (Country plcCountry = itemPLC.Country) { #region Announcement date wdcAnnouncementDate.Value = itemPLC.AnnouncementDate ?? null; iRegionAnnouncement.ImageUrl = itemPLC.AnnouncementDateType == 'R' ? "/hc_v4/img/flags/" + plcCountry.MainRegionCode + ".gif" : "/hc_v4/img/flags/" + curCountryCode + ".gif"; iRegionAnnouncement.Visible = itemPLC.AnnouncementDate != null; iRegionAnnouncement.ToolTip = itemPLC.AnnouncementDateType == 'R' ? "Regional date" : "Country date"; cboxAnnouncementDate.Visible = (itemPLC.AnnouncementDateType == 'R'); cboxAnnouncementDate.Checked = (itemPLC.AnnouncementDateType == 'C'); cbAnnL.Checked = itemPLC.AnnouncementLocked; #endregion #region Blind date wdcBlindDate.Value = itemPLC.BlindDate ?? null; iRegionBlind.ImageUrl = itemPLC.BlindDateType == 'R' ? "/hc_v4/img/flags/" + plcCountry.MainRegionCode + ".gif" : "/hc_v4/img/flags/" + curCountryCode + ".gif"; iRegionBlind.Visible = itemPLC.BlindDate != null; iRegionBlind.ToolTip = itemPLC.BlindDateType == 'R' ? "Regional date" : "Country date"; cboxBlindDate.Visible = (itemPLC.BlindDateType == 'R'); cboxBlindDate.Checked = (itemPLC.BlindDateType == 'C'); cbBlindL.Checked = itemPLC.BlindLocked; #endregion #region PID wdcPID.Value = itemPLC.FullDate ?? null; iRegionPID.ImageUrl = itemPLC.FullDateType == 'R' ? "/hc_v4/img/flags/" + plcCountry.MainRegionCode + ".gif" : "/hc_v4/img/flags/" + curCountryCode + ".gif"; iRegionPID.Visible = itemPLC.FullDate != null; iRegionPID.ToolTip = itemPLC.FullDateType == 'R' ? "Regional date" : "Country date"; cboxPID.Visible = (itemPLC.FullDateType == 'R'); cboxPID.Checked = (itemPLC.FullDateType == 'C'); cbPIDL.Checked = itemPLC.FullLocked; #endregion #region Obsolete date wdcObsoleteDate.Value = itemPLC.ObsoleteDate ?? null; iRegionObso.ImageUrl = itemPLC.ObsoleteDateType == 'R' ? "/hc_v4/img/flags/" + plcCountry.MainRegionCode + ".gif" : "/hc_v4/img/flags/" + curCountryCode + ".gif"; iRegionObso.Visible = itemPLC.ObsoleteDate != null; iRegionObso.ToolTip = itemPLC.ObsoleteDateType == 'R' ? "Regional date" : "Country date"; cboxObsoleteDate.Visible = (itemPLC.ObsoleteDateType == 'R'); cboxObsoleteDate.Checked = (itemPLC.ObsoleteDateType == 'C'); cbObsoL.Checked = itemPLC.ObsoleteLocked; //Prabhu - Fix for HPeZilla Bug 70814 - CRYS: Issue with the "PLC" Edit Window Date Fields //Commented out the if condition as it not needed //if ((Convert.ToDateTime(wdcObsoleteDate.Value).AddDays(30) < DateTime.Now) && (itemPLC.ObsoleteDate != null)) //{ // wdcObsoleteDate.Enabled = false; // cboxObsoleteDate.Enabled = false; // cbObsoL.Enabled = false; //} #endregion #region Removal date wdcRemovalDate.Value = itemPLC.RemovalDate ?? null; iRegionRemoval.ImageUrl = itemPLC.RemovalDateType == 'R' ? "/hc_v4/img/flags/" + plcCountry.MainRegionCode + ".gif" : "/hc_v4/img/flags/" + curCountryCode + ".gif"; iRegionRemoval.Visible = itemPLC.RemovalDate != null; iRegionRemoval.ToolTip = itemPLC.RemovalDateType == 'R' ? "Regional date" : "Country date"; cboxRemovalDate.Visible = (itemPLC.RemovalDateType == 'R'); cboxRemovalDate.Checked = (itemPLC.RemovalDateType == 'C'); cbRemovL.Checked = itemPLC.RemovalLocked; #endregion #region "Ugly PMT code" // Easy Content awesome requirement // Display a warning when PMT date is more recent and different from current obso and full date if (itemPLC.ObsoleteLocked || itemPLC.FullLocked) { bool bShowFullPMT = false, bShowObsoletePMT = false; using (Database dbObj = new Database(SessionState.CacheComponents["Inbound_DB"].ConnectionString)) { if (dbObj != null) { using (DataSet dsPMT = dbObj.RunSQLReturnDataSet("Select FileTimeStamp FROM Interfaces WHERE InterfaceId = 3")) { if (dsPMT != null && dsPMT.Tables.Count == 1 && dsPMT.Tables[0].Rows.Count == 1 && dsPMT.Tables[0].Rows[0][0] != DBNull.Value) { DateTime?pmtFileDate = Utils.PMTConvertToDate(dsPMT.Tables[0].Rows[0][0].ToString()); if (pmtFileDate != null) { using (DataSet ds = dbObj.RunSPReturnDataSet("QDE_GetPMTInfo", new SqlParameter("@CountryCode", curCountryCode) , new SqlParameter("@LanguageCode", curLanguageCode) , new SqlParameter("@Sku", curSku))) { if (ds != null && ds.Tables.Count == 1 && ds.Tables[0].Rows.Count == 1) { DateTime?pmtFull = HyperCatalog.DataAccessLayer.SqlDataAccessLayer.GetProperDate(ds.Tables[0].Rows[0]["FullDate"]); DateTime?pmtObso = HyperCatalog.DataAccessLayer.SqlDataAccessLayer.GetProperDate(ds.Tables[0].Rows[0]["ObsoleteDate"]); bShowFullPMT = pmtFull.HasValue && itemPLC.FullLocked && pmtFileDate > itemPLC.FullModifyDate && itemPLC.FullDate != pmtFull; bShowObsoletePMT = pmtObso.HasValue && itemPLC.ObsoleteLocked && pmtFileDate > itemPLC.ObsoleteModifyDate && itemPLC.ObsoleteDate != pmtObso; if (bShowFullPMT) { lbPID.Text = lbPID.Text + "<a href='javascript://' title='" + SessionState.User.FormatUtcDate(pmtFull.Value, false, SessionState.User.FormatDate).Substring(0, 10) + "'><font color=red><b>(PMT)</b></font></a>"; } if (bShowObsoletePMT) { lbPOD.Text = lbPOD.Text + "<a href='javascript://' title='" + SessionState.User.FormatUtcDate(pmtObso.Value, false, SessionState.User.FormatDate).Substring(0, 10) + "'><font color=red><b>(PMT)</b></font></a>"; } } else { Trace.Warn("Error running [Select * FROM PMT WHERE CountryCode = '" + curCountryCode + "' AND LanguageCode = '" + curLanguageCode + "' AND ProductNumber = '" + curSku + "'] query :" + dbObj.LastError); } } } else { Trace.Warn("Error : pmtFileDate return invalid datetime"); } } else { Trace.Warn("Error : Interface Id (#3) not found"); } } } else { Trace.Warn("Error : Cannot connect to Inbound DB [" + SessionState.CacheComponents["Inbound_DB"].ConnectionString + "]"); } } } #endregion // stored in JS the current value of announcement and the type of announcement date, use for the rule // stored in JS the current value of blind and the type of blind date, use for the rule //Commented for #2807 -- ITG GS: Error in "Products Nearly Obsolete" Page //string script = "var annR='" + itemPLC.AnnouncementDateType.Value + "';var blindR='" + itemPLC.BlindDateType.Value + "';"; // Fix for 2807 and 71549 are the same (Chardonnay and PRISM fixes) string script = "var annR='" + itemPLC.AnnouncementDateType + "';var blindR='" + itemPLC.BlindDateType + "';"; if (itemPLC.AnnouncementDate.HasValue) { int m = itemPLC.AnnouncementDate.Value.Month - 1; script = script + "var pann= new Date(" + itemPLC.AnnouncementDate.Value.Year.ToString() + ", " + m.ToString() + ", " + itemPLC.AnnouncementDate.Value.Day.ToString() + ");"; } else { script = script + "var pann= null;"; } if (itemPLC.BlindDate.HasValue) { int m = itemPLC.BlindDate.Value.Month - 1; script = script + "var pblind= new Date(" + itemPLC.BlindDate.Value.Year.ToString() + ", " + m.ToString() + ", " + itemPLC.BlindDate.Value.Day.ToString() + ");"; } else { script = script + "var pblind= null;"; } Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "script", "<script>" + script + "</script>"); } } } }
public Int32ArrayAccessor(PLC plc, int offset) : base(plc, offset, 4) { }
static int ConnectToPLC(PLC inputPLC) { return(Client.ConnectTo(inputPLC.IPAddress, 1, 1)); }
public FloatArrayAccessor(PLC plc, int offset) : base(plc, offset, 4) { }
public void RegisterAll(PLC plcRulliera, TabControl tabControl3) { throw new NotImplementedException(); }
/// <summary> /// Creates a struct of a specified type by an array of bytes. /// </summary> /// <param name="structType">The struct type</param> /// <param name="bytes">The array of bytes</param> /// <returns>The object depending on the struct type or null if fails(array-length != struct-length</returns> public static object FromBytes(DataBlock structType, byte[] bytes, PLC plc) { if (bytes == null) { return(null); } if (bytes.Length != GetStructSize(structType)) { return(null); } // and decode it int bytePos = 0; int bitPos = 0; double numBytes = 0.0; var infos = structType.Tags; foreach (Tag info in infos) { switch (info.DataType.ToString()) { case "Bit": // get the value bytePos = (int)Math.Floor(numBytes); bitPos = (int)((numBytes - (double)bytePos) / 0.125); if ((bytes[bytePos] & (int)Math.Pow(2, bitPos)) != 0) { info.Value = true; info.Checked = true; info.Enabled = true; info.Visible = true; info.ValueSelect1 = true; info.ValueSelect2 = true; info.Timestamp = DateTime.Now; } else { info.Value = false; info.Checked = false; info.Enabled = false; info.Visible = false; info.ValueSelect1 = false; info.ValueSelect2 = false; info.Timestamp = DateTime.Now; } numBytes += 0.125; break; case "Byte": numBytes = Math.Ceiling(numBytes); info.Value((bytes[(int)numBytes])); info.Timestamp = DateTime.Now; numBytes++; break; case "Int": numBytes = Math.Ceiling(numBytes); if ((numBytes / 2 - Math.Floor(numBytes / 2.0)) > 0) { numBytes++; } // hier auswerten ushort source = Word.FromBytes(bytes[(int)numBytes + 1], bytes[(int)numBytes]); info.Value = source.ConvertToShort(); info.Timestamp = DateTime.Now; numBytes += 2; break; case "Word": numBytes = Math.Ceiling(numBytes); if ((numBytes / 2 - Math.Floor(numBytes / 2.0)) > 0) { numBytes++; } // hier auswerten info.Value = Word.FromBytes(bytes[(int)numBytes + 1], bytes[(int)numBytes]); info.Timestamp = DateTime.Now; numBytes += 2; break; case "DWord": numBytes = Math.Ceiling(numBytes); if ((numBytes / 2 - Math.Floor(numBytes / 2.0)) > 0) { numBytes++; } // hier auswerten uint sourceUInt = DWord.FromBytes(bytes[(int)numBytes + 3], bytes[(int)numBytes + 2], bytes[(int)numBytes + 1], bytes[(int)numBytes + 0]); info.Value = sourceUInt.ConvertToInt(); info.Timestamp = DateTime.Now; numBytes += 4; break; case "Real": numBytes = Math.Ceiling(numBytes); if ((numBytes / 2 - Math.Floor(numBytes / 2.0)) > 0) { numBytes++; } // hier auswerten info.Value = S7.Net.Types.Double.FromByteArray(new byte[] { bytes[(int)numBytes], bytes[(int)numBytes + 1], bytes[(int)numBytes + 2], bytes[(int)numBytes + 3] }); info.Timestamp = DateTime.Now; numBytes += 4; break; case "Single": numBytes = Math.Ceiling(numBytes); if ((numBytes / 2 - Math.Floor(numBytes / 2.0)) > 0) { numBytes++; } // hier auswerten info.Value = S7.Net.Types.Single.FromByteArray(new byte[] { bytes[(int)numBytes], bytes[(int)numBytes + 1], bytes[(int)numBytes + 2], bytes[(int)numBytes + 3] }); numBytes += 4; break; case "String": // info.Value = plc.ReadStrings(info.Address); info.Timestamp = DateTime.Now; break; default: break; } } return(infos); }
void Monitor_OnPLC(PLCEventArgs args) { if (InvokeRequired) { BeginInvoke(new PLCEventHandler(Monitor_OnPLC), args); } else { try { PLC plc = args.plc; TextBox txt = GetTextBox(plc.TextName, plc.ID); //任务编号 PictureBox pic = GetPictureBox(plc.PicName, plc.ID); TextBox txtErrCode = GetTextBox(plc.TextErrName, plc.ID); TextBox txtTaskType = GetTextBox(plc.TextTypeName, plc.ID); if (txtErrCode != null) { txtErrCode.Text = plc.ErrCode; } if (txtTaskType != null) { txtTaskType.Text = plc.TaskType; } if (txt != null) { txt.Text = plc.Text; if (plc.IsErr == "1") { txt.BackColor = Color.Red; } else { txt.BackColor = Control.DefaultBackColor; } } if (pic != null) { if (plc.ShowPic == "1") { pic.Visible = true; } else { pic.Visible = false; } if (pic.Visible) { if (plc.IsErr == "1") { pic.BackColor = Color.Red; } else { pic.BackColor = Color.Transparent; } } } } catch (Exception ex) { MCP.Logger.Error("监控界面中Monitor_OnPLC出现异常" + ex.Message); } } }
public ArrayAccessor(PLC plc, int offset, int elmSize) { m_plc = plc; m_offset = offset; m_elmSize = elmSize; }
public Control(IPEndPoint ip, string pass) { m_ip = ip; plc = new PLC(ip, pass); plc.Connect(); }
public async Task <int> Handle(CreateHardwareCommand request, CancellationToken cancellationToken) { var contract = await _context.Contracts.FirstOrDefaultAsync(c => c.Id == request.ContractId); if (contract == null) { throw new NullReferenceException("Договор с таким Id не найден."); } Hardware entity; switch (request.HardwareType) { case HardwareType.Cabinet: entity = new Cabinet { Position = request.Position, SerialNumber = request.SerialNumber, Constructed = (DateTime)request.Constructed, ConstructedBy = request.ConstructedBy }; break; case HardwareType.FlowComputer: entity = new FlowComputer { Position = request.Position, SerialNumber = request.SerialNumber, DeviceModel = request.DeviceModel, IP = request.IPAddress, AssemblyVersion = request.AssemblyVersion, CRC32 = request.CRC32, LastConfigDate = request.LastConfigDate }; break; case HardwareType.Flowmeter: entity = new Flowmeter { Position = request.Position, SerialNumber = request.SerialNumber, DeviceModel = request.DeviceModel, DeviceType = request.DeviceType, MinValue = request.MinValue, MaxValue = request.MaxValue, EU = request.EU, Kfactor = request.KFactor, SignalType = request.SignalType, Settings = new ModbusSettings { Address = request.ModbusSettings.Address, BoudRate = request.ModbusSettings.BoudRate, DataBits = request.ModbusSettings.DataBits, Parity = Enum.GetName(typeof(Parity), request.ModbusSettings.Parity), StopBit = request.ModbusSettings.StopBit } }; break; case HardwareType.Network: entity = new NetworkHardware { Position = request.Position, SerialNumber = request.SerialNumber, DeviceType = request.DeviceType, DeviceModel = request.DeviceModel, Mask = request.Mask }; foreach (var item in request.NetworkDevices) { ((NetworkHardware)entity).NetworkDevices.Add(new NetworkDevice { IP = item.IP, MacAddress = item.MacAddress, Name = item.Name }); } break; case HardwareType.PLC: entity = new PLC { Position = request.Position, SerialNumber = request.SerialNumber, DeviceModel = request.DeviceModel, IP = request.IPAddress, AssemblyVersion = request.AssemblyVersion }; break; case HardwareType.Pressure: entity = new Pressure { Position = request.Position, SerialNumber = request.SerialNumber, DeviceModel = request.DeviceModel, DeviceType = request.DeviceType, MinValue = request.MinValue, MaxValue = request.MaxValue, EU = request.EU, SignalType = request.SignalType }; break; case HardwareType.Temperature: entity = new Temperature { Position = request.Position, SerialNumber = request.SerialNumber, DeviceModel = request.DeviceModel, DeviceType = request.DeviceType, MinValue = request.MinValue, MaxValue = request.MaxValue, EU = request.EU, SignalType = request.SignalType }; break; case HardwareType.DiffPressure: entity = new DiffPressure { Position = request.Position, SerialNumber = request.SerialNumber, DeviceModel = request.DeviceModel, DeviceType = request.DeviceType, MinValue = request.MinValue, MaxValue = request.MaxValue, EU = request.EU, SignalType = request.SignalType }; break; case HardwareType.GasAnalyzer: entity = new GasAnalyzer { Position = request.Position, SerialNumber = request.SerialNumber, DeviceModel = request.DeviceModel, DeviceType = request.DeviceType, MinValue = request.MinValue, MaxValue = request.MaxValue, EU = request.EU, SignalType = request.SignalType }; break; case HardwareType.InformPanel: entity = new InformPanel { Position = request.Position, SerialNumber = request.SerialNumber, DeviceModel = request.DeviceModel, DeviceType = request.DeviceType, PanelType = request.PanelType }; break; case HardwareType.FireSensor: entity = new FireSensor { Position = request.Position, SerialNumber = request.SerialNumber, DeviceModel = request.DeviceModel, DeviceType = request.DeviceType }; break; case HardwareType.FireModule: entity = new FireModule { Position = request.Position, SerialNumber = request.SerialNumber, DeviceType = request.DeviceType }; break; case HardwareType.Valve: entity = new Valve { Position = request.Position, SerialNumber = request.SerialNumber, DeviceType = request.DeviceType, DeviceModel = request.DeviceModel, SignalType = request.SignalType, Settings = new ModbusSettings { Address = request.ModbusSettings.Address, BoudRate = request.ModbusSettings.BoudRate, DataBits = request.ModbusSettings.DataBits, Parity = Enum.GetName(typeof(Parity), request.ModbusSettings.Parity), StopBit = request.ModbusSettings.StopBit } }; break; case HardwareType.ARM: entity = new ARM { Position = request.Position, Name = request.ArmName, SerialNumber = request.SerialNumber, Monitor = request.Monitor, MonitorSN = request.MonitorSN, Keyboard = request.Keyboard, KeyboardSN = request.KeyboardSN, Mouse = request.Mouse, MouseSN = request.MouseSN, OS = request.OS, ProductKeyOS = request.ProductKeyOS, HasRAID = request.HasRAID }; foreach (var item in request.NetworkAdapters) { ((ARM)entity).NetworkAdapters.Add(new NetworkAdapter { IP = item.IP, MacAddress = item.MacAddress }); } break; case HardwareType.APC: entity = new APC { Position = request.Position, SerialNumber = request.SerialNumber, DeviceModel = request.DeviceModel, DeviceType = request.DeviceType }; break; default: entity = null; break; } contract.HardwareList.Add(entity); contract.HasProtocol = false; _context.Update(contract); try { await _context.SaveChangesAsync(cancellationToken); } catch (Exception ex) { throw ex; } return(entity.Id); }
/// <summary> /// 写入变量值 /// </summary> /// <param name="value">写入值</param> /// <returns>写入结果</returns> public OpResult WriteValue(object value) { return(PLC.ForceWrite(this, value)); }
public void CmdTest() { IPEndPoint ip = null; // TODO: Initialize to an appropriate value string password = string.Empty; // TODO: Initialize to an appropriate value PLC target = new PLC(ip, password); // TODO: Initialize to an appropriate value byte[] buf = null; // TODO: Initialize to an appropriate value Response expected = null; // TODO: Initialize to an appropriate value Response actual; actual = target.Cmd(buf); Assert.AreEqual(expected, actual); Assert.Inconclusive("Verify the correctness of this test method."); }
/// <summary> /// 读取变量值 /// </summary> /// <returns>读取结果</returns> public OpResult ReadValue() { return(PLC.ForceRead(this)); }
public UInt16ArrayAccessor(PLC plc, int offset) : base(plc, offset, 2) { }
private void Start() { PLC = GameObject.Find("ProgrammingArea").GetComponent <PLC>(); }
protected void Page_Load(object sender, EventArgs e) { if (SessionState.User.IsReadOnly) { uwToolbar.Items.FromKeyButton("Save").Enabled = wdcAnnouncementDate.Enabled = wdcBlindDate.Enabled = wdcPID.Enabled = wdcObsoleteDate.Enabled = wdcRemovalDate.Enabled = cbAnnL.Enabled = cbBlindL.Enabled = cbObsoL.Enabled = cbPIDL.Enabled = cbRemovL.Enabled = cboxPID.Enabled = cboxRemovalDate.Enabled = cboxBlindDate.Enabled = cboxAnnouncementDate.Enabled = cboxObsoleteDate.Enabled = false; } Culture c = null; try { using (Item item = QDEUtils.GetItemIdFromRequest()) { if (!SessionState.User.HasItemInScope(item.Id)) { UITools.HideToolBarButton(uwToolbar, "Save"); UITools.HideToolBarSeparator(uwToolbar, "SaveSep"); } else { UITools.ShowToolBarButton(uwToolbar, "Save"); UITools.ShowToolBarSeparator(uwToolbar, "SaveSep"); } itemId = item.Id; curSku = item.Sku; curItemType = item.TypeId; int PLCUserId = PLC.PLCUser(itemId); if (Request["co"] != null) { // Country code is passed directly using (CultureList cul = HyperCatalog.Business.Culture.GetAll("CountryCode = '" + Request["co"].ToString() + "'")) { if (cul.Count > 0) { c = cul[0]; } else { UITools.FrameAlertAndBack("Invalid Country Code [" + Request["co"].ToString() + "'"); } } } else { c = QDEUtils.UpdateCultureCodeFromRequest(); } curLanguageCode = c.LanguageCode; curCountryCode = c.CountryCode; if (Request["dg"] != null) { Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "InitVarNames", "<script>dg = '" + Request["dg"].ToString() + "';" + Environment.NewLine + "col = " + Request["col"].ToString() + ";" + Environment.NewLine + "row = " + Request["row"].ToString() + ";</script>"); } Page.ClientScript.RegisterClientScriptBlock(Page.GetType(), "InitVarNames2", "<script>var cbPIDL = '" + cbPIDL.ClientID + "';" + Environment.NewLine + "var cbObsoL = '" + cbObsoL.ClientID + "';" + Environment.NewLine + "var cbBlindL = '" + cbBlindL.ClientID + "';" + Environment.NewLine + "var cbAnnL = '" + cbAnnL.ClientID + "';" + Environment.NewLine + "var cbRemovL = '" + cbRemovL.ClientID + "';" + Environment.NewLine + "var cboxPID = '" + cboxPID.ClientID + "';" + Environment.NewLine + "var cboxObsoleteDate = '" + cboxObsoleteDate.ClientID + "';" + Environment.NewLine + "var cboxBlindDate = '" + cboxBlindDate.ClientID + "';" + Environment.NewLine + "var cboxAnnouncementDate = '" + cboxAnnouncementDate.ClientID + "';" + Environment.NewLine + "var cboxRemovalDate = '" + cboxRemovalDate.ClientID + "';" + Environment.NewLine + "var wdcObsoleteDate = '" + wdcObsoleteDate.ClientID + "';" + Environment.NewLine + "var wdcPID = '" + wdcPID.ClientID + "';" + Environment.NewLine + "var wdcRemovalDate = '" + wdcRemovalDate.ClientID + "';" + Environment.NewLine + "var wdcBlindDate = '" + wdcBlindDate.ClientID + "';" + Environment.NewLine + "var wdcAnnouncementDate = '" + wdcAnnouncementDate.ClientID + "';" + Environment.NewLine + "</script>"); if (c.CountryCode != string.Empty) { uwToolbarTitle.Items.FromKeyLabel("Culture").Image = "/hc_v4/img/flags/" + curCountryCode + ".gif"; } uwToolbarTitle.Items.FromKeyLabel("Culture").Text = c.Country.Name + " "; uwToolbarTitle.Items.FromKeyLabel("Sku").Text = "[" + item.Sku + "]"; if (!Page.IsPostBack) { RetrievePLC(); lError.Visible = false; } //Modified for CR 4516/4537 - Prabhu //if (!c.Country.CanLocalizePLC || item.IsMinimizedByCulture(SessionState.Culture.Code) || item.IsRoll || PLCUserId < 1) if (!c.Country.CanLocalizePLC || item.IsRoll || PLCUserId < 1) { UITools.HideToolBarButton(uwToolbar, "Save"); UITools.HideToolBarSeparator(uwToolbar, "SaveSep"); wdcAnnouncementDate.Enabled = wdcBlindDate.Enabled = wdcPID.Enabled = wdcObsoleteDate.Enabled = wdcRemovalDate.Enabled = cbAnnL.Enabled = cbBlindL.Enabled = cbObsoL.Enabled = cbPIDL.Enabled = cbRemovL.Enabled = cboxPID.Enabled = cboxRemovalDate.Enabled = cboxBlindDate.Enabled = cboxAnnouncementDate.Enabled = cboxObsoleteDate.Enabled = false; if (!c.Country.CanLocalizePLC) { lError.Text = "This country cannot localize PLC"; } else if (item.IsRoll) { lError.Text = "This product is roll"; } //else if (item.IsMinimizedByCulture(SessionState.Culture.Code)) //{ // lError.Text = "This product is minimized"; //} //QC 1639: CRYS: PLC section becomes editable after the PLC is updated through UI (using reports from Localize menu) // Fixed by Prabhu - 02 Mar 08 // Comment: Added PLCUserId check to filter PMG sourced products being edited in UI else if (PLCUserId < 1) { lError.Text = "The PLC for this product is sourced from PMG. User cannot edit it."; } lError.CssClass = "hc_error"; lError.Visible = true; } System.Globalization.CultureInfo ci = System.Globalization.CultureInfo.CreateSpecificCulture("en-US"); ci.DateTimeFormat.ShortDatePattern = SessionState.User.FormatDate; ci.DateTimeFormat.LongDatePattern = SessionState.User.FormatDate; wdcAnnouncementDate.CalendarLayout.Culture = ci; wdcBlindDate.CalendarLayout.Culture = ci; wdcPID.CalendarLayout.Culture = ci; wdcObsoleteDate.CalendarLayout.Culture = ci; wdcRemovalDate.CalendarLayout.Culture = ci; } } catch (Exception fe) { UITools.FrameAlertAndBack(fe.ToString().Replace(Environment.NewLine, ".")); } finally { if (c != null) { c.Dispose(); } } }
public ActionResult Connect(int id) { PLC plc = db.PLC.Find(id); return(View(plc)); }
private void btnConnection_Click(object sender, EventArgs e) { try { if (string.IsNullOrEmpty(txtIPaddress.Text)) { throw new Exception("Xin vui lòng nhập địa chỉ IP"); } int selectionIndex = cboxPLCs.SelectedIndex; CPU_Type cpuType = CPU_Type.S7200; string ipAddress = txtIPaddress.Text; switch (selectionIndex) { case 0: cpuType = CPU_Type.S7200; break; case 1: cpuType = CPU_Type.S7300; break; case 2: cpuType = CPU_Type.S7400; break; case 3: cpuType = CPU_Type.S71200; break; default: cboxPLCs.SelectedIndex = 3; cpuType = CPU_Type.S71200; break; } plc = new PLC(cpuType, ipAddress, (short)numericUpDownRack.Value, (short)numericUpDownSlot.Value); if (!plc.IsAvailable) { throw new Exception("Không tìm thấy PLC cần kết nối!"); } errCode = plc.Open(); if (errCode != ExceptionCode.ExceptionNo) { throw new Exception(plc.lastErrorString); } this.SetEnabledBotton(false); //BackgroundWorker START worker = new BackgroundWorker(); worker.WorkerSupportsCancellation = true; worker.DoWork += new DoWorkEventHandler(worker_DoWork); //worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bw_RunWorkerCompleted); //worker.DoWork += (obj, ea) => worker_DoWork(); worker.RunWorkerAsync(); } catch (Exception ex) { MessageBox.Show(this, ex.Message, "Notification", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void button6_Click(object sender, EventArgs e) { if (treeView1.SelectedNode != null && treeView1.SelectedNode.Level == 2) { string orderNumber = treeView1.SelectedNode.Text; string shortDesignation = treeView1.SelectedNode.Parent.Text; string filePath = @"Devices\" + shortDesignation + @" (" + orderNumber + @").xml"; try { plc = new PLC(filePath); int x = (devicesPanel.Size.Width / 2) - (PLC.Info.picture.Width / 2); int y = (devicesPanel.Size.Height / 2) - (PLC.Info.picture.Height / 2); pictureBox4.Size = new System.Drawing.Size(PLC.Info.picture.Width, PLC.Info.picture.Height); pictureBox4.Location = new Point(x, y); Bitmap bmp = new Bitmap(PLC.Info.picture.FilePath); this.pictureBox4.Image = (System.Drawing.Image)bmp; labelShortDesignation.Text = PLC.Info.device.modules[0].ShortDesignation; labelOrderNumber.Text = PLC.Info.device.modules[0].OrderNumber; labelFirmwareVersion.Text = PLC.Info.device.modules[0].Version; foreach (var led in PLC.InputModule) { this.pictureBox4.Controls.Add(led.Value); } foreach (var led in PLC.OutputModule) { this.pictureBox4.Controls.Add(led.Value); } foreach (var led in PLC.CpuModule) { this.pictureBox4.Controls.Add(led.Value); } actualPanel = devicesPanel; devicePanelChooseModule.Visible = false; devicesPanel.Visible = true; setDevices = true; if (PLC.Info.device.FamilyName == "SIMATIC S7-300") { CommunicationModule.Server.DataReceived += S7_300_Engine.Engine.client_DataReceived; S7_300_Engine.Engine.SetPLCInfo(PLC.Info.device.modules[0].ShortDesignation, PLC.Info.device.modules[0].OrderNumber); } ThreadPool.QueueUserWorkItem(delegate { PLC.Run(); } ); } catch (FileNotFoundException fsince) { MessageBox.Show(fsince.Message); } catch (Devices.FileStructIsNotCorectException fsince) { MessageBox.Show(fsince.Message); } } else { MessageBox.Show("Wybierz konkretny model"); } }