Exemple #1
0
        public void StartServer()
        {
            TcpServerChannel channelTcpServer = new TcpServerChannel("TcpServerChannel", 9988);
            SingleFormatterByteArrayInterpreter interpreter = new SingleFormatterByteArrayInterpreter("Interpreter");

            interpreter.SetTailers(new byte[] { 0xAA, 0x55 });
            interpreter.SetHeaders(new byte[] { 0x55, 0xAA });

            ByteArrayFormatter formatter = new ByteArrayFormatter("Formatter1");

            ByteArrayCompositeValueItem byteArrayCompositeValueItem = new ByteArrayCompositeValueItem("ByteArrayCompositeValueItem1");

            byteArrayCompositeValueItem.AddItem(new ByteArrayStringItem("NodeName", 1, 6, Encoding.ASCII));
            byteArrayCompositeValueItem.AddItem(new ByteArrayInt32Item("NodeId", 0));
            byteArrayCompositeValueItem.AddItem(new ByteArrayInt16Item("Temperature", 2));
            byteArrayCompositeValueItem.AddItem(new ByteArrayDoubleItem("Longitude", 3));
            byteArrayCompositeValueItem.AddItem(new ByteArrayByteItem("Reserved", 4));

            ByteArrayLoopItem byteArrayLoopItem = new ByteArrayLoopItem("byteArrayLoopItem1", 1, byteArrayCompositeValueItem);

            formatter.AddItem(new ByteArrayInt32Item("Type", 0));
            formatter.AddItem(byteArrayLoopItem);

            interpreter.AddFormatter(formatter);

            ByteArrayAdapter baa = new ByteArrayAdapter("ByteArrayAdapter", channelTcpServer, interpreter, Program.ShowEnvelop);

            baa.Setup();
        }
Exemple #2
0
        /// <summary>
        /// Get the attribute value.
        /// </summary>
        /// <typeparam name="TAttributeValue">The attribute value generic type.</typeparam>
        /// <param name="attributeName">The attribute name.</param>
        /// <returns>The attribute value.</returns>
        public TAttributeValue GetAttributeValue <TAttributeValue>(string attributeName)
        {
            object attributeValue = default(TAttributeValue);

            if (typeof(TAttributeValue) == typeof(string))
            {
                attributeValue = new SingleLineAdapter(this.SearchResult.Properties[attributeName]).Value;
            }
            else if (typeof(TAttributeValue) == typeof(byte[]))
            {
                attributeValue = new ByteArrayAdapter(this.SearchResult.Properties[attributeName]).Value;
            }
            else if (typeof(TAttributeValue) == typeof(DateTime))
            {
                attributeValue = new DateTimeAdapter(this.SearchResult, attributeName).Value;
            }
            else if (typeof(TAttributeValue) == typeof(Guid))
            {
                attributeValue = new GuidAdapter(this.SearchResult.Properties[attributeName]).Value;
            }
            else if (typeof(TAttributeValue) == typeof(int))
            {
                attributeValue = new IntegerAdapter(this.SearchResult.Properties[attributeName]).Value;
            }
            else if (typeof(TAttributeValue) == typeof(IList <string>) || typeof(TAttributeValue) == typeof(List <string>))
            {
                attributeValue = new MultipleLineAdapter(this.SearchResult.Properties[attributeName]).Value;
            }
            return((TAttributeValue)attributeValue);
        }
Exemple #3
0
        public void StartServer()
        {
            TcpServerChannel tcpServerChannel = new TcpServerChannel("TcpServerChannel", 9988);

            SingleFormatterByteArrayInterpreter interpreter = new SingleFormatterByteArrayInterpreter("Interpreter");

            interpreter.SetHeaders(new byte[] { 0x55, 0xAA });
            interpreter.SetTailers(new byte[] { 0xAA, 0x55 });

            ByteArrayFormatter formatter = new ByteArrayFormatter("Formatter1");

            formatter.AddItem(new ByteArrayStringItem("NodeName", 1, 6, Encoding.ASCII));
            formatter.AddItem(new ByteArrayInt32Item("NodeId", 0));
            formatter.AddItem(new ByteArrayInt16Item("Temperature", 2));
            formatter.AddItem(new ByteArrayDoubleItem("Longitude", 3));

            ByteArrayByteItem babi = new ByteArrayByteItem("Flags", 4);

            babi.AddBitItem("Flag1", 1);
            babi.AddBitItem("Flag2", 3);
            babi.AddBitItem("Flag3", 4);
            formatter.AddItem(babi);

            interpreter.AddFormatter(formatter);

            ByteArrayAdapter baa = new ByteArrayAdapter("ByteArrayAdapter", tcpServerChannel, interpreter, Program.ShowEnvelop);

            baa.Setup();
        }
Exemple #4
0
        public void StartServer()
        {
            TcpServerChannel tcpServerChannel = new TcpServerChannel("TcpServerChannel", 9988);

            IActivator activator1 = new OneTimeActivator("Activator1");

            byte[] command1Bytes = new byte[] { 0x01, 0x16 };
            activator1.AddCommand(new ByteArrayCommand("command1", tcpServerChannel, command1Bytes));

            SingleFormatterByteArrayInterpreter interpreter = new SingleFormatterByteArrayInterpreter("Interpreter");

            interpreter.SetHeaders(new byte[] { 0x55, 0xAA });
            interpreter.SetTailers(new byte[] { 0xAA, 0x55 });

            ByteArrayFormatter formatter = new ByteArrayFormatter("Formatter1");

            formatter.AddItem(new ByteArrayStringItem("NodeName", 1, 6, Encoding.ASCII));
            formatter.AddItem(new ByteArrayInt32Item("NodeId", 0));
            formatter.AddItem(new ByteArrayInt16Item("Temperature", 2));
            formatter.AddItem(new ByteArrayDoubleItem("Longitude", 3));
            formatter.AddItem(new ByteArrayByteItem("Reserved", 4));

            interpreter.AddFormatter(formatter);

            tcpServerChannel.Connected += activator1.SendToTarget;

            ByteArrayAdapter baa = new ByteArrayAdapter("ByteArrayAdapter", tcpServerChannel, interpreter, Program.ShowEnvelop);

            baa.Setup();
        }
Exemple #5
0
        public void StartServer()
        {
            TcpServerChannel channelTcpServer = new TcpServerChannel("TcpServerChannel", 9988);
            MultipleFormatterByteArrayInterpreter interpreter = new MultipleFormatterByteArrayInterpreter("Interpreter");

            interpreter.SetTailers(new byte[] { 0xAA, 0x55 });
            interpreter.SetHeaders(new byte[] { 0x55, 0xAA });

            /////////////////////////////////////////////////////////////////////////////////////////

            ByteArrayFormatter formatter_F1 = new ByteArrayFormatter("Formatter1", 1);

            ByteArrayCompositeValueItem byteArrayCompositeValueItem_F1 = new ByteArrayCompositeValueItem("F1_ByteArrayCompositeValueItem1");

            byteArrayCompositeValueItem_F1.AddItem(new ByteArrayStringItem("F1_NodeName", 1, 6, Encoding.ASCII));
            byteArrayCompositeValueItem_F1.AddItem(new ByteArrayInt32Item("F1_NodeId", 0));
            byteArrayCompositeValueItem_F1.AddItem(new ByteArrayInt16Item("F1_Temperature", 2));
            byteArrayCompositeValueItem_F1.AddItem(new ByteArrayDoubleItem("F1_Longitude", 3));
            byteArrayCompositeValueItem_F1.AddItem(new ByteArrayByteItem("F1_Reserved", 4));

            ByteArrayLoopItem byteArrayLoopItem_F1 = new ByteArrayLoopItem("F1_byteArrayLoopItem1", 1, byteArrayCompositeValueItem_F1);

            formatter_F1.AddItem(new ByteArrayInt32Item("F1_Type", 0));
            formatter_F1.AddItem(byteArrayLoopItem_F1);

            /////////////////////////////////////////////////////////////////////////////////////////

            ByteArrayFormatter formatter_F2 = new ByteArrayFormatter("Formatter2", 2);

            formatter_F2.AddItem(new ByteArrayInt32Item("F2_Type", 0));
            formatter_F2.AddItem(new ByteArrayStringItem("F2_NodeName", 2, 6, Encoding.ASCII));
            formatter_F2.AddItem(new ByteArrayInt32Item("F2_NodeId", 1));
            formatter_F2.AddItem(new ByteArrayInt16Item("F2_Temperature", 3));
            formatter_F2.AddItem(new ByteArrayDoubleItem("F2_Longitude", 4));
            formatter_F2.AddItem(new ByteArrayByteItem("F2_Reserved", 5));

            ///////////////////////////////////////////////////////////////////////////////////////////////

            ByteArrayTypedFormatterFilter byteArrayTypedFormatterFilter = new ByteArrayTypedFormatterFilter("ByteArrayTypedFormatterFilter", 0);

            //the index we use 0 meaning the Type Id is the index[0] in the input buffer without header.

            interpreter.AddFormatter(formatter_F1);
            interpreter.AddFormatter(formatter_F2);
            interpreter.AddFormatterFilter(byteArrayTypedFormatterFilter);

            ByteArrayAdapter baa = new ByteArrayAdapter("ByteArrayAdapter", channelTcpServer, interpreter, Program.ShowEnvelop);

            baa.Setup();
        }
        private IAdapter GetAdapter(XElement element)
        {
            string adapterType = GetAttribute(element, "Type");
            string adapterName = GetAttribute(element, "Name");

            IAdapter adapter = null;

            var channelElement = element.Element("Channel");

            if (channelElement == null)
            {
                throw new ElementNotFoundException("Channel elemnt not found.");
            }

            var interpreterElement = element.Element("Interpreter");

            if (interpreterElement == null)
            {
                throw new ElementNotFoundException("Interpreter elemnt not found.");
            }

            if (adapterType == "ByteArrayAdapter")
            {
                IChannel <byte[]>     channel     = (IChannel <byte[]>)GetChannel(channelElement);
                IInterpreter <byte[]> interpreter = (IInterpreter <byte[]>)GetInterpreter(interpreterElement);

                adapter = new ByteArrayAdapter(adapterName, channel, interpreter);
            }
            else if (adapterType == "StringAdapter")
            {
                IChannel <string>     channel     = (IChannel <string>)GetChannel(channelElement);
                IInterpreter <string> interpreter = (IInterpreter <string>)GetInterpreter(interpreterElement);

                adapter = new StringAdapter(adapterName, channel, interpreter);
            }
            else
            {
                throw new UnknownElementException("Unknown adapter type:" + adapterType);
            }

            _adapterObjects[_currentAdapterName].Add(adapter.Name, adapter);

            return(adapter);
        }
Exemple #7
0
        public void StartServer()
        {
            TcpServerChannel channelTcpServer = new TcpServerChannel("TcpServerChannel", 9988);
            SingleFormatterByteArrayInterpreter interpreter = new SingleFormatterByteArrayInterpreter("Interpreter");

            ByteArrayFormatter formatter = new ByteArrayFormatter("Formatter1");

            formatter.AddItem(new ByteArrayStringItem("NodeName", 1, 6, Encoding.ASCII));
            formatter.AddItem(new ByteArrayInt32Item("NodeId", 0));
            formatter.AddItem(new ByteArrayInt16Item("Temperature", 2));
            formatter.AddItem(new ByteArrayDoubleItem("Longitude", 3));
            formatter.AddItem(new ByteArrayByteItem("Reserved", 4));

            interpreter.AddFormatter(formatter);

            ByteArrayAdapter baa = new ByteArrayAdapter("ByteArrayAdapter", channelTcpServer, interpreter, Program.ShowEnvelop);

            baa.Setup();
        }
Exemple #8
0
        public void StartServer()
        {
            TcpServerChannel channelTcpServer = new TcpServerChannel("TcpServerChannel", 9988);
            SingleFormatterByteArrayInterpreter interpreter = new SingleFormatterByteArrayInterpreter("Interpreter");

            interpreter.SetTailers(new byte[] { 0xAA, 0x55 });
            interpreter.SetHeaders(new byte[] { 0x55, 0xAA });

            ByteArrayFormatter formatter = new ByteArrayFormatter("Formatter1");

            formatter.AddItem(new ByteArrayStringItem("NodeName", 1, 6, Encoding.ASCII));
            formatter.AddItem(new ByteArrayInt32Item("NodeId", 0));
            formatter.AddItem(new CustomItem("CustomItem", 2, "test2"));
            formatter.AddItem(new ByteArrayByteItem("Reserved", 3));

            interpreter.AddFormatter(formatter);

            ByteArrayAdapter baa = new ByteArrayAdapter("ByteArrayAdapter", channelTcpServer, interpreter, Program.ShowEnvelop);

            baa.Setup();
        }
Exemple #9
0
        public void StartServer()
        {
            TcpServerChannel channelTcpServer = new TcpServerChannel("TcpServerChannel", 9988);
            SingleFormatterByteArrayInterpreter interpreter = new SingleFormatterByteArrayInterpreter("Interpreter");

            interpreter.SetTailers(new byte[] { 0xAA, 0x55 });
            interpreter.SetHeaders(new byte[] { 0x55, 0xAA });

            ByteArrayFormatter formatter = new ByteArrayFormatter("Formatter1");

            ByteArrayCompositeValueItem byteArrayCompositeValueItem = new ByteArrayCompositeValueItem("ByteArrayCompositeValueItem1");
            byteArrayCompositeValueItem.AddItem(new ByteArrayStringItem("NodeName", 1, 6, Encoding.ASCII));
            byteArrayCompositeValueItem.AddItem(new ByteArrayInt32Item("NodeId", 0));
            byteArrayCompositeValueItem.AddItem(new ByteArrayInt16Item("Temperature", 2));
            byteArrayCompositeValueItem.AddItem(new ByteArrayDoubleItem("Longitude", 3));
            byteArrayCompositeValueItem.AddItem(new ByteArrayByteItem("Reserved", 4));

            formatter.AddItem(byteArrayCompositeValueItem);

            interpreter.AddFormatter(formatter);

            ByteArrayAdapter baa = new ByteArrayAdapter("ByteArrayAdapter", channelTcpServer, interpreter, Program.ShowEnvelop);
            baa.Setup();
        }
Exemple #10
0
        public void StartServer()
        {
            TcpServerChannel tcpServerChannel = new TcpServerChannel("TcpServerChannel", 9988);

            IntervalActivator activator1 = new IntervalActivator("Activator1", 5000);

            byte[] command1Bytes = new byte[] { 0x01, 0x16 };
            activator1.AddCommand(new ByteArrayCommand("command1", tcpServerChannel, command1Bytes));

            SingleFormatterByteArrayInterpreter interpreter = new SingleFormatterByteArrayInterpreter("Interpreter");
            interpreter.SetHeaders(new byte[] { 0x55, 0xAA });
            interpreter.SetTailers(new byte[] { 0xAA, 0x55 });

            ByteArrayFormatter formatter = new ByteArrayFormatter("Formatter1");

            formatter.AddItem(new ByteArrayStringItem("NodeName", 1, 6, Encoding.ASCII));
            formatter.AddItem(new ByteArrayInt32Item("NodeId", 0));
            formatter.AddItem(new ByteArrayInt16Item("Temperature", 2));
            formatter.AddItem(new ByteArrayDoubleItem("Longitude", 3));
            formatter.AddItem(new ByteArrayByteItem("Reserved", 4));

            interpreter.AddFormatter(formatter);

            ByteArrayAdapter baa = new ByteArrayAdapter("ByteArrayAdapter", tcpServerChannel, interpreter, Program.ShowEnvelop);

            baa.SetupFinished += activator1.StartProcess;

            baa.Setup();
        }
Exemple #11
0
        public void StartServer()
        {
            TcpServerChannel channelTcpServer = new TcpServerChannel("TcpServerChannel", 9988);
            MultipleFormatterByteArrayInterpreter interpreter = new MultipleFormatterByteArrayInterpreter("Interpreter");

            interpreter.SetTailers(new byte[] { 0xAA, 0x55 });
            interpreter.SetHeaders(new byte[] { 0x55, 0xAA });

            /////////////////////////////////////////////////////////////////////////////////////////

            ByteArrayFormatter formatter_F1 = new ByteArrayFormatter("Formatter1", 1);

            ByteArrayCompositeValueItem byteArrayCompositeValueItem_F1 = new ByteArrayCompositeValueItem("F1_ByteArrayCompositeValueItem1");
            byteArrayCompositeValueItem_F1.AddItem(new ByteArrayStringItem("F1_NodeName", 1, 6, Encoding.ASCII));
            byteArrayCompositeValueItem_F1.AddItem(new ByteArrayInt32Item("F1_NodeId", 0));
            byteArrayCompositeValueItem_F1.AddItem(new ByteArrayInt16Item("F1_Temperature", 2));
            byteArrayCompositeValueItem_F1.AddItem(new ByteArrayDoubleItem("F1_Longitude", 3));
            byteArrayCompositeValueItem_F1.AddItem(new ByteArrayByteItem("F1_Reserved", 4));

            ByteArrayLoopItem byteArrayLoopItem_F1 = new ByteArrayLoopItem("F1_byteArrayLoopItem1", 1, byteArrayCompositeValueItem_F1);

            formatter_F1.AddItem(new ByteArrayInt32Item("F1_Type", 0));
            formatter_F1.AddItem(byteArrayLoopItem_F1);

            /////////////////////////////////////////////////////////////////////////////////////////

            ByteArrayFormatter formatter_F2 = new ByteArrayFormatter("Formatter2", 2);

            formatter_F2.AddItem(new ByteArrayInt32Item("F2_Type", 0));
            formatter_F2.AddItem(new ByteArrayStringItem("F2_NodeName", 2, 6, Encoding.ASCII));
            formatter_F2.AddItem(new ByteArrayInt32Item("F2_NodeId", 1));
            formatter_F2.AddItem(new ByteArrayInt16Item("F2_Temperature", 3));
            formatter_F2.AddItem(new ByteArrayDoubleItem("F2_Longitude", 4));
            formatter_F2.AddItem(new ByteArrayByteItem("F2_Reserved", 5));

            ///////////////////////////////////////////////////////////////////////////////////////////////

            ByteArrayTypedFormatterFilter byteArrayTypedFormatterFilter = new ByteArrayTypedFormatterFilter("ByteArrayTypedFormatterFilter", 0);
            //the index we use 0 meaning the Type Id is the index[0] in the input buffer without header.

            interpreter.AddFormatter(formatter_F1);
            interpreter.AddFormatter(formatter_F2);
            interpreter.AddFormatterFilter(byteArrayTypedFormatterFilter);

            ByteArrayAdapter baa = new ByteArrayAdapter("ByteArrayAdapter", channelTcpServer, interpreter, Program.ShowEnvelop);
            baa.Setup();
        }
Exemple #12
0
        private IAdapter GetAdapter(XElement element)
        {
            string adapterType = GetAttribute(element, "Type");
            string adapterName = GetAttribute(element, "Name");

            IAdapter adapter = null;

            var channelElement = element.Element("Channel");
            if (channelElement == null)
            {
                throw new ElementNotFoundException("Channel elemnt not found.");
            }

            var interpreterElement = element.Element("Interpreter");
            if (interpreterElement == null)
            {
                throw new ElementNotFoundException("Interpreter elemnt not found.");
            }

            if (adapterType == "ByteArrayAdapter")
            {
                IChannel<byte[]> channel = (IChannel<byte[]>)GetChannel(channelElement);
                IInterpreter<byte[]> interpreter = (IInterpreter<byte[]>)GetInterpreter(interpreterElement);

                adapter = new ByteArrayAdapter(adapterName, channel, interpreter);
            }
            else if (adapterType == "StringAdapter")
            {
                IChannel<string> channel = (IChannel<string>)GetChannel(channelElement);
                IInterpreter<string> interpreter = (IInterpreter<string>)GetInterpreter(interpreterElement);

                adapter = new StringAdapter(adapterName, channel, interpreter);
            }
            else
            {
                throw new UnknownElementException("Unknown adapter type:" + adapterType);
            }

            _adapterObjects[_currentAdapterName].Add(adapter.Name, adapter);

            return adapter;
        }
Exemple #13
0
        public void StartServer()
        {
            TcpServerChannel tcpServerChannel = new TcpServerChannel("TcpServerChannel", 9988);

            SingleFormatterByteArrayInterpreter interpreter = new SingleFormatterByteArrayInterpreter("Interpreter");
            interpreter.SetHeaders(new byte[] { 0x55, 0xAA });
            interpreter.SetTailers(new byte[] { 0xAA, 0x55 });

            ByteArrayFormatter formatter = new ByteArrayFormatter("Formatter1");

            formatter.AddItem(new ByteArrayStringItem("NodeName", 1, 6, Encoding.ASCII));
            formatter.AddItem(new ByteArrayInt32Item("NodeId", 0));
            formatter.AddItem(new ByteArrayInt16Item("Temperature", 2));
            formatter.AddItem(new ByteArrayDoubleItem("Longitude", 3));

            ByteArrayByteItem babi = new ByteArrayByteItem("Flags", 4);
            babi.AddBitItem("Flag1", 1);
            babi.AddBitItem("Flag2", 3);
            babi.AddBitItem("Flag3", 4);
            formatter.AddItem(babi);

            interpreter.AddFormatter(formatter);

            ByteArrayAdapter baa = new ByteArrayAdapter("ByteArrayAdapter", tcpServerChannel, interpreter, Program.ShowEnvelop);

            baa.Setup();
        }