* DriverBoitierV2.cs: Amelioration gestion d'erreurs

* SequenceurMacro.cs: Repetition : insensible a la casse

* DriverBoitierV1.cs: Reactivation
This commit is contained in:
manu 2013-12-24 17:09:16 +00:00
parent f7416f39c9
commit 07ee1ef506
3 changed files with 30 additions and 21 deletions

View file

@ -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;

View file

@ -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 ;
}

View file

@ -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)