Ciao a tutti,
ho un problema di questo tipo:
sto facendo un'applicazione che gestisce l'invio e la ricezione di dati su rs232, ogni ricezione andata a buon fine o no scatena rispettivamente un evente di RxOK o RxErr...il problema è che in fase di debug ho inserito un contatore che traccia gli eventi che vengono chiamati e i contatori si incrementano con un fattore 3...
Ogni volta che si scatena l'evento mi rimane nel metodo (RxOK o RxErr) per 3 volte senza tornare mai al codice che chiama il delegato.....posto il codie...magari si capisce di più...:


CLASSE SERIALE:

// Delegate declaration

public delegate void typeReceiveEndOk(object sender, System.EventArgs endOk);

public delegate void typeReceiveEndError(object sender, System.EventArgs endErr);



// Event Declaration.

public event typeReceiveEndOk receiveEndOk;

public event typeReceiveEndError receiveEndError;



System.EventArgs endErr = new System.EventArgs();

System.EventArgs endOk = new System.EventArgs();



// Verifica dei dati ricevuti.

switch (checkDataReceived())

{

case stateCheckDataReceived.OK:

enableComRx = false;

timeTx.Enabled = false;

// Funzione terminata, devo generare un evento che e' tutto OK.

// System.EventArgs endOk = new System.EventArgs();

receiveEndOk(this, endOk);

break;



case stateCheckDataReceived.ERR:

enableComRx = false;

timeTx.Enabled = false;

// Genero un evento di fine comunicazione con errore.

receiveEndError(this, endErr);







//************************************************** **
// setto gli eventi di errore e di OK
//************************************************** **
Serial485.receiveEndError += new Serial485_Pse.typeReceiveEndError(RxErr);

Serial485.receiveEndOk += new Serial485_Pse.typeReceiveEndOk(RxOk);

----------------------------------------------------------------------------------
CLASSE UTILIZZATRICE:

/************************************************** ******
* Evento Ricezione andata a buon fine
************************************************** ******
*/



private void RxOk(object sender, EventArgs e)

{



Int16 tara = 0;

Int16 ricOK = 0;

Int16 statoProd = 0;



string stringaVersione = "";



//Debug.

debCntPckt++;

// classe che trasforma i buffer ricevuti in stringhe in

// modo che sia piu' semplice testare i comandi.

strg_cmd = class_BuildData.cmdFromByte(Serial485.cmdRx);

strg_subCmd = class_BuildData.cmdFromByte(Serial485.subCmdRx);




nrFormulaTB.Text = Convert.ToString(debCntPckt);



switch (strg_cmd)

{

case "WTD":



tara = class_BuildData.intFromBfByte(Serial485.bfDataRx, 3);

ricOK = class_BuildData.intFromBfByte(Serial485.bfDataRx, 2);

statoProd = class_BuildData.intFromBfByte(Serial485.bfDataRx, 1);



if ((ricOK == 1) && (statoProd == 99))

dosaggiTB.Text = "Fine dosaggio!!!!";


break;

case "FOR":



switch (strg_subCmd)

{

case "SAB":

stateSubCmdFormula = subCmdFormula.LEG;

break;

case "LEG":

stateSubCmdFormula = subCmdFormula.TM1;

break;

case "TM1":

stateSubCmdFormula = subCmdFormula.H2O;

break;

case "TM2":

stateSubCmdFormula = subCmdFormula.TAR;

break;

case "H2O":

stateSubCmdFormula = subCmdFormula.TM2;

break;

case "TAR":

frameToTx = listFrameToTx.STR;

break;

}



break;



case "STR":

frameToTx = listFrameToTx.WTD;

break;



case "ERR":

break;



case "VER":

stringaVersione = class_BuildData.stringFromBfByte(Serial485.bfDataR x, 1);

frameToTx = listFrameToTx.WTD;

break;



case "END":

if (Convert.ToInt16(dosaggiTB.Text) > contaDosaggi)

{

frameToTx = listFrameToTx.FOR;

contaDosaggi++;

}

else if (Convert.ToInt16(dosaggiTB.Text) == contaDosaggi)

{

// @@@@@@@@@@@@@@@

panelFineCicli.Visible = true;

eseguiB.Enabled = false;

acquaMenoB.Enabled = false;

acquaPiuB.Enabled = false;

dosaggiMenoB.Enabled = false;

dosaggiPiuB.Enabled = false;

indietroB.Enabled = false;

// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

// visualizza pulsanti con selezione 1/2 1/4 e FINE....

// disabilita le text box

// controllo tipo di selezione

}

break;

}

fSerialeFree = true;

}



/*
* ************************************
* Evento Ricezione CON Errore
* **************************************
*/



private void RxErr(object sender, EventArgs e)

{

debTaraRx++;

dosaggiTB.Text = Convert.ToString(debTaraRx);

fSerialeFree = true;

}

Volevo sapere se è un problema degli eventi in se o se ho sbagliato qualcosa...Grazie!