コード例 #1
0
        public uMCPInoPort(string portName, BaudRate baudrate, bool selectDefaultState,
                           uint selectIntMs, uint timeoutIntMs, byte packetSize, byte maxMessages)
        {
            timer        = new PrecisionTimer();
            timer.Period = 100;
            timer.Mode   = Mode.Periodic;
            timer.Tick  += (o, e) => { node.OnTick(); };

            node = new uMCPInoNode(selectDefaultState, timeoutIntMs, selectIntMs, packetSize, maxMessages);
            node.OnSTATEChangedEventHandler          += (o, e) => { OnStateChangedEventHandler.Rise(this, e); };
            node.OnSELECTChangedEventHandler         += (o, e) => { OnSelectChangedEventHandler.Rise(this, e); };
            node.OnDataBlockAcknowledgedEventHandler += (o, e) => { OnDataBlockAcknowledgedEventHandler.Rise(this, e); };
            node.OnDataBlockReceivedEventHandler     += (o, e) => { OnDataBlockReceivedEventHandler.Rise(this, e); };
            node.OnActionInfoEventHandler            += (o, e) => { OnActionInfoEventHandler.Rise(this, e); };
            node.OnTransmitterEmptyEventHandler      += (o, e) => { OnTransmitterEmptyEventHandler.Rise(this, e); };
            node.OnOutcomingEventHandler             += new EventHandler <uMCPInoDataEventArgs>(node_OnOutcomingEventHandler);

            port = new SerialPort(portName, (int)baudrate);
            port.DataReceived += (o, e) =>
            {
                var data = new byte[port.BytesToRead];
                port.Read(data, 0, data.Length);
                node.OnIncomingData(data);
            };

            port.ErrorReceived += (o, e) => { PortErrorEventHandler.Rise(this, e); };
        }
コード例 #2
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
        }