私はまだAS3に苦労していますが、できるだけ覚えています。私はソケットクラスを使用してシリアルポートに変数を送ることができる小さなサンプルのフラッシュアプリケーションを作成しようとしています。私は宿題をしましたが、フラッシュはCOMやUSBのようなシリアルポートでデータを送信できないことを知っています。これを行うには、Flashからの送信データを受信して希望のポートに送信するプログラムを使用する必要があります。そのようなプロセスの最善の例はArduinoのウェブサイトで説明されています。 そこから、私がダウンロードしてWin7マシンにインストールしたserproxyを使用するのが最善の方法であることを知りました。私はこの問題のためのさまざまなチュートリアルを見て、私は私が欲しいものを正確に行うと思っていたフラアプリケーションを組みました。残念ながら問題は、アプリケーションがserproxyに接続していても、私はデータを送信できないということです。AS3ソケットクラスのserproxyとの接続とデータ送信
考えてみると、USBまたはCOMポートを介してローカルに接続された簡単なデバイスを制御できるということです。
私は、ポート5331を使ってserproxy上のローカルホストへの接続を確立して閉じることができるボタンを作成しました。ソケット、文字列、整数で2種類のデータを送信するボタンも作成しました。残念ながら、いずれもCOMポートに到達していません。私はserproxyの設定ファイルをチェックして、それが正しく設定されているので、最後のオプションは私がAS3で何かを台無しにするかもしれないということです。 関連があるかどうかわかりませんが、フラッシュプレーヤーとAIR 2.6でこれを確認していましたが、助けにはなりませんでした。
この全体のスクリプトで何が間違っているかを教えてくれる良い魂があるなら、本当に助けてもらえますか? ところで、フラッシュ映画の最初のフレームにスクリプトを載せて申し訳ありません - これは私が現時点で働いている方法です - 適切な方法を学ぶ時間はありませんでしたが、すぐにそれをしたいです。
も私のzip形式のFLAファイル from hereをダウンロードすることがより明確に前年比については
そして、これはあなたがまた、2つのプログラムが実行されているとのjpgのをダウンロードすることができ
import flash.display.Sprite
import flash.net.Socket
import flash.utils.*
import flash.events.*;
const PORT:Number = 5331
const LOCALHOST:String = "127.0.0.1"
var socket:Socket = null
socket = new Socket();
mess.text = "Click to open/close connection"
notext.text = "0"
onOffbtn.gotoAndStop(1)
var socketStatus:Boolean = false
onOffbtn.addEventListener(MouseEvent.MOUSE_DOWN, onOffbtnSocket)
function onOffbtnSocket(e:MouseEvent):void{
if(socketStatus){
socket.close()
socketStatus = false
onOffbtn.gotoAndStop(1)
trace("_Connection with Serproxy has been closed")
mess.text = "_Connection with Serproxy has been closed"
}else{
socket.connect(LOCALHOST, PORT)
socketStatus = true
onOffbtn.gotoAndStop(2)
}
}
socket.addEventListener(IOErrorEvent.IO_ERROR,errorHandler)
socket.addEventListener(Event.CONNECT, doSocketConnect)
socket.addEventListener(Event.CLOSE, doSocketClose)
socket.addEventListener(Event.COMPLETE, onReady);
function onReady(e:Event):void
{
trace("bytes has been send")
}
function errorHandler(errorEvent:IOErrorEvent):void {
trace("- "+errorEvent.text);
trace("- Did you start the Serproxy program ?");
mess.text = "! " + errorEvent.text + " \n! Please start the Serproxy program first"
onOffbtn.gotoAndStop(1)
}
function doSocketConnect(event:Event):void {
trace("- Connection with Serproxy established.")
mess.text = "_Connection with Serproxy established. \nTry to send data."
}
function doSocketClose(event:Event):void {
trace("_Connection with Serproxy has been closed")
mess.text = "_Connection with Serproxy has been closed"
}
function onResponse(e:ProgressEvent):void{
//var str:String = socket.readUTFBytes(bytesAvailable);
//trace(str);
}
btn1.addEventListener(MouseEvent.MOUSE_DOWN, dobtn1)
btn2.addEventListener(MouseEvent.MOUSE_DOWN, dobtn2)
btn3.addEventListener(MouseEvent.MOUSE_DOWN, dobtn3)
btn4.addEventListener(MouseEvent.MOUSE_DOWN, dobtn4)
btn5.addEventListener(MouseEvent.MOUSE_DOWN, dobtn5)
function dobtn1(event:MouseEvent):void {
socket.writeInt(1)
notext.text = "1"
}
function dobtn2(event:MouseEvent):void {
socket.writeInt(2)
notext.text = "2"
}
function dobtn3(event:MouseEvent):void {
socket.writeInt(3)
notext.text = "3"
}
function dobtn4(event:MouseEvent):void {
socket.writeInt(4)
notext.text = "4"
}
function dobtn5(event:MouseEvent):void {
socket.writeInt(5)
notext.text = "5"
}
btnA.addEventListener(MouseEvent.MOUSE_DOWN, dobtnA)
btnB.addEventListener(MouseEvent.MOUSE_DOWN, dobtnB)
btnC.addEventListener(MouseEvent.MOUSE_DOWN, dobtnC)
btnD.addEventListener(MouseEvent.MOUSE_DOWN, dobtnD)
btnE.addEventListener(MouseEvent.MOUSE_DOWN, dobtnE)
function dobtnA(event:MouseEvent):void {
socket.writeUTFBytes("This is a test for A")
notext.text = "A"
}
function dobtnB(event:MouseEvent):void {
socket.writeUTFBytes("This is a test for B")
notext.text = "B"
}
function dobtnC(event:MouseEvent):void {
socket.writeUTFBytes("This is a test for C")
notext.text = "C"
}
function dobtnD(event:MouseEvent):void {
socket.writeUTFBytes("This is a test for D")
notext.text = "D"
}
function dobtnE(event:MouseEvent):void {
socket.writeUTFBytes("This is a test for E")
notext.text = "E"
}
(FLA内枠に書かれた)私のコードですconnected
事前にお寄せいただきありがとうございます。
The_asManのおかげで私が欲しいのと同じように動作する更新されたコードがあります。
import flash.display.Sprite
import flash.net.Socket
import flash.utils.*
import flash.events.*;
const PORT:Number = 5331
const LOCALHOST:String = "127.0.0.1"
var socket:Socket = null
socket = new Socket();
mess.text = "Click to open/close connection"
notext.text = "0"
onOffbtn.gotoAndStop(1)
var socketStatus:Boolean = false
onOffbtn.addEventListener(MouseEvent.MOUSE_DOWN, onOffbtnSocket)
function onOffbtnSocket(e:MouseEvent):void{
if(socketStatus){
socket.close()
socketStatus = false
onOffbtn.gotoAndStop(1)
trace("_Connection with Serproxy has been closed")
mess.text = "_Connection with Serproxy has been closed"
}else{
socket.connect(LOCALHOST, PORT)
socketStatus = true
onOffbtn.gotoAndStop(2)
}
}
socket.addEventListener(IOErrorEvent.IO_ERROR,errorHandler)
socket.addEventListener(Event.CONNECT, doSocketConnect)
socket.addEventListener(Event.CLOSE, doSocketClose)
socket.addEventListener(Event.COMPLETE, onReady);
function onReady(e:Event):void
{
trace("bytes has been send")
}
function errorHandler(errorEvent:IOErrorEvent):void {
trace("- "+errorEvent.text);
trace("- Did you start the Serproxy program ?");
mess.text = "! " + errorEvent.text + " \n! Please start the Serproxy program first"
onOffbtn.gotoAndStop(1)
}
function doSocketConnect(event:Event):void {
trace("- Connection with Serproxy established.")
mess.text = "_Connection with Serproxy established. \nTry to send data."
}
function doSocketClose(event:Event):void {
trace("_Connection with Serproxy has been closed")
mess.text = "_Connection with Serproxy has been closed"
onOffbtn.gotoAndStop(1)
notext.text = "0"
}
function onResponse(e:ProgressEvent):void{
//var str:String = socket.readUTFBytes(bytesAvailable);
//trace(str);
}
btn1.addEventListener(MouseEvent.MOUSE_DOWN, dobtn1)
btn2.addEventListener(MouseEvent.MOUSE_DOWN, dobtn2)
btn3.addEventListener(MouseEvent.MOUSE_DOWN, dobtn3)
btn4.addEventListener(MouseEvent.MOUSE_DOWN, dobtn4)
btn5.addEventListener(MouseEvent.MOUSE_DOWN, dobtn5)
function dobtn1(event:MouseEvent):void {
socket.writeInt(1)
socket.flush()
notext.text = "1"
}
function dobtn2(event:MouseEvent):void {
socket.writeInt(2)
socket.flush()
notext.text = "2"
}
function dobtn3(event:MouseEvent):void {
socket.writeInt(3)
socket.flush()
notext.text = "3"
}
function dobtn4(event:MouseEvent):void {
socket.writeInt(4)
socket.flush()
notext.text = "4"
}
function dobtn5(event:MouseEvent):void {
socket.writeInt(5)
socket.flush()
notext.text = "5"
}
btnA.addEventListener(MouseEvent.MOUSE_DOWN, dobtnA)
btnB.addEventListener(MouseEvent.MOUSE_DOWN, dobtnB)
btnC.addEventListener(MouseEvent.MOUSE_DOWN, dobtnC)
btnD.addEventListener(MouseEvent.MOUSE_DOWN, dobtnD)
btnE.addEventListener(MouseEvent.MOUSE_DOWN, dobtnE)
function dobtnA(event:MouseEvent):void {
socket.writeUTFBytes("This is a test for A" + String.fromCharCode(0))
socket.flush()
notext.text = "A"
}
function dobtnB(event:MouseEvent):void {
socket.writeUTFBytes("This is a test for B" + String.fromCharCode(0))
socket.flush()
notext.text = "B"
}
function dobtnC(event:MouseEvent):void {
socket.writeUTFBytes("This is a test for C" + String.fromCharCode(0))
socket.flush()
notext.text = "C"
}
function dobtnD(event:MouseEvent):void {
socket.writeUTFBytes("This is a test for D" + String.fromCharCode(0))
socket.flush()
notext.text = "D"
}
function dobtnE(event:MouseEvent):void {
socket.writeUTFBytes("This is a test for E" + String.fromCharCode(0))
socket.flush()
notext.text = "E"
}
あなたのご意見ありがとうございますThe_asMan提案したとおりにスクリプトを更新し、テストして、それが私に役立つかどうかをお知らせします。 –
私はwvxvwで提案されているように、コードを変更してWiresharkでテストしました。だから私はフラッシュコマンドが重要だったと思う。私は他のコマンドが何をしているのか正確にはわからない、String.fromCharCode(0)、しかし私はそれが同様に役立つと推測する。あなたの助けをもう一度ありがとう! –
書き込みコマンドは基本的にバッファに書き込んでおり、flushコマンドはサーバにバッファデータを送信するのと同じです –