diff --git a/DMX-2.0/DriverBoitierV1.cs b/DMX-2.0/DriverBoitierV1.cs index 5a48b4c..a30931e 100644 --- a/DMX-2.0/DriverBoitierV1.cs +++ b/DMX-2.0/DriverBoitierV1.cs @@ -43,8 +43,8 @@ namespace DMX2 public DriverBoitierV1 (string serialport, string id): base(id) { portname = serialport; - //patch = Conduite.Courante.Patches[0]; - //Start(); + patch = Conduite.Courante.Patches[0]; + Start(); //serial = serialport; outputbuffer[0]=27; outputbuffer[1]=68; diff --git a/DMX-2.0/DriverBoitierV2.cs b/DMX-2.0/DriverBoitierV2.cs index a9faf20..13c3804 100644 --- a/DMX-2.0/DriverBoitierV2.cs +++ b/DMX-2.0/DriverBoitierV2.cs @@ -113,11 +113,16 @@ namespace DMX2 if (serial != null) { serial.Close (); serial.Dispose (); + serial = null; + } + if (!System.IO.File.Exists (portname)) { + Thread.Sleep (200); + return; } serial = new SerialPort (portname, 460800, Parity.None, 8, StopBits.One); //serial.DtrEnable = false; - serial.ReadTimeout = 200; - serial.WriteTimeout = 200; + //serial.ReadTimeout = 200; + //serial.WriteTimeout = 200; try { serial.Open (); Attente(DateTime.Now.AddMilliseconds(1000)); @@ -129,8 +134,10 @@ namespace DMX2 etat = etatAutomate.Deconnecte; } - } catch { + } catch (Exception ex) { etat = etatAutomate.Deconnecte; + Console.WriteLine("DriverV2:Connection : {0}",ex); + Thread.Sleep (500); } } @@ -141,7 +148,7 @@ namespace DMX2 bool Synchronisation () { //return true; - + Console.WriteLine ("DriverV2.Synchronisation()"); if (serial == null) return false; @@ -183,6 +190,7 @@ namespace DMX2 void MainLoop () { + DateTime t = DateTime.Now; while (etat != etatAutomate.Fin) { try { switch (etat) { @@ -192,6 +200,8 @@ namespace DMX2 break; case etatAutomate.Transmission: finAttente = DateTime.Now.AddMilliseconds (22); + Console.WriteLine(DateTime.Now-t); + t = DateTime.Now; EnvoiTrame (); Reception (); Attente (finAttente); @@ -201,17 +211,10 @@ namespace DMX2 EnvoieReInit(); break; case etatAutomate.Erreur: + Console.WriteLine("DriverV2 : etatAutomate.Erreur"); compteErreur ++; - if (compteErreur > 3) { - Deconnecte (); - Attente (DateTime.Now.AddSeconds (2)); - } else { - Attente (DateTime.Now.AddMilliseconds (250)); - if (Synchronisation ()) - etat = etatAutomate.Transmission; - else - compteErreur++; - } + Deconnecte (); + Attente (DateTime.Now.AddSeconds (2)); break; // case etatAutomate.Parametrage: // EnvoiParam(); @@ -250,12 +253,16 @@ namespace DMX2 void EnvoiTrame () { try { - if(!serial.IsOpen) { - etat = etatAutomate.Erreur; - } if(patch1!=null) patch1.CalculUnivers(outputbuffer,2,512); if(patch2!=null) patch2.CalculUnivers(outputbuffer,514,512); + if(!serial.IsOpen) { + etat = etatAutomate.Erreur; + return; + } + while (serial.BytesToWrite > 0) + Thread.Sleep(1); + serial.Write(outputbuffer,0,outputbuffer.Length); } catch (Exception ex) { Console.WriteLine("Exception Envoi {0}",ex); @@ -269,7 +276,8 @@ namespace DMX2 while (serial.BytesToRead < len) { Thread.Sleep (1); - if (++wcnt > timeout) return false; + if (++wcnt > timeout) + return false; } return true; } @@ -295,6 +303,7 @@ namespace DMX2 if(!WaitForData (inputbuffer.Length)) { etat = etatAutomate.Erreur; + Console.WriteLine("DriverV2.Reception : attente depassee"); return ; } diff --git a/DMX-2.0/SequenceurMacro.cs b/DMX-2.0/SequenceurMacro.cs index ee2fe31..4054cec 100644 --- a/DMX-2.0/SequenceurMacro.cs +++ b/DMX-2.0/SequenceurMacro.cs @@ -352,7 +352,7 @@ namespace DMX2 enCours = lignes[index]; // Gestion de la Reprise - if(enCours.Circuits.Equals("R") && ligneMaitre != null) + if(enCours.Circuits.ToLower().Equals("r") && ligneMaitre != null) enCours = ligneMaitre; if(enCours.Nom.Length!=0)