示例#1
0
        public static void Main(string[] args)
        {
            bool running = true;

            // use Ctrl-C to stop the programm
            Console.CancelKeyPress += delegate(object sender, ConsoleCancelEventArgs e) {
                e.Cancel = true;
                running  = false;
            };

            string hostname = "localhost";
            int    tcpPort  = 2404;

            if (args.Length > 0)
            {
                hostname = args [0];
            }

            if (args.Length > 1)
            {
                int.TryParse(args [1], out tcpPort);
            }

            // Setup virtual serial port
            TcpClientVirtualSerialPort port = new TcpClientVirtualSerialPort(hostname, tcpPort);

            port.Start();

            // Setup balanced CS101 master
            LinkLayerParameters llParameters = new LinkLayerParameters();

            llParameters.AddressLength    = 1;
            llParameters.UseSingleCharACK = false;

            CS101Master master = new CS101Master(port, LinkLayerMode.BALANCED, llParameters);

            master.DebugOutput  = false;
            master.OwnAddress   = 1;
            master.SlaveAddress = 2;
            master.SetASDUReceivedHandler(asduReceivedHandler, null);
            master.SetLinkLayerStateChangedHandler(linkLayerStateChanged, null);
            master.SetReceivedRawMessageHandler(rcvdRawMessageHandler, null);

            long lastTimestamp = SystemUtils.currentTimeMillis();

            // This will start a separate thread!
            // alternativley you can you master.Run() inside the loop
            master.Start();

            while (running)
            {
                if ((SystemUtils.currentTimeMillis() - lastTimestamp) >= 5000)
                {
                    lastTimestamp = SystemUtils.currentTimeMillis();

                    if (master.GetLinkLayerState() == lib60870.linklayer.LinkLayerState.AVAILABLE)
                    {
                        master.SendInterrogationCommand(CauseOfTransmission.ACTIVATION, 1, 20);
                    }
                    else
                    {
                        Console.WriteLine("Link layer: " + master.GetLinkLayerState().ToString());
                    }
                }
            }

            master.Stop();

            port.Stop();
        }
示例#2
0
        public static void Main(string[] args)
        {
            bool running = true;

            // use Ctrl-C to stop the programm
            Console.CancelKeyPress += delegate(object sender, ConsoleCancelEventArgs e) {
                e.Cancel = true;
                running  = false;
            };

            string portName = "/dev/ttyUSB1";

            if (args.Length > 0)
            {
                portName = args [0];
            }

            // Setup serial port
            SerialPort port = new SerialPort();

            port.PortName  = portName;
            port.BaudRate  = 9600;
            port.Parity    = Parity.Even;
            port.Handshake = Handshake.None;
            port.Open();
            port.DiscardInBuffer();

            // Setup balanced CS101 master
            LinkLayerParameters llParameters = new LinkLayerParameters();

            llParameters.AddressLength    = 1;
            llParameters.UseSingleCharACK = false;

            CS101Master master = new CS101Master(port, LinkLayerMode.BALANCED, llParameters);

            master.DebugOutput  = false;
            master.OwnAddress   = 1;
            master.SlaveAddress = 2;
            master.SetASDUReceivedHandler(asduReceivedHandler, null);
            master.SetLinkLayerStateChangedHandler(linkLayerStateChanged, null);
            master.SetReceivedRawMessageHandler(rcvdRawMessageHandler, null);

            long lastTimestamp = SystemUtils.currentTimeMillis();

            // This will start a separate thread!
            // alternativley you can you master.Run() inside the loop
            master.Start();

            while (running)
            {
                if ((SystemUtils.currentTimeMillis() - lastTimestamp) >= 5000)
                {
                    lastTimestamp = SystemUtils.currentTimeMillis();

                    if (master.GetLinkLayerState() == lib60870.linklayer.LinkLayerState.AVAILABLE)
                    {
                        master.SendInterrogationCommand(CauseOfTransmission.ACTIVATION, 1, 20);
                    }
                    else
                    {
                        Console.WriteLine("Link layer: " + master.GetLinkLayerState().ToString());
                    }
                }
            }

            master.Stop();

            port.Close();
        }