コード例 #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
        private void AcknowledgeSentItems(int to)
        {
            for (byte a = A; a != to; a++)
            {
                A++;
                var acknowledgedBlock = sentDataBlocks[A];
                BytesTransmitted += Convert.ToUInt32(acknowledgedBlock.Length);
                sentDataBlocks.Remove(A);
                OnDataBlockAcknowledgedEventHandler.Rise(this, new uMCPDataEventArgs(acknowledgedBlock));
            }

            if (sentDataBlocks.Count == 0)
            {
                OnTransmitterEmptyEventHandler.Rise(this, new EventArgs());
            }
        }
コード例 #3
0
        private void AcknowledgeSentItems(int to)
        {
            byte from = A;
            byte a    = from;

            while (a != to)
            {
                a = Convert.ToByte((a + 1) % MaxMessages);
                A = Convert.ToByte((A + 1) % MaxMessages);
                var acknowledgedBlock = sentDataBlocks[A];
                BytesTransmitted += Convert.ToUInt32(acknowledgedBlock.Length);
                sentDataBlocks.Remove(A);
                OnDataBlockAcknowledgedEventHandler.Rise(this, new uMCPInoDataEventArgs(acknowledgedBlock));
            }

            if (sentDataBlocks.Count == 0)
            {
                OnTransmitterEmptyEventHandler.Rise(this, new EventArgs());
            }
        }