using System; using System.Collections.Generic; using System.Xml.Serialization; using static IOB_UT_NEXT.CustomObj; namespace IOB_WIN_NEXT { /* -------------------------------------------------------------------------------- * Controlli ModBusTCP FIMAT * - protocollo ModBus TCP * - gestione stato via Modbus * - resto gestioen via file * * G:\Drive condivisi\30_Clienti\Tenditalia\Macchina Fimat * * -------------------------------------------------------------------------------- */ public class IobModbusTCPFimat : IobModbusTCP { #region Public Constructors /// /// Classe base con i metodi x ModBusTCP /// /// /// public IobModbusTCPFimat(AdapterForm caller, IobConfiguration IOBConf) : base(caller, IOBConf) { lgInfo("NEW IOB ModBus TCP FIMAT"); // provo lettura una prima volta i dati DYN if (currPLC != null && currPLC.Connected) { try { processDynData(); if (EnableTest) { processDataSync(); testReadExt(); } } catch (Exception exc) { lgError($"Eccezione in processDynData iniziale x ModBus TCP FIMAT:{Environment.NewLine}{exc}"); } } } /// /// Elenco dei path validi x processing, tra cui /// - archivio template ricette /// - archivio PODL ricette inviate /// - path remota invio PODL /// - path remota lettura tasl ([P]ODL) svolti /// - archivio task ([P]ODL) recuperati /// protected List pathlist { get; set; } = new List(); /// /// Prepara la ricetta indicata partendo dai dati della ricetta template + dati ODL di riferimento /// /// Path del template della ricetta /// Record del PODL da inviare /// Path della ricetta da inviare protected string prepareRecipe(string recTemplatePath, PODLModel podlReq) { string recFilePath = ""; // leggo il file template ricetta return recFilePath; } /// /// Effettua invio XML del PODL dato il suo path verso la macchina /// /// /// protected bool sendRecipe(string odlRecipePath) { bool fatto = false; return fatto; } /// /// Verifica l'elenco dei PODL (Attivi) per la macchina e verifica se vadano inviati (controllando archivio PODL inviati /// /// /// protected bool trySendPOdl(List actPOdlList) { bool answ = false; foreach (var item in actPOdlList) { // verifico se sia nella folder di quelli inviati // se non presente preparo, leggendo conf del NUMERO ricetta (e configurandola come 10'000+num???) // infine invio } return answ; } #endregion Public Constructors #region Public Classes [XmlRoot(ElementName = "A_Recipe")] public class ARecipe { #region Public Properties [XmlElement(ElementName = "ColRecipe")] public List ColRecipe { get; set; } [XmlElement(ElementName = "DesRecipe")] public DesRecipe DesRecipe { get; set; } //[XmlAttribute(AttributeName = "noNamespaceSchemaLocation")] //public string NoNamespaceSchemaLocation { get; set; } //[XmlText] //public string Text { get; set; } //[XmlAttribute(AttributeName = "xsi")] //public string Xsi { get; set; } #endregion Public Properties } [XmlRoot(ElementName = "ColData")] public class ColData { #region Public Properties [XmlElement(ElementName = "ColourCode")] public string ColourCode { get; set; } [XmlElement(ElementName = "CompNumber")] public int CompNumber { get; set; } [XmlElement(ElementName = "Cost")] public double Cost { get; set; } [XmlElement(ElementName = "Date")] public DateTime Date { get; set; } [XmlElement(ElementName = "Description")] public string Description { get; set; } [XmlElement(ElementName = "DosDuration")] public int DosDuration { get; set; } [XmlElement(ElementName = "DosError")] public string DosError { get; set; } [XmlElement(ElementName = "DosNote")] public object DosNote { get; set; } [XmlElement(ElementName = "Origin")] public string Origin { get; set; } [XmlElement(ElementName = "PartsPerc")] public double PartsPerc { get; set; } [XmlElement(ElementName = "PartsWeight")] public double PartsWeight { get; set; } [XmlElement(ElementName = "TypComp")] public string TypComp { get; set; } [XmlElement(ElementName = "Weight-gr")] public double Weightgr { get; set; } [XmlElement(ElementName = "Weight-gr-dosed")] public double Weightgrdosed { get; set; } [XmlElement(ElementName = "Weight-gr-prev")] public double Weightgrprev { get; set; } [XmlElement(ElementName = "Weight-gr-total")] public double Weightgrtotal { get; set; } #endregion Public Properties } [XmlRoot(ElementName = "ColRecipe")] public class ColRecipe { #region Public Properties [XmlElement(ElementName = "ColData")] public ColData ColData { get; set; } #endregion Public Properties } [XmlRoot(ElementName = "DesData")] public class DesData { #region Public Properties [XmlElement(ElementName = "Article")] public string Article { get; set; } [XmlElement(ElementName = "CustDrumCode")] public object CustDrumCode { get; set; } [XmlElement(ElementName = "Customer")] public object Customer { get; set; } [XmlElement(ElementName = "Date")] public DateTime Date { get; set; } [XmlElement(ElementName = "Design")] public int Design { get; set; } [XmlElement(ElementName = "DosDuration")] public int DosDuration { get; set; } [XmlElement(ElementName = "DosedLine")] public int DosedLine { get; set; } [XmlElement(ElementName = "DosType")] public string DosType { get; set; } [XmlElement(ElementName = "DrumCode")] public double DrumCode { get; set; } [XmlElement(ElementName = "DrumInitialWeightKG")] public double DrumInitialWeightKG { get; set; } [XmlElement(ElementName = "DrumTag")] public int DrumTag { get; set; } [XmlElement(ElementName = "DrumType")] public int DrumType { get; set; } [XmlElement(ElementName = "Info1")] public object Info1 { get; set; } [XmlElement(ElementName = "Info2")] public object Info2 { get; set; } [XmlElement(ElementName = "Info3")] public object Info3 { get; set; } [XmlElement(ElementName = "Info4")] public object Info4 { get; set; } [XmlElement(ElementName = "Info5")] public object Info5 { get; set; } [XmlElement(ElementName = "Info6")] public object Info6 { get; set; } [XmlElement(ElementName = "Info7")] public object Info7 { get; set; } [XmlElement(ElementName = "Info8")] public object Info8 { get; set; } [XmlElement(ElementName = "Info9")] public object Info9 { get; set; } [XmlElement(ElementName = "LotID")] public object LotID { get; set; } [XmlElement(ElementName = "Note1")] public string Note1 { get; set; } [XmlElement(ElementName = "Note2")] public object Note2 { get; set; } [XmlElement(ElementName = "OrderCode")] public string OrderCode { get; set; } [XmlElement(ElementName = "Prio")] public string Prio { get; set; } [XmlElement(ElementName = "Quantity-kg")] public double Quantitykg { get; set; } [XmlElement(ElementName = "Quantity-kg-dosed")] public double Quantitykgdosed { get; set; } [XmlElement(ElementName = "RecipeStatus")] public string RecipeStatus { get; set; } [XmlElement(ElementName = "RecipeType")] public string RecipeType { get; set; } [XmlElement(ElementName = "RecName")] public int RecName { get; set; } [XmlElement(ElementName = "ReqType")] public string ReqType { get; set; } [XmlElement(ElementName = "Screen")] public object Screen { get; set; } [XmlElement(ElementName = "Sequence")] public int Sequence { get; set; } [XmlElement(ElementName = "SequenceTot")] public int SequenceTot { get; set; } [XmlElement(ElementName = "Series")] public int Series { get; set; } [XmlElement(ElementName = "ServiceType")] public string ServiceType { get; set; } [XmlElement(ElementName = "SplitCurrent")] public int SplitCurrent { get; set; } [XmlElement(ElementName = "SplitTotal")] public int SplitTotal { get; set; } [XmlElement(ElementName = "Taglio-D")] public double TaglioD { get; set; } [XmlElement(ElementName = "Taglio-N")] public double TaglioN { get; set; } [XmlElement(ElementName = "UM")] public int UM { get; set; } [XmlElement(ElementName = "Variant")] public object Variant { get; set; } [XmlElement(ElementName = "ViscoName")] public object ViscoName { get; set; } [XmlElement(ElementName = "ViscoValue")] public double ViscoValue { get; set; } #endregion Public Properties } // using System.Xml.Serialization; XmlSerializer serializer = new // XmlSerializer(typeof(ARecipe)); using (StringReader reader = new StringReader(xml)) { var // test = (ARecipe)serializer.Deserialize(reader); } [XmlRoot(ElementName = "DesRecipe")] public class DesRecipe { #region Public Properties [XmlElement(ElementName = "DesData")] public DesData DesData { get; set; } #endregion Public Properties } #endregion Public Classes #region Protected Properties /// /// Restituisce controllo IN ALLARME /// protected bool AlarmState { get { return testIntCondition("AlarmIntCond"); } } /// /// Restituisce status di ESTOP triggered (triggered = premuta, altrimenti armed) /// protected bool EStopTriggered { get { return testBitCondition("EStopBitCond"); } } /// /// Restituisce status di Manuale, hard coded /// protected bool ManualState { get { return testBitCondition("ManualBitCond"); } } /// /// Restituisce status di WORK (auto + lavora), hard coded /// protected bool WorkState { get { return testIntCondition("WorkIntCond"); } } #endregion Protected Properties #region Protected Methods /// /// Effettua decodifica aree memoria alla bitmap usata x MAPO /// protected override void decodeToBaseBitmap() { // init a zero... B_input = 0; /* ----------------------------------------------------- * bitmap MAPO STANDARD 60 * B0: POWER_ON * B1: RUN * B2: pzCount * B3: allarme * B4: manuale * B5: slowTC * B6: WarmUpCoolDown * B7: EmergArmata * ----------------------------------------------------- */ var MemInt = new byte[2]; int byteSignals = 0; // bit 0 (poweron) imposto a 1 SE connected... if (currPLC.Connected) { byteSignals += (1 << 0); } // se ho qualcosa nella holding register... if (HoldingRegisterLUT != null && HoldingRegisterLUT.Count > 0) { // se emergenza NON premuta (triggered) indico OK (armata...) FARE !!! togliere true if (!EStopTriggered) { byteSignals += (1 << 7); } // impiego controlli da setup IntConditions... processo dagli stati + gravi... if (AlarmState || hasAlarms()) { byteSignals += (1 << 3); } else if (ManualState) { byteSignals += (1 << 4); } else if (WorkState) { byteSignals += (1 << 1); } checkTranslateBit(); checkTranslateInt(); } else { lgInfo("HoldingRegisterLUT vuoto!"); } // salvo! B_input = byteSignals; } /// /// Effettua sync dati /// protected override void processDataSync() { // richiesta check autoODL processAutoOdl(); // richiesta generazione quotidiana dossiers processAutoDossier(); // effettua gestione import file... processFileImport(); } #endregion Protected Methods } }