通过 JSON 建立 Arduino 和 Flex 4.0 之间的连接

发布于 2024-09-29 17:09:14 字数 1445 浏览 4 评论 0原文

我尝试在 arduino 和 Flex 4.0 之间建立连接,我将 JSON 库和 as3corelib.swc 添加到 Flex 中。当我运行 Flex 文件时,PC 与 arduino 之间的连接正在工作(我可以在 SERPROXY 窗口中看到它),并且在 Flex 窗口中也没有任何问题,我将 Flex 的 SWF 文件添加到 //http 的列表中://www.macromedia.com/support/documentation/tr/flashplayer/help/settings_manager04.html,但是读取结果没有显示在SWF中,我不明白为什么!,感谢您的帮助

,这里是代码

package
{
 import com.adobe.serialization.json.JSON;
 //http://www.macromedia.com/support/documentation/tr/flashplayer/help/settings_manager04.html
 import flash.display.Sprite;
 import flash.errors.*;
 import flash.events.*;
 import flash.net.Socket;
 import flash.text.TextField;


 public class deneme extends Sprite
 {
  private var magnetic:Socket=new Socket("localhost",5331);
  private var magneticValue:Number=0;
  private var distance:Number;
  private var newText:TextField=new TextField();
  private var listText:TextField=new TextField();
  private var MNx:Number;
  private var MNy:Number;
  private var MNz:Number;
  private var d:Object={"x":null, "y":null, "z":null};

  public function deneme()
  {
   socketDataHandler();

  }
  private function socketDataHandler():void
  {
   newText.text=magnetic.readUTFBytes(magnetic.bytesAvailable);

   d= JSON.decode(newText.text);
   MNx=d["x"];
   MNy=d["y"];
   MNz=d["z"];

   listText.x=10;
   listText.y=10;
   listText.width=600;
   listText.height=100;
   listText.text=newText.text;
   addChild(newText); 
  }      
        }
    }

I try to make a connection between arduino and Flex 4.0, I added the JSON lib and also as3corelib.swc to Flex. When I run the Flex file the connection between PC to arduino is working (I can see it in SERPROXY window) and also I don't have any problems in Flex window, I added the SWF file of Flex to the list at //http://www.macromedia.com/support/documentation/tr/flashplayer/help/settings_manager04.html, Bu the reading result is not shows in the SWF, I couldn't understand why !, thanks for help

and here the code

package
{
 import com.adobe.serialization.json.JSON;
 //http://www.macromedia.com/support/documentation/tr/flashplayer/help/settings_manager04.html
 import flash.display.Sprite;
 import flash.errors.*;
 import flash.events.*;
 import flash.net.Socket;
 import flash.text.TextField;


 public class deneme extends Sprite
 {
  private var magnetic:Socket=new Socket("localhost",5331);
  private var magneticValue:Number=0;
  private var distance:Number;
  private var newText:TextField=new TextField();
  private var listText:TextField=new TextField();
  private var MNx:Number;
  private var MNy:Number;
  private var MNz:Number;
  private var d:Object={"x":null, "y":null, "z":null};

  public function deneme()
  {
   socketDataHandler();

  }
  private function socketDataHandler():void
  {
   newText.text=magnetic.readUTFBytes(magnetic.bytesAvailable);

   d= JSON.decode(newText.text);
   MNx=d["x"];
   MNy=d["y"];
   MNz=d["z"];

   listText.x=10;
   listText.y=10;
   listText.width=600;
   listText.height=100;
   listText.text=newText.text;
   addChild(newText); 
  }      
        }
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

奶气 2024-10-06 17:09:14
package
{   import com.adobe.serialization.json.JSON;

import flash.display.Sprite;
import flash.errors.*;
import flash.events.*;
import flash.net.Socket;
import flash.text.TextField;
import mx.rpc.events.ResultEvent;


    public class deneme2 extends Sprite
    {    
        private var newText:TextField=new TextField();
        private var listText:TextField=new TextField();
        private var magnetic:Socket=new Socket("localhost",5331);
        private var MNx:Number;
        private var MNy:Number;
        private var MNz:Number;
        private var d:Object={"x":null, "y":null, "z":null};


        public function deneme2()
        {

            magnetic.addEventListener(ProgressEvent.SOCKET_DATA,getDATA); 

        }

        private function getDATA(event:ProgressEvent):void
        {
            newText.text=magnetic.readUTFBytes(magnetic.bytesAvailable);
            d= JSON.decode(newText.text);
            MNx=d["x"];
            MNy=d["y"];
            MNz=d["z"];

            listText.x=10;
            listText.y=10;
            listText.width=600;
            listText.height=100;
            listText.text="X="+String(MNx)+" Y="+String(MNy)+" Z="+String(MNz);

            addChild(listText);
        }
    }


}
package
{   import com.adobe.serialization.json.JSON;

import flash.display.Sprite;
import flash.errors.*;
import flash.events.*;
import flash.net.Socket;
import flash.text.TextField;
import mx.rpc.events.ResultEvent;


    public class deneme2 extends Sprite
    {    
        private var newText:TextField=new TextField();
        private var listText:TextField=new TextField();
        private var magnetic:Socket=new Socket("localhost",5331);
        private var MNx:Number;
        private var MNy:Number;
        private var MNz:Number;
        private var d:Object={"x":null, "y":null, "z":null};


        public function deneme2()
        {

            magnetic.addEventListener(ProgressEvent.SOCKET_DATA,getDATA); 

        }

        private function getDATA(event:ProgressEvent):void
        {
            newText.text=magnetic.readUTFBytes(magnetic.bytesAvailable);
            d= JSON.decode(newText.text);
            MNx=d["x"];
            MNy=d["y"];
            MNz=d["z"];

            listText.x=10;
            listText.y=10;
            listText.width=600;
            listText.height=100;
            listText.text="X="+String(MNx)+" Y="+String(MNy)+" Z="+String(MNz);

            addChild(listText);
        }
    }


}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文