コード例 #1
0
ファイル: NauCom.cs プロジェクト: christianduerselen/BaSta
    private void DataAccepted(NauBee Sender)
    {
        lock (this.NB)
        {
            foreach (NauBee nauBee in this.NB)
            {
                if (nauBee != Sender)
                {
                    nauBee.Dispose();
                }
                nauBee.ClearDataRecievedEvents();
            }
            this.NB.Clear();
            this.NB.Add(Sender);
        }
        this.DetectedPort = Sender.ListeningPort.PortName;
        Action portScanCompleted = this.PortScanCompleted;

        if (portScanCompleted == null)
        {
            return;
        }
        portScanCompleted();
    }
コード例 #2
0
ファイル: NauCom.cs プロジェクト: christianduerselen/BaSta
 public NauCom(
     Protocols p,
     string SerialPort = "ANY",
     NauBeeChannels nWirelessChannel = NauBeeChannels.CHANNEL_0,
     bool bPassiveListenerMode       = false,
     int SelectedGroup  = 15,
     int teamDispLength = 24)
 {
     this.Protocol            = p;
     this.PassiveListenerMode = bPassiveListenerMode;
     this._teamDispLength     = teamDispLength;
     this.Board = new cBoard(this);
     this.Com   = new Communication(this.Board);
     if (this.Protocol == Protocols.NG12)
     {
         this.PacketBuilder = (iPacketBuilder) new PacketBuilderNG12(this, this.Board);
     }
     else
     {
         if (this.Protocol == Protocols.NG08Direct && !SttyExecution.IsPlatformCompatible())
         {
             throw new PlatformNotSupportedException("This serial implementation only works on platforms with stty");
         }
         this.PacketBuilder = (iPacketBuilder) new PacketBuilderNG08(this, this.Board);
         if (SelectedGroup > 15)
         {
             throw new Exception("illegal group for NG08");
         }
     }
     this.Group           = SelectedGroup;
     this.WirelessChannel = nWirelessChannel;
     this.Com.CommunicationUpdateChannel(this);
     this.Com.CommunicationSetDBM(this);
     this.PacketBuilder.ClearFlags();
     this.NB = new List <NauBee>();
     if (SerialPort.ToUpper() != "ANY" && SerialPort.ToUpper() != "ALL")
     {
         this.NB.Add(new NauBee(SerialPort, this.Protocol));
     }
     else
     {
         foreach (string portName in System.IO.Ports.SerialPort.GetPortNames())
         {
             try
             {
                 this.NB.Add(new NauBee(portName, this.Protocol));
             }
             catch (Exception ex)
             {
             }
         }
     }
     if (this.Protocol == Protocols.NG08Direct)
     {
         foreach (NauBee nauBee in this.NB)
         {
             SttyExecution.CallStty("-F " + nauBee.ListeningPort.PortName + " inpck parmrk -parenb cmspar parodd");
         }
     }
     if (this.NB.Count == 0)
     {
         throw new Exception("No Given Com Ports Could be opened");
     }
     foreach (NauBee nauBee in this.NB)
     {
         NauBee N = nauBee;
         N.NauBeeEvent += PacketBuilder.NauBeeEvent;
         if (PassiveListenerMode)
         {
             N.DataRecieved += () => DataAccepted(N);
         }
     }
     TaskTimerStart().GetAwaiter().GetResult();
 }