コード例 #1
0
        public uMCPNMEAPort(SerialPortSettings portSettings)
        {
            #region Parsers

            parsers = new Dictionary <string, parserDelegate>()
            {
                { "0", new parserDelegate(LACK_Parse) },
                { "2", new parserDelegate(RACK_Parse) },
                { "3", new parserDelegate(RPKT_Parse) },
                { "5", new parserDelegate(STAT_Parse) }
            };

            #endregion

            #region port

            port = new NMEASerialPort(portSettings);

            port.PortError      += (o, e) => { PortErrorEventHandler.Rise(this, e); };
            port.NewNMEAMessage += new EventHandler <NewNMEAMessageEventArgs>(port_MessageReceived);

            #endregion

            #region nmea

            if (!nmeaSingleton)
            {
                NMEAParser.AddManufacturerToProprietarySentencesBase(ManufacturerCodes.MCP);
                NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.MCP, "0", "c--c,x");
                NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.MCP, "1", "x,x,x,x,x");
                NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.MCP, "2", "h--h");
                NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.MCP, "3", "h--h");
                NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.MCP, "4", "h--h");
                NMEAParser.AddProprietarySentenceDescription(ManufacturerCodes.MCP, "5", "x,x");

                //#define IC_D2H_LACK             '0'        // $PMCP0,sentenceID,errCode  - local command ACK
                //#define IC_H2D_STRT             '1'        // $PMCP1,senderID,targetID,selectDefState,selIntMs,toutIntMs - restart protocol with specified params
                //#define IC_D2H_RACK             '2'        // $PMCP2,h--h // sent packet acknowledged
                //#define IC_D2H_RPKT             '3'        // $PMCP3,h--h // packet received
                //#define IC_H2D_SPKT             '4'        // $PMCP4,h--h // send packet
                //#define IC_D2H_STAT             '5'        // $PMCP5,state,select // protocol state changed
            }

            #endregion

            #region timer

            timer        = new PrecisionTimer();
            timer.Period = 1000;
            timer.Mode   = Mode.OneShot;
            timer.Tick  += (o, e) => { PortTimeoutEventHandler.Rise(this, new EventArgs()); IsWaiting = false; };

            #endregion

            #region other

            dataToSend = new TSQueue <byte[]>(128, 128);
            dataToSend.ItemEnqueued += (o, e) => { if (!isWaiting)
                                                   {
                                                       OnPortFree();
                                                   }
            };

            #endregion
        }