Example #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));

            formatter.AddItem(byteArrayCompositeValueItem);

            interpreter.AddFormatter(formatter);

            ByteArrayAdapter baa = new ByteArrayAdapter("ByteArrayAdapter", channelTcpServer, interpreter, Program.ShowEnvelop);
            baa.Setup();
        }
Example #2
0
        private object GetInterpreter(XElement element)
        {
            string interpreterType = GetAttribute(element, "Type");
            string interpreterName = GetAttribute(element, "Name");

            var headerElement = element.Element("Header");
            var trailerElement = element.Element("Tailer");

            IObjectWithName returnInterpreter = null;

            if (interpreterType == "MultipleFormatterByteArrayInterpreter")
            {
                MultipleFormatterByteArrayInterpreter interpreter = new MultipleFormatterByteArrayInterpreter(interpreterName);

                if (headerElement != null && !string.IsNullOrEmpty(headerElement.Value.Trim()))
                {
                    string headerString = headerElement.Value;
                    interpreter.SetHeaders(HexStringToByteArray(headerString));
                }

                if (trailerElement != null && !string.IsNullOrEmpty(trailerElement.Value.Trim()))
                {
                    string tailerString = trailerElement.Value;
                    interpreter.SetTailers(HexStringToByteArray(tailerString));
                }

                foreach (var formatterElement in element.Elements("Formatter"))
                {
                    interpreter.AddFormatter((IFormatter<byte[]>)GetFormatter(formatterElement));
                }

                if (element.Element("FormatterFilter") != null)
                {
                    foreach (var filterElement in element.Elements("FormatterFilter"))
                    {
                        IFormatterFilter<byte[]> filter = (IFormatterFilter<byte[]>)GetFormatterFilter(filterElement);
                        interpreter.AddFormatterFilter(filter);
                    }
                }

                returnInterpreter = interpreter;
            }
            else if (interpreterType == "SingleFormatterByteArrayInterpreter")
            {
                SingleFormatterByteArrayInterpreter interpreter = new SingleFormatterByteArrayInterpreter(interpreterName);

                if (headerElement != null && !string.IsNullOrEmpty(headerElement.Value.Trim()))
                {
                    string headerString = headerElement.Value;
                    interpreter.SetHeaders(HexStringToByteArray(headerString));
                }

                if (trailerElement != null && !string.IsNullOrEmpty(trailerElement.Value.Trim()))
                {
                    string tailerString = trailerElement.Value;
                    interpreter.SetTailers(HexStringToByteArray(tailerString));
                }

                var formatterElement = element.Element("Formatter");

                interpreter.AddFormatter((IFormatter<byte[]>)GetFormatter(formatterElement));

                returnInterpreter = interpreter;
            }
            else if (interpreterType == "StringInterpreter")
            {
                StringInterpreter interpreter = new StringInterpreter(interpreterName);

                var formatterElement = element.Element("Formatter");

                interpreter.AddFormatter((IFormatter<string>)GetFormatter(formatterElement));

                returnInterpreter = interpreter;
            }
            else
            {
                throw new UnknownElementException("Unknown interpreter type:" + interpreterType);
            }

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

            return returnInterpreter;
        }
Example #3
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();
        }
Example #4
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();
        }