Exemplo n.º 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 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();
        }
Exemplo n.º 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 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();
        }
Exemplo n.º 3
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/ttyUSB3";

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

            SerialPort port = new SerialPort();

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

            /* set link layer address length */
            LinkLayerParameters llParameters = new LinkLayerParameters();

            llParameters.AddressLength = 1;

            /* unbalanced mode allows multiple slaves on a single serial line */
            CS101Master master = new CS101Master(port, LinkLayerMode.UNBALANCED, llParameters);

            master.DebugOutput = false;
            master.SetASDUReceivedHandler(asduReceivedHandler, null);

            master.SetLinkLayerStateChangedHandler(linkLayerStateChanged, null);

            master.AddSlave(1);
            master.AddSlave(2);

            long lastTimestamp = SystemUtils.currentTimeMillis();

            master.SlaveAddress = 1;
            //master.GetFile (1, 30000, NameOfFile.TRANSPARENT_FILE, new Receiver ());


            while (running)
            {
                master.PollSingleSlave(1);

                master.Run();

                master.PollSingleSlave(2);

                master.Run();

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

                    try {
                        master.SlaveAddress = 1;
                        master.SendInterrogationCommand(CauseOfTransmission.ACTIVATION, 1, 20);
                    }
                    catch (LinkLayerBusyException) {
                        Console.WriteLine("Slave 1: Link layer busy or not ready");
                    }

                    try {
                        master.SlaveAddress = 2;
                        master.SendInterrogationCommand(CauseOfTransmission.ACTIVATION, 2, 20);
                    }
                    catch (LinkLayerBusyException) {
                        Console.WriteLine("Slave 2: Link layer busy or not ready");
                    }
                }
            }

            port.Close();
        }