예제 #1
0
        public static void Main()
        {
            const Int32 c_port = 2000;

            byte[] ip      = { 192, 168, 1, 100 };
            byte[] subnet  = { 255, 255, 255, 0 };
            byte[] gateway = { 192, 168, 1, 1 };
            byte[] mac     = { 0x00, 0x26, 0x1C, 0x7B, 0x29, 0xE8 };
            WIZnet_W5100.Enable(SPI.SPI_module.SPI1, (Cpu.Pin)FEZ_Pin.Digital.Di10,
                                (Cpu.Pin)FEZ_Pin.Digital.Di7, true);
            NetworkInterface.EnableStaticIP(ip, subnet, gateway, mac);
            NetworkInterface.EnableStaticDns(new byte[] { 192, 168, 1, 1 });
            Socket server = new Socket(AddressFamily.InterNetwork,
                                       SocketType.Stream, ProtocolType.Tcp);
            IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Any, c_port);

            server.Bind(localEndPoint);
            server.Listen(1);
            while (true)
            {
                // Wait for a client to connect.
                Socket clientSocket = server.Accept();
                // Process the client request. true means asynchronous.
                new ProcessClientRequest(clientSocket, true);
            }
        }
예제 #2
0
 /// <summary>
 /// Initalizes the network shield to use a static IP connection and the provided MAC address.
 /// </summary>
 /// <param name="ip">The IP address assigned to your device.</param>
 /// <param name="subnet">Your connection's subnet address</param>
 /// <param name="gateway">You connection'sgateway address</param>
 /// <param name="mac">
 /// This must be a unique MAC address value represented as a byte array.
 ///  Here is a resource for generating random MAC addresses: http://www.macvendorlookup.com/
 /// </param>
 /// <param name="dns">The IP address of your DNS server</param>
 public static void Initialize(byte[] ip, byte[] subnet, byte[] gateway, byte[] mac, byte[] dns)
 {
     // Configure the ethernet port
     WIZnet_W5100.Enable(SPI.SPI_module.SPI1, (Cpu.Pin)FEZ_Pin.Digital.Di10, (Cpu.Pin)FEZ_Pin.Digital.Di9, true); // WIZnet interface on FEZ Panda
     NetworkInterface.EnableStaticIP(ip, subnet, gateway, mac);
     NetworkInterface.EnableStaticDns(dns);
 }
예제 #3
0
 private void ServerAgent()
 {
     while (!_serverTerminate)
     {
         try
         {
             WIZnet_W5100.Enable(SPI.SPI_module.SPI1, (Cpu.Pin)FEZ_Pin.Digital.Di10, (Cpu.Pin)FEZ_Pin.Digital.Di7, true);
             NetworkInterface.EnableStaticIP(ServerAddress, ServerSubnet, ServerGateway, ServerMac);
             NetworkInterface.EnableStaticDns(ServerGateway);
             try
             {
                 ListenerClose(/*_listenerSocket == null*/);   /*just to ensure tidiness*/
                 _listenerSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                 try
                 {
                     IPEndPoint endPoint = new IPEndPoint(IPAddress.Any, ServerPort);
                     _listenerSocket.Bind(endPoint);
                     _listenerSocket.Listen(1);                        /*blocks...*/
                     SessionClose(/*_sessionSocket == null*/);         /*just to ensure tidiness*/
                     using (_sessionSocket = _listenerSocket.Accept()) /*using overkill, but what th' hey...*/
                         try
                         {
                             SignOfLifeStart(/*_signOfLifeTimer != null*/);
                             try
                             {
                                 byte[] buffer = new byte[/*extra for safety*/ 2 * CommandDefinition.PacketSize];
                                 while (/*read OK?*/ _sessionSocket.Receive(buffer, buffer.Length, SocketFlags.None) >= 1 /*blocks...*/)
                                 {
                                     CommandDefinition.CommandFormat command = new CommandDefinition.CommandFormat();
                                     command = command.Deserialize(buffer);
                                     ProcessCommand(command);
                                 }
                             }
                             catch { SendSignOfLife(uint.MaxValue - 4); }
                             finally { SignOfLifeStop(/*_signOfLifeTimer == null*/); }
                         }
                         catch { SendSignOfLife(uint.MaxValue - 3); }
                         finally { SessionClose(/*_sessionSocket == null*/); }
                 }
                 catch { SendSignOfLife(uint.MaxValue - 2); }
                 finally { ListenerClose(/*_listenerSocket == null*/); }
             }
             catch { SendSignOfLife(uint.MaxValue - 1); }
             finally { WIZnet_W5100.ReintializeNetworking(); }
         }
         catch { SendSignOfLife(uint.MaxValue); }
         finally
         {
             Thread.Sleep(/*1s*/ 1000 /*ms*/);
             Program.ResetBoard();
         }
     }
 }
예제 #4
0
        public static void Main()
        {
            M8_TempMgr tempMgr;
            M8_PID     pid;
            M8_SSR     ssr;

            M8_WebServer server;

            DateTime updateIn = new DateTime();

            // We want to update every second
            updateIn = DateTime.Now.AddMilliseconds(1000);

            pid     = new M8_PID(M8_PID.defaultPGain, M8_PID.defaultIGain, M8_PID.defaultDGain);
            ssr     = new M8_SSR((Cpu.Pin)FEZ_Pin.Digital.Di6);
            tempMgr = new M8_TempMgr((Cpu.Pin)FEZ_Pin.Digital.Di5);
            tempMgr.setPidThermometer(0);

            Debug.Print("W5100.Enable");
            WIZnet_W5100.Enable(SPI.SPI_module.SPI1, (Cpu.Pin)FEZ_Pin.Digital.Di10, (Cpu.Pin)FEZ_Pin.Digital.Di9, false);
            //We need to give the Wiz chip some "alone time"
            Thread.Sleep(1000);

            NetworkInterface.EnableStaticIP(new byte[] { 192, 168, 1, 177 }, new byte[] { 255, 255, 255, 0 }, new byte[] { 192, 168, 1, 1 }, new byte[] { 0x90, 0xA2, 0xDA, 0x00, 0x14, 0x14 });
            NetworkInterface.EnableStaticDns(new byte[] { 192, 168, 1, 1 });

            server = new M8_WebServer(new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp), tempMgr, pid, ssr);

            server.startServer(80);

            while (true)
            {
                //Read the temps in
                if (DateTime.Now > updateIn)
                {
                    tempMgr.update();

                    //Calculate the PID value and set it on the SSR
                    pid.calcPID(tempMgr.getTemp(), tempMgr.getError());
                    ssr.setPower(pid.getSSRValue());

                    updateIn = DateTime.Now.AddMilliseconds(1000);

                    Debug.Print("-----------------" + DateTime.Now.ToString());
                }

                //Update the SSR
                ssr.update();

                server.update();
            }
        }
예제 #5
0
 private static void InitNetwork()
 {
     //сетевая конфигурация
     byte[] ip      = { 192, 168, 10, 1 };
     byte[] subnet  = { 255, 255, 255, 0 };
     byte[] gateway = { 192, 168, 10, 10 };
     byte[] mac     = { 0x00, 0x26, 0x1C, 0x7B, 0x29, 0xE8 };
     //инициализация сети
     WIZnet_W5100.Enable(SPI.SPI_module.SPI1, (Cpu.Pin)FEZ_Pin.Digital.Di10, (Cpu.Pin)FEZ_Pin.Digital.Di9, false);
     GHIElectronics.NETMF.Net.NetworkInformation.NetworkInterface.EnableStaticIP(ip, subnet, gateway, mac);
     GHIElectronics.NETMF.Net.NetworkInformation.NetworkInterface.EnableStaticDns(gateway); // DNS Server
     //
     Debug.Print("InitNetwork OK");
 }
예제 #6
0
        /** Configure Wi-Fi shield and setup internet settings */
        private void enableNetworking()
        {
            WIZnet_W5100.Enable(SPI.SPI_module.SPI1,           // спецификация производителя
                                (Cpu.Pin)FEZ_Pin.Digital.Di10, // спецификация производителя
                                (Cpu.Pin)FEZ_Pin.Digital.Di7,  // ???
                                false);

            // TODO пояснить что и зачем
            byte[] ipAddress = new byte[] { 192, 168, 17, 36 };
            byte[] netmask   = new byte[] { 255, 255, 255, 0 };
            byte[] gateway   = new byte[] { 192, 168, 17, 1 };
            // set our own mac address for this device
            byte[] macAddress = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x36 };

            NetworkInterface.EnableStaticIP(ipAddress, netmask, gateway, macAddress);
        }
예제 #7
0
파일: Program.cs 프로젝트: donwilliam/itWEM
        public static void Main()
        {
            led    = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.LED, ledState);
            config = new I2CDevice.Configuration(address, clockRateKHz);
            device = new I2CDevice(config);
            WIZnet_W5100.Enable(SPI.SPI_module.SPI1, (Cpu.Pin)FEZ_Pin.Digital.Di10, (Cpu.Pin)FEZ_Pin.Digital.Di7, true);
            Dhcp.EnableDhcp(new byte[] { 0x00, 0x26, 0x1C, 0x7B, 0x29, 0xE8 }, "tt");


            while (true)
            {
                uploadData(gatherData());
                getHeaterStatus();
                setHeaterStatus();

                Thread.Sleep(updateTime);
            }
        }
예제 #8
0
        // подготовить микроконтроллер для работы с интернетом
        private void enableNetworking()
        {
            // Настраиваем Wi-Fi модуль WIZNet W5100
            WIZnet_W5100.Enable(SPI.SPI_module.SPI1,           // спецификация производителя
                                (Cpu.Pin)FEZ_Pin.Digital.Di10, // спецификация производителя
                                (Cpu.Pin)FEZ_Pin.Digital.Di7,  // ???
                                false);

            // TODO пояснить что и зачем
            // ИП аддресс для нашего микроконтроллера
            byte[] ipAddress = new byte[] { 192, 168, 17, 36 };
            byte[] netmask   = new byte[] { 255, 255, 255, 0 };
            byte[] gateway   = new byte[] { 192, 168, 17, 1 };
            // set our own mac address for this device
            byte[] macAddress = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x36 };

            // enable microcontroller to use static IP
            NetworkInterface.EnableStaticIP(ipAddress, netmask, gateway, macAddress);
        }
예제 #9
0
        /// <summary>
        /// Initialize connection
        /// </summary>
        public DataPointService(Credentials credentials, string projectName, string hubId, int intervalMilliseconds)
        {
            // Configure Internet connection
            byte[] mac      = { 0x00, 0x26, 0x1C, 0x7B, 0x29, 0xE8 };
            string hostname = "idiotsdk";

            WIZnet_W5100.Enable(SPI.SPI_module.SPI1, (Cpu.Pin)FEZ_Pin.Digital.Di10, (Cpu.Pin)FEZ_Pin.Digital.Di7, true);
            Dhcp.EnableDhcp(mac, hostname);
            Dhcp.RenewDhcpLease();

            // Set current time
            NTPTime("pool.ntp.org");

            // Set interval between requests
            this.RequestInterval = intervalMilliseconds;

            this.username    = credentials.Username;
            this.credentials = credentials;
            this.projectName = projectName;
            this.hubId       = hubId;

            // TODO: Display info on screen module
        }
예제 #10
0
 /// <summary>
 /// Initalizes the network shield to use a DHCP connection and the provided MAC address.
 /// </summary>
 /// <param name="mac">
 ///  This must be a unique MAC address value represented as a byte array.
 ///  Here is a resource for generating random MAC addresses: http://www.macvendorlookup.com/
 /// </param>
 public static void Initialize(byte[] mac)
 {
     // Configure the ethernet port
     WIZnet_W5100.Enable(SPI.SPI_module.SPI1, (Cpu.Pin)FEZ_Pin.Digital.Di10, (Cpu.Pin)FEZ_Pin.Digital.Di9, true); // WIZnet interface on FEZ Panda
     Dhcp.EnableDhcp(mac, "FEZDomino");
 }