WIFI RS21 Image transfer

Hi to everyone, i use a Serial Camera L2 and WIFI RS21 modules for transferring captured image form camera to PC.
I use a WebEvent responder.Respond() method to transfer the captured image. I use Raptor (2014 R5 SDK, 4.3.6 firmware).

Here is wifi, camera and WebServer initialization code:



Responder pictoPCResponder; //responder handle
public byte[] capturedata = null;//Image buffer

 void ProgramStarted()
        {           
                InitializeCamera();
                Thread t = new Thread(new ThreadStart(() =>
           {
                InitializeWIFIRS21();
           }));

           t.Start();
                
                this.r_capture_timer = new GT.Timer(1000);
                this.r_capture_timer.Tick+=this.r_capture_timer_Tick;
          
        }

 private void InitializeCamera()
        {
            Debug.Print("Camera Initialization...");
            serialCameraL2.ImageResolution = SerialCameraL2.Resolution.QVGA;
            serialCameraL2.StartStreaming();                 
            Debug.Print("Camera Initialized");
        }

 private void InitializeWIFIRS21()
        {
            WiFiRS9110.NetworkParameters ADHOC_PARAMS = new WiFiRS9110.NetworkParameters();

            ADHOC_PARAMS.Channel = 10;
            ADHOC_PARAMS.Key = KEY;
            ADHOC_PARAMS.Ssid = SSID;
            ADHOC_PARAMS.SecurityMode = WiFiRS9110.SecurityMode.Wep;
            ADHOC_PARAMS.NetworkType = WiFiRS9110.NetworkType.AdHoc;
            

            wifiRS21.NetworkInterface.Open();          

            wifiRS21.NetworkInterface.EnableStaticIP("192.168.0.18", "255.255.255.0", "192.168.0.18");          
          
            wifiRS21.NetworkInterface.StartAdHocNetwork(ADHOC_PARAMS);         
            ipaddress = wifiRS21.NetworkInterface.IPAddress;
            wifiRS21.NetworkDown += wifiRS21_NetworkDown;
            wifiRS21.NetworkUp += wifiRS21_NetworkUp;
            
        }

        void wifiRS21_NetworkUp(GTM.Module.NetworkModule sender, GTM.Module.NetworkModule.NetworkState state)
        {
            Debug.Print("network UP");
            Thread.Sleep(3000);
            RunServer();
            
        }

        void wifiRS21_NetworkDown(GTM.Module.NetworkModule sender, GTM.Module.NetworkModule.NetworkState state)
        {
            Debug.Print("network down");
        }
 public void RunServer()
       {
            WebEvent pictopc = WebServer.SetupWebEvent("pictopc");           
            pictopc.WebEventReceived += pictopc_WebEventReceived;
            WebServer.StartLocalServer(ipaddress, 80);  
            
       }
        
        void pictopc_WebEventReceived(string path, WebServer.HttpMethod method, Responder responder)
        {
            r_capture_timer.Start();
            pictoPCResponder = responder;       
        }

After i send http request from PC, pictopc_WebEventReceived event handler start the timer for image preparation and response to http client:


 void r_capture_timer_Tick(GT.Timer timer)
        {
            Debug.Print("Preparing image");        
           
                if (serialCameraL2.NewImageReady)
                {
                    Debug.Print("Image ready");
                    timer.Stop();        
                    capturedata = serialCameraL2.GetImageData();       
                    if (capturedata != null)
                    {
                    
                       pictoPCResponder.Respond(capturedata, "image/bmp");
                               
                    }
                    else
                    {
                        Debug.Print("Image data is null");
                    }

                }
        
        }

I have the folowing problems:

1)This is the main problem. I could transfer image to PC only when i load in vs 2013 debuger, if i load assemblies in release mode and don’t attach debugger, the image is not transfering.
2) Very very slow serialCameraL2.NewImageReady event. Aprox… 30 seconds up to 1 minute before image is ready.
3) How stable is Ad-Hoc connection between PC and WIFI RS21, can i use it for image transferring purpose?

Does anybody meet the same problem?

Hello Alex,

Did you try to inactivate Firewall and Virus Scanner?

Hi, RoSchmi!!!
Thank you for reply! I don’t have a virus scanner, also my firewall is deactivated.
I really had a more fast and stable transfer with an old RN XV and your brilliant driver. But i have to switch for RS 21 because i need a multiple connections, that RN XV doesn’t support.

I would modify your code like this. Does not solve your Problem but it runs with Debugger and without Debugger


public partial class Program
    {
        private const string Key = "E8430A5EDB";

        private const string SSID = "YourSSID";

        private string ipaddress;

        Responder pictoPCResponder; //responder handle
        public byte[] capturedata = null;//Image buffer
        GT.Timer r_capture_timer;

        GT.Networking.WebEvent defaultEvent;
        GT.Networking.WebEvent pictopc; 


        // This method is run when the mainboard is powered up or reset.   
        void ProgramStarted()
        {
            r_capture_timer = new GT.Timer(1000);
            r_capture_timer.Tick +=r_capture_timer_Tick;

            InitializeCamera();
            WiFiRS9110.NetworkParameters ADHOC_PARAMS = new WiFiRS9110.NetworkParameters();
            ADHOC_PARAMS.Channel = 10;
            ADHOC_PARAMS.Key = Key;
            ADHOC_PARAMS.Ssid = SSID;
            ADHOC_PARAMS.SecurityMode = WiFiRS9110.SecurityMode.Wep;
            ADHOC_PARAMS.NetworkType = WiFiRS9110.NetworkType.AdHoc;
            wifiRS21.NetworkInterface.Open();
            wifiRS21.NetworkInterface.EnableStaticIP("192.168.0.18", "255.255.255.0", "192.168.0.18");
            wifiRS21.NetworkInterface.StartAdHocNetwork(ADHOC_PARAMS);
            ipaddress = wifiRS21.NetworkInterface.IPAddress;
            wifiRS21.NetworkDown += wifiRS21_NetworkDown;
            wifiRS21.NetworkUp += wifiRS21_NetworkUp;
            Debug.Print("Program Started");
        }
        void wifiRS21_NetworkUp(GTM.Module.NetworkModule sender, GTM.Module.NetworkModule.NetworkState state)
        {
            Debug.Print("network UP");
            Thread.Sleep(3000);
            RunServer();
        }

        void wifiRS21_NetworkDown(GTM.Module.NetworkModule sender, GTM.Module.NetworkModule.NetworkState state)
        {
            Debug.Print("network down");
        }
        public void RunServer()
        {
            defaultEvent = WebServer.DefaultEvent;
            pictopc = WebServer.SetupWebEvent("pictopc");
             
            pictopc.WebEventReceived += pictopc_WebEventReceived;
            defaultEvent.WebEventReceived += defaultEvent_WebEventReceived;
            WebServer.StartLocalServer(ipaddress, 80);
        }

        void defaultEvent_WebEventReceived(string path, WebServer.HttpMethod method, Responder responder)
        {
            string requestedURL = path;
            switch (path)
            {
                case "Beautiful.jpg":
                    {
                        // Get the image from the resources in the byte array
                        byte[] document = Resources.GetBytes(Resources.BinaryResources.Beautiful);
                        responder.Respond(document, "images/jpeg");
                    }
                    break;
                default:
                    {
                        string content = "<html><body><h1>Hello, could not be found....</h1></body></html>";
                        byte[] bytes = new System.Text.UTF8Encoding().GetBytes(content);
                        responder.Respond(bytes, "text/html");
                        break;
                    }

            }
            Debug.Print("Default WebEvent received");
        }

        void pictopc_WebEventReceived(string path, WebServer.HttpMethod method, Responder responder)
        {
          //  r_capture_timer.Start();                  //?
          //  pictoPCResponder = responder;   //?
        }



@ Alex Bilityuk -
I did same perliminary tests, may be that starting new threads for the responses does the trick:


void defaultEvent_WebEventReceived(string path, WebServer.HttpMethod method, Responder responder)
        {
            SendResponseInThread mySendResponseInThread = new SendResponseInThread(path, method, responder);

            Debug.Print("Default WebEvent received. Thread: " + Thread.CurrentThread.GetHashCode().ToString());
        }

        class SendResponseInThread
        {
            public SendResponseInThread(string pPath, WebServer.HttpMethod pMethod, Responder pResponder)
            {
                Thread sendThread = new Thread(new ThreadStart(() =>
                {
                    SendResponse(pPath, pMethod, pResponder);
                }));
                sendThread.Start();
            }

            private void SendResponse(string _path, WebServer.HttpMethod _method, Responder _responder)
            {
                switch (_path)
                {
                    case "Beautiful.jpg":
                        {
                            // Get the image from the resources in the byte array
                            byte[] document = Resources.GetBytes(Resources.BinaryResources.Beautiful);
                            _responder.Respond(document, "images/jpeg");
                        }
                        break;
                    case "BigImage.jpg":
                        {
                            // Get the image from the resources in the byte array
                            byte[] document = Resources.GetBytes(Resources.BinaryResources.BigImage);
                            _responder.Respond(document, "images/jpeg");
                        }
                        break;
                    default:
                        {
                            string content = "<html><body><h1>Hello, could not be found....</h1></body></html>";
                            byte[] bytes = new System.Text.UTF8Encoding().GetBytes(content);
                            _responder.Respond(bytes, "text/html");
                        }
                        break;
                }
            }
        }

3 Likes

@ RoSchmi -
Thank you very much for a code sample… wifi module stopped working for unknown reasons, i will try this code as soon as i figure out the wifi problem and let you know the results…

Any luck with this issue? I am getting the same results using a Hydra and SerialCameraL2.
Is 1 frame per minute the expected performance?