コード例 #1
0
        public M8_WebServer(Socket server, M8_TempMgr tempMgr, M8_PID pid, M8_SSR ssr)
        {
            this._server = server;

            this._tempMgr = tempMgr;
            this._ssr = ssr;
            this._pid = pid;
        }
コード例 #2
0
        /// <summary>
        /// The constructor calls another method to handle the request, but can 
        /// optionally do so in a new thread.
        /// </summary>
        /// <param name="clientSocket"></param>
        /// <param name="asynchronously"></param>
        public M8_ClientRequest(Socket clientSocket, Boolean asynchronously, M8_TempMgr tempMgr, M8_PID pid, M8_SSR ssr)
        {
            m_clientSocket = clientSocket;
                m_ssr = ssr;
                m_pid = pid;
                m_tempMgr = tempMgr;

                if (asynchronously)
                    // Spawn a new thread to handle the request.
                    new Thread(ProcessRequest).Start();
                else ProcessRequest();
        }
コード例 #3
0
        /// <summary>
        /// Initalizes a tcp connectio to the given IP address and port.
        /// </summary>
        /// <param name="destIp">The IP address you are connecting to.</param>
        /// <param name="port">The port you are connecting to.</param>
        public static void ConnectTCP(byte[] destIp, int port)
        {
            if (Connected)
            {
                Disconnect();
            }

            Socket             = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            Socket.SendTimeout = SendTimeout;
            Socket.Connect(new IPEndPoint(new IPAddress(destIp), port));
            myConnected = true;
        }
コード例 #4
0
 /// <summary>
 /// The constructor calls another method to handle the request, but can
 /// optionally do so in a new thread.
 /// </summary>
 /// /// <param name="clientSocket"></param>
 /// <param name="asynchronously"></param>
 public ProcessClientRequest(Socket clientSocket, Boolean asynchronously)
 {
     m_clientSocket = clientSocket;
     if (asynchronously)
     {
         // Spawn a new thread to handle the request.
         new Thread(ProcessRequest).Start();
     }
     else
     {
         ProcessRequest();
     }
 }
コード例 #5
0
        private static Socket InitSocket()
        {
            const Int32 c_port = 1001;
            Socket      server = new Socket(AddressFamily.InterNetwork,
                                            SocketType.Stream, ProtocolType.Tcp);
            IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Any, c_port);

            server.Bind(localEndPoint);
            server.Listen(1);
            //
            Debug.Print("InitSocket OK");
            //
            return(server);
        }
コード例 #6
0
        /// <summary>
        /// The constructor calls another method to handle the request, but can
        /// optionally do so in a new thread.
        /// </summary>
        /// <param name="clientSocket"></param>
        /// <param name="asynchronously"></param>
        public M8_ClientRequest(Socket clientSocket, Boolean asynchronously, M8_TempMgr tempMgr, M8_PID pid, M8_SSR ssr)
        {
            m_clientSocket = clientSocket;
            m_ssr          = ssr;
            m_pid          = pid;
            m_tempMgr      = tempMgr;

            if (asynchronously)
            {
                // Spawn a new thread to handle the request.
                new Thread(ProcessRequest).Start();
            }
            else
            {
                ProcessRequest();
            }
        }
コード例 #7
0
 /// <summary>
 /// The constructor calls another method to handle the request, but can
 /// optionally do so in a new thread.
 /// </summary>
 /// <param name="clientSocket"></param>
 /// <param name="asynchronously"></param>
 public ProcessClientRequest(Socket clientSocket)
 {
     m_clientSocket = clientSocket;
     // Spawn a new thread to handle the request.
     new Thread(ProcessRequest).Start();
 }
コード例 #8
0
ファイル: Program.cs プロジェクト: jowadmax/FezPanda
        /// <summary>
        /// This code will create a TCP socket between this DHCP client and a server node on a specific IP and Port.
        /// ServerIP can be modified to point at the correct Server IP
        /// the main also spins off a serialport thread to monitor the serial port for new GPS Data.
        /// </summary>
        public static void Main()
        {
            SoftwareI2C tempS = new SoftwareI2C((Cpu.Pin)FEZ_Pin.Digital.IO66, (Cpu.Pin)FEZ_Pin.Digital.IO65,400);

                byte[] inBuffer = new byte[2];
                byte[] A = new byte[] { 0x03 }; // A command

                tempS.Transmit(true, false, 0x90); //address
                tempS.Transmit(false, false, 0x00); //register num
                tempS.Transmit(true, false, 0x91); //send read address

                inBuffer[0] = tempS.Receive(true, false);
                inBuffer[1] = tempS.Receive(true, true);

            byte[] mac = { 0x00, 0x26, 0x1c, 0x7b, 0x29, 0xE8 };  //The Network board does not come pre installed with a MAC address
            //Please use(http://www.macvendorlookup.com/) to create a Mac address for you device

            WIZnet_W5100.Enable(SPI.SPI_module.SPI1, (Cpu.Pin)FEZ_Pin.Digital.Di10, (Cpu.Pin)FEZ_Pin.Digital.Di7, true);  //initializes the Panda II hardware to to connect to the FEZ Connect
            //NetworkInterface.EnableStaticIP(ip, subnet, gateway,mac); //This can be used to intialize your client connection if you want to hard code in the network configuration instead of using DHCP
            Dhcp.EnableDhcp(mac, "FEZ");  //Intialize FEZ connect using the mac address "FEZ" is the name of the host change this for multiple clients
            Socket mysocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);  //create network socket
            byte[] ServerIp = { 10, 10, 4, 24 }; //change this to your Server IP
            mysocket.SendTimeout = 3000;
            mysocket.Connect(new IPEndPoint(new IPAddress(ServerIp),9090)); //Connect to server using socket

            OutputPort LED = new OutputPort((Cpu.Pin)69, true);
            LED.Write(!LED.Read());
            string message = "hello Mom\n";
            mysocket.Send(Encoding.UTF8.GetBytes(message));
            InterruptPort IntButton = new InterruptPort((Cpu.Pin)FEZ_Pin.Interrupt.IO4,true,Port.ResistorMode.PullUp,Port.InterruptMode.InterruptEdgeLow); //create button interrupt
            IntButton.OnInterrupt+= new NativeEventHandler(IntButton_ONInterrupt);

            int value;

            while (true)
            {
                if (newstring)
                {
                      Debug.Print(datastring);
                      mysocket.Send(Encoding.UTF8.GetBytes(datastring));        //write string to network socket
                      newstring = false;
                      LED.Write(!LED.Read());
                }
                tempS.Transmit(true, false, 0x90); //send I2C Device write address for dummy write
                tempS.Transmit(false, false, 0x00); //Send Register read address
                tempS.Transmit(true, false, 0x91); //send I2C Device Read address

                inBuffer[0] = tempS.Receive(true, false); //Read MSB (bits 11-4)
                inBuffer[1] = tempS.Receive(true, true);  //Read LSB (bits 0-3 left justified)

                value = (int)inBuffer[0]*256 + inBuffer[0]; //combine MSB and LSB
                value = value>>4;                           //Shift value to right by 4 bits to right justify "value" holds the temperature in deg. C with .0625 Deg. Resolution
                value = (int) ((float)value * .0625);       //The "value" variable now holds the temp in degrees C.
                value = (9 * value) / 5 + 32;               //Convert to deg. f

                Debug.Print(value.ToString());              //Print "value" as a string to the debug port
                if (datastring != (value.ToString() + "\n"))
                {
                    datastring = value.ToString() + "\n";
                    newstring = true;
                }
                Thread.Sleep(500);
            }
        }