Meilleure fermeture du driver en cas d'erreur persistante

ajout de gestion des temps brk&mab sur arduinov3
This commit is contained in:
tzim 2014-05-05 14:06:43 +00:00
parent d93631e6d6
commit 8367b66485
6 changed files with 19 additions and 30 deletions

View file

@ -103,7 +103,7 @@ namespace DMX2
void MainLoop()
{
while(etat != etatAutomate.Fin)
while(!disposed && etat != etatAutomate.Fin)
{
switch (etat) {
case etatAutomate.Deconnecte:

View file

@ -209,7 +209,7 @@ namespace DMX2
void MainLoop ()
{
//DateTime t = DateTime.Now;
while (etat != etatAutomate.Fin) {
while (!disposed && etat != etatAutomate.Fin) {
try {
switch (etat) {
case etatAutomate.Deconnecte:

View file

@ -42,7 +42,7 @@ namespace DMX2
Fin
}
const int timeout = 200;
const int timeout = 100;
// tampons Entrée/Sortie
public byte[] inputbuffer = new byte[516];
@ -130,15 +130,12 @@ namespace DMX2
Thread.Sleep (1500);
return;
}
serial = new SerialPort (portname);//, 9600, Parity.None, 8, StopBits.One);
serial = new SerialPort (portname);
Console.WriteLine (portname);
//serial.DtrEnable = false;
//serial.ReadTimeout = 200;
//serial.WriteTimeout = 200;
try {
serial.RtsEnable = true;
serial.Open ();
//Attente(DateTime.Now.AddMilliseconds(100));
if(Synchronisation())
etat = etatAutomate.Transmission;
@ -169,11 +166,11 @@ namespace DMX2
return false;
// Au cas ou le boitier attends une fin de commande : envoi 1030 octets a 0 (le boitier ignorera tout seul la suite)
byte[] tmpBuffer = new byte[530];
//serial.Write (tmpBuffer, 0, 530);
byte[] tmpBuffer = new byte[2];
serial.Write (tmpBuffer, 0, tmpBuffer.Length);
// On attends un peu
Thread.Sleep (100);
Thread.Sleep (50);
// Vide le buffer d'entree
if (serial.BytesToRead > 0)
@ -204,7 +201,7 @@ namespace DMX2
void MainLoop ()
{
//DateTime t = DateTime.Now;
while (etat != etatAutomate.Fin) {
while (!disposed && etat != etatAutomate.Fin) {
try {
switch (etat) {
case etatAutomate.Deconnecte:

View file

@ -52,6 +52,8 @@ namespace DMX2
return DriverBoitierV1.Load(conduite, el);
case "DriverBoitierV2":
return DriverBoitierV2.Load(conduite,el);
case "DriverBoitierV3":
return DriverBoitierV3.Load(conduite,el);
}
return null;
}

View file

@ -18,10 +18,10 @@ volatile int index_input_pc=0; // entrée serial 0
volatile int index_output_pc=0; // sortie serial 0
volatile int index_input_dmx=513; // entrée dmx
volatile int index_output_dmx=0; //sortie dmx -2 en attente de fin de transmission; -1 break; 0 à 512 transmission
volatile int index_output_dmx2=0; //sortie dmx -2 en attente de fin de transmission; -1 break; 0 à 512 transmission
volatile int etat_input_pc=0; // 0 raz ; 1 esc reçu ; 2 D reçu : pret à recevoir ; 3 prèt à emmetre
volatile int start_code_rec=-1;
char key; // caractère reçu serial 0
int ledPin = 13; // led interne
int tx1pin = 1; // pin DMX serial 1
@ -33,6 +33,7 @@ volatile int emissionPc=0;
/* ------------ Gestion Liaison USB -------------- */
/* On a surcharge tout ca pour optimiser les temps de transfert */
typedef struct
{
@ -89,7 +90,7 @@ bool CDC_Setup(Setup& setup)
return false;
}
// lancé par interruption USB sur reception d'un char
// lancé par interruption USB sur reception d'un char <- Cette fonction nécessite une modif de la lib arduino
void CDC_accept()
{
int c = USB_Recv(CDC_RX);
@ -175,12 +176,12 @@ void litUSB(char c)
case 11: // 2nd parametre : duree du break en us
etat_input_pc++;
//brk_timer_end = 255 - (c/2) +1;
brk_timer_end = (c/2);
break;
case 12: // 3eme parametre : duree du mab en us
etat_input_pc++;
//mab_timer_end = 255 - (c/2) +1;
mab_timer_end = (c/2);
break;
case 13: // 4eme parametre : merge
@ -259,7 +260,6 @@ ISR(TIMER4_COMPA_vect) {
digitalWrite(tx1pin, HIGH); // on met la broche 18 à 1 pendant 10 µs
index_output_dmx=-3;
index_output_dmx2=-3;
OCR4A = mab_timer_end ;
TCNT4 = 0 ;// RAZ compteur timer
TIFR4 = 0 ; //Clear Flags timer
@ -283,7 +283,6 @@ void setup() {
// init pin led interne en sortie
pinMode(ledPin, OUTPUT);
// initialisation à 250k de serial 1
// baudrate
@ -302,15 +301,11 @@ void setup() {
sbi(UCSR1B, RXCIE1); //Interruption sur reception
sbi(UCSR1B, TXCIE1); //Interruption pour fin de transmission
// init timer break
TIMSK4 = 0;
TCCR4C = 0;
TCCR4B = 0;
TCCR4A = 0; // 00000000
// ASSR &= ~(1<<AS2); <--------------------
TCNT4 = 0; // compteur
TC4H=0;
@ -318,11 +313,6 @@ void setup() {
// préparation du premier break
index_output_dmx=-1;
// PORTA = 255;
// DDRA = 0;
// PORTC = 255;
// DDRC = 0;
tab_input_dmx[533]=0;
}
@ -341,13 +331,13 @@ void loop() {
TCCR4B = 6; // 00000011 division par 32 de l'horloge base => 2µs
} // fin du break
// suite du code
// octets d'état. Pour le moment, tous à 0
tab_input_dmx[513]= 0;
tab_input_dmx[514]= 0;
tab_input_dmx[515]=0;
tab_input_dmx[516]=0;
if(_usbLineInfo.lineState) { // Si port ouvert
if(_usbLineInfo.lineState) { // Si port serie USB ouvert
if(emissionPc!=0) {
ecritUSB();
}