【.Net MF網路開發板研究-01】IP地址設定及簡單web示範

來源:互聯網
上載者:User

       早期推出的開發板並不具備網口,所以.NET Micro Framework很多基於網路的功能,便無從研究了,其實在物聯網時代,具備網路功能才是王道。

      新開發板除了具備乙太網路模組以外,還增加了USB Host模組,當然還增加了其它相關介面,詳情請參見:

     

     由於該開發板是基於Cortex-M3核心,MF核心程式(TinyCLR)部署在片內Flash上,但是片內Flash一般容量有限,所以就沒有移植TinyBooter,這樣官方MFDeploy的網路設定功能便無法使用了,因此我在TinyCLR代碼中增加了網路設定的代碼模組,此外同步又升級了YFAccessFlash工具,以方便使用者配置開發板的IP地址等相關參數。

   具體配置方法如下:

 

   單擊菜單【Network Config】進入IP配置介面,如所示:

 

配置成功後,開發板會自動重啟,以使新配置生效。

1、韌體版本必須高於V0.9.05 才支援IP配置

http://www.sky-walker.com.cn/MFRelease/firmware/mfv41_firmware_hy_redbull.rar

2、YFAccessFlash工具必須版本高於V2.0.2.1才支援IP配置

http://www.sky-walker.com.cn/MFRelease/Tools/YFAccessFlash.rar

3、必須用YFAccessFlash部署工具中的ER_Config,否則配置IP時,開發板會出現異常。

請參考:http://www.sky-walker.com.cn/MFRelease/document/MFManual_V2.0.pdf

   該手冊中,有如何部署ER_Config的介紹

 

開發板運行後,我們用PC機,進行ping測試,效果如下:

網路通了,我們進行簡單的編程,來做一個簡單並且比較實用的Web Server。

我們直接在官方SocketServer進行修改,其修改後的代碼如下:

     private void ProcessRequest()

      {

            const Int32 c_microsecondsPerSecond = 1000000;

            // 'using' ensures that the client's socket gets closed.

            using (m_clientSocket)

            {

                // Wait for the client request to start to arrive.

                Byte[] buffer = new Byte[1024];

                if (m_clientSocket.Poll(5 * c_microsecondsPerSecond,

                    SelectMode.SelectRead))

                {

                    // If 0 bytes in buffer, then the connection has been closed,

                    // reset, or terminated.

                    if (m_clientSocket.Available == 0)  return;

                    // Read the first chunk of the request (we don't actually do

                    // anything with it).

                    Int32 bytesRead = m_clientSocket.Receive(buffer,

                        m_clientSocket.Available, SocketFlags.None);

 

                    // Return a static HTML document to the client.

                    String scrHtml = Resource1.GetString(Resource1.StringResources.webpage);

                    string[] scrHtml_lines = scrHtml.Split('\r');

                    string objHtml = "",strTemp="";

 

                    ADC.Start(0); //ADC0

                    ADC.Read(14, out MySocketServer.AD8, 2, 0);

                    ADC.Stop(0);

 

                    MySocketServer.AD7 = MySocketServer.AD8*490/4096;

                    MySocketServer.AD1 += 1;

                    if (MySocketServer.AD1 > 10) MySocketServer.AD1 = 0;

                    foreach (string line in scrHtml_lines)

                    {

                        if (line.Length > 0)

                        {

                            strTemp = line;

                            if (line.IndexOf("AD8%") > 0) strTemp = StringReplace(line, "AD8%", MySocketServer.AD8.ToString());

                            if (line.IndexOf("AD7%") > 0) strTemp = StringReplace(line, "AD7%", MySocketServer.AD7.ToString());

                            if (line.IndexOf("AD1%") > 0) strTemp = StringReplace(line, "AD1%", MySocketServer.AD1.ToString());

                            objHtml += strTemp + "\r";

                        }

                    }

                    m_clientSocket.Send(Encoding.UTF8.GetBytes(objHtml));

                }

            }

        }

在IE瀏覽器中輸入:http://192.168.0.100/ 則顯示如下介面:

選擇 開發板上的類比量輸入按鈕,的進度條會動態變化。

下篇文章,我們將介紹Http Server相關的內容。

 -------------------------------------------------------------------------------------------------------------------------

源碼/文檔:http://www.sky-walker.com.cn/MFRelease/Sample/YFSocketServer.rar

MF論壇:http://space.cnblogs.com/group/MFSoft/

MF開發板:http://item.taobao.com/item.htm?id=7117999726

網路開發板:http://item.taobao.com/item.htm?id=10919470266

QQ群:127465602(已滿) 146524112

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.