Example #1
0
    /*
     *  protected virtual void OnThresholdReached(EventArgs e)
     *  {
     *          EventHandler handler = ThresholdReached;
     *          if (handler != null)
     *          {
     *                  handler(this, e);
     *          }
     *  }
     */
    private void ReadSerial()
    {
        //EventHandler handler = ThresholdReached;
        do
        {
            try
            {
                String   comandoricevuto = com.ReadLine().Trim();
                String[] sottocomandi    = comandoricevuto.Split(' ');
                switch (sottocomandi.Length)
                {
                case 1:
                    stato = sottocomandi[0];
                    switch (sottocomandi[0])
                    {
                    case "s0":
                        votoincorso = false;
                        if (EventoStatoZero != null)
                        {
                            EventoStatoZero(this, new EventArgs());
                        }
                        break;

                    case "ds":         // discovery
                        if (EventoInizioDiscovery != null)
                        {
                            EventoInizioDiscovery(this, new EventArgs());
                        }
                        break;

                    case "is":         // invia sync
                        if (EventoInviaSync != null)
                        {
                            EventoInviaSync(this, new EventArgs());
                        }
                        break;

                    case "ip":         // inizio poll
                        votoincorso = true;
                        if (EventoInizioPoll != null)
                        {
                            EventoInizioPoll(this, new EventArgs());
                        }
                        break;

                    default:
                        cmderr(comandoricevuto);
                        break;
                    }
                    break;

                case 2:
                    switch (sottocomandi[0])
                    {
                    case "e":         // messaggio dal master
                        MsgEventArgs mea = new MsgEventArgs();
                        mea.msg = sottocomandi[1];
                        if (EventoNuovoMessaggio != null)
                        {
                            EventoNuovoMessaggio(this, mea);
                        }
                        break;

                    case "ns":         // max numero slave
                        NumSlaveEventArgs nse = new NumSlaveEventArgs();
                        nse.numslave = int.Parse(sottocomandi[1]);
                        if (EventoRxNumMaxSlave != null)
                        {
                            EventoRxNumMaxSlave(this, nse);
                        }
                        break;

                    case "dx":         // max numero slave
                        DiscFailEventArgs dfe = new DiscFailEventArgs();
                        dfe.indirizzo = int.Parse(sottocomandi[1]);
                        if (EventoDiscFail != null)
                        {
                            EventoDiscFail(this, dfe);
                        }
                        break;

                    default:
                        cmderr(comandoricevuto);
                        break;
                    }
                    break;

                case 3:
                    switch (sottocomandi[0])
                    {
                    case "v":         // nuovo voto acquisito
                        VotoEventArgs vea = new VotoEventArgs();
                        vea.indirizzo = int.Parse(sottocomandi[1]);
                        vea.oravoto   = uint.Parse(sottocomandi[2]);
                        if (EventoVotoAcquisito != null)
                        {
                            EventoVotoAcquisito(this, vea);
                        }
                        break;

                    default:
                        cmderr(comandoricevuto);
                        break;
                    }
                    break;

                case 5:
                    switch (sottocomandi[0])
                    {
                    case "d":         // trovato nuovo client
                        DiscoveryEventArgs dea = new DiscoveryEventArgs();
                        dea.indirizzo  = int.Parse(sottocomandi[1]);
                        dea.batteria   = ((float)3.0 * float.Parse(sottocomandi[2])) / 255;
                        dea.rssislave  = int.Parse(sottocomandi[3]);
                        dea.rssimaster = int.Parse(sottocomandi[4]);
                        if (EventoNuovoClient != null)
                        {
                            EventoNuovoClient(this, dea);
                        }
                        break;

                    default:
                        cmderr(comandoricevuto);
                        break;
                    }
                    break;

                default:
                    cmderr(comandoricevuto);
                    break;
                }
            }
            catch (TimeoutException te)
            {
            }
            catch (InvalidOperationException ee)
            {
                cmderr(ee.Message);
                //return;
            }
            catch (System.IO.IOException ioe)
            {
                return;
            }
        } while (mustexit == false);
    }
Example #2
0
 void RxNumSlave(object sender, NumSlaveEventArgs e)
 {
     SetText(e.numslave.ToString(), TBNumMaxSlave);
 }