how to listen serial.print with flash ?

Hey,

I begin with Arduino and I search to send varible value with arduino to Proxy (serial.print ??) and, after, read this value with Flash

(In my project, I send orders to Arduino with Flash and, sometimes the connection is refused by the proxy. I want to re-send order if the value in Arduino isn't good...)

If you have a little example ...? please !

You may need to re-phrase your post. Its not clear what you are asking.

Do you use an ethernet shield? Or serial communication?

flash is typically what is known as the program memory on the Arduino. Are you talking about the PC software?

If so, you can try and code your app to resend if it doesn't receive a response in a certain time. You will also have to make sure the Arduino can send a response with every request it receives.

Adobe Flash player, either standalone or as a browser plugin does not have access to the serial port.

Flash can access network connections, so you would need to run some sort of network to serial bridge server on the computer to which the Arduino was connected.

I've not personally tried it, but this link is supposed to be the software to do it that way http://download.berlios.de/arduino/serproxy-0.1.3-3.bin.win32.zip

See http://www.sencha.com/forum/showthread.php?36825-Can-Adobe-AIR-accessing-serial-port

Alternatively, you could package your Flash program as Adobe AIR, and use an AIR Native Extension See https://forums.adobe.com/message/3987536

Specifically http://code.google.com/p/as3-arduino-connector/

Also as noted on that forum, packagers like MDM Zinc may also have the functionality you want

Sorry, I m french and my english…

I use the serial communication. with serproxy for the link between Flash (the software!) and arduino.
The program is to run a engine

My problem : sometimes the connection is refused !
I’ve think to code my app to resend if it doesn’t receive a response (thanks pYro !) but I don’t know how to make that !!

In Arduino :

#include <Servo.h>

int demarre;
int pinI1=8;//define I1 interface
int pinI2=11;//define I2 interface 
int speedpinA=9;//enable motor A
int spead =60;//define the spead of motor

void setup()
{
  pinMode(pinI1,OUTPUT);
  pinMode(pinI2,OUTPUT);
  pinMode(speedpinA,OUTPUT);
  Serial.begin(57600);
}

void loop()
{    
     if(Serial.available() >0)
  {
    demarre = Serial.read();
    if (demarre == 'E')
    {
     analogWrite(speedpinA,spead);//input a simulation value to set the speed
     digitalWrite(pinI2,HIGH);//horaire
     digitalWrite(pinI1,LOW);
     
    }else{
      if (demarre == 'C')
      {
       digitalWrite(speedpinA,LOW);   
      }
    }
  }
}

In Flash :

import flash.display.Sprite;
import flash.net.Socket;
import flash.events.MouseEvent;

var _socket:Socket;
var _proxyAddress:String = "127.0.0.1";
var _proxyPort:uint = 5331;

_socket = new Socket();

function onClic1(pEvt:Event):void
{	                    

    _socket.connect(_proxyAddress, _proxyPort);	
    var ENDOF_1:String = "E";	
	trace ("Droite");	
	_socket.writeUTFBytes(ENDOF_1);//send this string value to arduino
	_socket.flush();
}

function onClic2(pEvt:Event):void
{	                    

    _socket.connect(_proxyAddress, _proxyPort);	
    var ENDOF_2:String = "C";	
	trace ("Gauche");	
	_socket.writeUTFBytes(ENDOF_2);//send this string value to arduino
	_socket.flush();
}

function onClicStop(pEvt:Event):void
{                  

    _socket.connect(_proxyAddress, _proxyPort);	
    var ENDOF_S:String = "S";	
	trace ("stop");	
	_socket.writeUTFBytes(ENDOF_S);//send this string value to arduino
	_socket.flush();
}

btn1.addEventListener(MouseEvent.CLICK, onClic1);
btn2.addEventListener(MouseEvent.CLICK, onClic2);
btnStop.addEventListener(MouseEvent.CLICK, onClicStop);

in serproxy :

# Transform newlines coming from the serial port into nils
# if using Flash AS2 or AS1 : true
# if using Flash AS3 : false
newlines_to_nils=false

comm_baud=57600
comm_databits=8
comm_stopbits=1
comm_parity=none

# Idle time out in seconds
timeout=300

comm_ports=3
net_port3=5331

This does not seem to be an Arduino issue.

sometimes the connection is refused !

It sounds like the problem is with the serial proxy server

I suspect it is not closing the connection or you have the Arduino IDE also connecting to the same port.

I have never used that software so I can't be of more help

I've more informations ! I've make code to listen the problem and flash return this :

ArgumentError: Error #1063: Non-correspondance du nombre d'arguments sur Boutonallumermoteur1cs5_fla::MainTimeline/handleDisconnect(). 0 prévu(s), 1 détecté(s).

help me pleeeeeeeeeeeeeeease !!!

Your code is not very good

Why dont you just create a socket and leave it open, then just send the data whenever there is a click event

But with your current code I suspect the problem is you never close() the socket after each transfer

Looking at Adobe's docs on the socket class, flush() doesn't close, (And I would not expect it to close the connection)

BTW. The most interesting part of this is the serial proxy server

Which I actually located here

http://sourceforge.net/projects/arduino.berlios/files/serproxy-0.1.3-3.bin.win32.zip/download

which takes the serial data and redirects it as a tcp port - which could be handy for other things, I wonder if it would be possible to upload a sketch to a Arduino with a wifi to serial module attached to the serial lines (albeit it won't do the hardware reset normally triggered duing the upload)

Thanks rogerClark !!!

I suspect the same think as you ! the close() ! but I have 2 problems : - I m a beginner in AS3 , I true to add the close function but I can't do ..... :blush: - English isn't my language and I understand half of the advice on the english forums !!

Please, can you write me a close function because my : _socket.close(); don't work !

I doubt that socket.close() is not working, its probably a bug in your code.

BTW. Best practice is not put your code on the timeline

Make a class for your main flash document and put the code inside the class

BTW. If you are using a PC, download FlashDevelop it will make your flash coding easier