A Flash Developer Resource Site

Page 1 of 5 12345 LastLast
Results 1 to 20 of 82

Thread: (AS2) Flash to read\listen to serial port?

  1. #1
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756

    Thumbs up (AS2) Flash to read\listen to serial port?

    Been a while since I messed with some Flash stuff, but have a perfect project for it that I have been kicking around for a while now.

    My question is how can I go about getting a Flash app to listen/read incoming serial data?

    I have a Flash movie embedded into a page, that is being locally hosted on a RaspberryPi device, served up via local LAMP install..

    I have a connected Arduino, that will pass data over to this RPi/Flash app...

    I have never done any sort of socket communication before (that I recall at least).. would this be the solution I need to read up more about?

    I am hoping to NOT have some sort of 'polling' solution, as there is no telling when the connected Arduino will send data..

    In a worst case scenario I migth be able to have the Arduino, send this data to a PHP script... have this PHP script save this data to either a text file or database..

    then have the flash app load this text file or call this php script to query the database.. but that seems kind of 'messy'.. and again.. just random polling.. which would kill resources over time I'm sure..

    Any feedback or suggestions on thing to research is appreciated.

    Thanks!
    -whispers

  2. #2
    Senior Member
    Join Date
    Feb 2005
    Posts
    1,836
    As far as I know, actionscript is not set up to listen at all for socket connections. https://github.com/phax/as2-server is the closest I got to that for as2 and the server side is built in java. Documentation for as3 but could be useful: https://help.adobe.com/en_US/as3/dev...9d1c-8000.html

    While looking up socket networking I realized that networking wasn't the main thing. However, I'm pretty sure the point still stands. I'm pretty sure that saving data and listening for socket connections were never allowed to bypass the web sandboxing.
    .

  3. #3
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    Thank you for the reply..


    Well.. the system/browser and the Flash app are BOTH local.. just using a browser to view it (but again.. still locally)..

    Wonder if exporting to an .exe bypassing any of these security issues? or perhaps not embedding it and directly loading/calling the .swf? (not sure if that would work on machine that doesnt have Flash software installed?)


    This is for an off-line, RPi project.. meaning in the end.. there will be no internet connection or loading of assets from any domain.. just the local LAMP install..

    I have another similar (in respects to communicating from Arduino to RPi, using PHP and AJAX.. thats works fine.. but it is definitely a send/receive type of communication.. not just one side open/listening constantly for any incoming data..) that I am also working on that takes a hosted HTML/CSS/jQuery/PHP form.... sends some data out to a connected Arduino (via PHP and serial comm)...

    Arduino listens for any incoming serial data, ... parsed data.. does whatever action the serial command says.. and responds to a listening PHP.. (that was called/executed from an AJAX snippet in the HTML page).... that in return updates the HTML page/form state

    This works great and without issue...

    However.. trying to avoid a 'polling type solution'..
    And this is an Embeded Flash app.. so one more layer to get the data down to.. (not just the HTML markup level)


    Comments/feedback welcome!

  4. #4
    Client Software Programmer AS3.0's Avatar
    Join Date
    Apr 2011
    Posts
    1,404
    Ok first I have found rp to run an swf the slowest out of all pi's, orange pi one can run boxhead swf game smooth and has hdmi but never comes with a power cable :/

    Even the banana pi zero m2 is the best pi for swf but I always have trouble moving the mouse and keyboard, its best to buy 1 usb for both wireless peripherals.

    Wiring:
    arduino tx - raspberry pis ttyS0 rx pin
    arduino rx - raspberry pis ttyS0 tx pin
    arduino ground - raspberry pi ground

    Login as root in terminal type:
    PHP Code:
    su 
    and enter password if it asks.

    On the rpi terminal logged in as root get the serial socket program:

    PHP Code:
    sudo apt-get udpate
    sudo apt
    -get install socat 
    After socat installs, I run this which is a serial socket port 7777:
    PHP Code:
    socat -----x TCP-LISTEN:7777,reuseaddr,fork FILE:/dev/ttyUSB0,b9600,raw 
    Back to the arduino you can use this script:
    PHP Code:
    void setup() {
    Serial.begin(9600);
      
    Serial.println('1');
    Serial.print('\0');
    Serial.flush();
    delay(500);
    }

    void loop() {

    To send a 1 on port 7777 from the arduino to rpi browser swf, if your socat is running and your swf is listening on port 7777 you should receive a string that says "1"

    And your swf can also reply with the normal as2 socket send procedures, I don't know if you need a script for that as well to read it on arduino, let me know.


    This is from what I remember because I don't want to setup stuff right now, but it should still work.
    Last edited by AS3.0; 01-28-2019 at 10:41 PM.

  5. #5
    Client Software Programmer AS3.0's Avatar
    Join Date
    Apr 2011
    Posts
    1,404
    post #5 for chromium browser install on Linux pi:

    http://board.flashkit.com/board/show...n-FK-Your-view

  6. #6
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    Thank you for the reply..


    Well.. the system/browser and the Flash app are BOTH local.. just using a browser to view it (but again.. still locally)..

    Wonder if exporting to an .exe bypassing any of these security issues? or perhaps not embedding it and directly loading/calling the .swf? (not sure if that would work on machine that doesnt have Flash software installed?)


    This is for an off-line, RPi project.. meaning in the end.. there will be no internet connection or loading of assets from any domain.. just the local LAMP install..

    I have another similar (in respects to communicating from Arduino to RPi, using PHP and AJAX.. thats works fine.. but it is definitely a send/receive type of communication.. not just one side open/listening constantly for any incoming data..) that I am also working on that takes a hosted HTML/CSS/jQuery/PHP form.... sends some data out to a connected Arduino (via PHP and serial comm)...

    Arduino listens for any incoming serial data, ... parsed data.. does whatever action the serial command says.. and responds to a listening PHP.. (that was called/executed from an AJAX snippet in the HTML page).... that in return updates the HTML page/form state

    This works great and without issue...

    However.. trying to avoid a 'polling type solution'..
    And this is an Embeded Flash app.. so one more layer to get the data down to.. (not just the HTML markup level)


    Comments/feedback welcome!


    update:

    my RPi and Chromium install are already complete.. (was like that out of the box w/ flashplayer support on the latest Raspbian OS/distro)

    Also.. my Arduino is connected to the RPi via USB so I'm use that as the serial port

  7. #7
    Client Software Programmer AS3.0's Avatar
    Join Date
    Apr 2011
    Posts
    1,404
    If you look on my site for these words: c++ usb pipe for adobe air 1 file version

    You will see I compiled in c++ a serial socket for windows machines as well so you can communicate swf and arduino through the usb as socket and easier because you have your flash IDE there:
    https://rpguy.weebly.com/

  8. #8
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    If this is for Windows... how does that work/compare to me working with a RPi? (confused, as to what your saying)

    And what is this C++ serial socket? an .exe file? (not gonna use that or go that route... not that it even matters if its for Windows?)


    this:

    Code:
    sudo apt-get install socat
    Looks the most promising out of all of this... but I havent read anything on it yet..

    However.. I didnt see you post anything on the Flash side of things.. on how to READ anything from the socat incoming serial data??

    Is that an incomplete example? or does it just get the data to the RPi level? (that doesnt help much.. as I need to get the data into the embedded flash app level of things)

  9. #9
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    f your socat is running and your swf is listening on port 7777 you should receive a string that says "1"
    Can you expand on this or show an example?



    How does the embedded .swf listen to a specific port? (is this part for the XML socket set-up? I havent never messed with that before.. so that is why I am asking)

    Is this some sort of polling action?

  10. #10
    Client Software Programmer AS3.0's Avatar
    Join Date
    Apr 2011
    Posts
    1,404
    This is not polling, its a tcp socket and its fast,

    socat - is the Linux socket server for usb data

    the .exe I posted is the windows socket server for usb data


    arduino program:
    PHP Code:
    void setup() {
    Serial.begin(9600);
    }

    void loop() {
    Serial.println('1');
    Serial.print('\0');
    Serial.flush();
    delay(500);

    -----------------------------------------------------------------------------------------------------------------------------------------------------
    Linux example:

    Once you have socat installed run this line in the terminal, change ttyUSB0 to the arduinos tty com port name, the arduino ide might give help you write the /dev path to the port and modify the line below

    ok now run this in Linux terminal:
    PHP Code:
    socat -----x TCP-LISTEN:7777,reuseaddr,fork FILE:/dev/ttyUSB0,b9600,raw 
    Now run the swf I sent you on Linux pi browser and open up port 7777 to see the data coming in.
    -----------------------------------------------------------------------------------------------------------------------------------------------------


    windows example using exe I posted + flash as2 socket .fla file in video description:

  11. #11
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    Thank you for clarifying..

    I dont need nor am I looking for a Windows solution (but perhaps others are, just confusing mixing the two right now, as I'm trying to find a Linux based approach currently)

    I cant open your .fla right now..

    I only have CS5 at home... (but CS6 at work, so it'll have to wait.. bummer!)..

    Maybe re-post as CS5 compatible?

    I dont have any questions on the Arduino side of things.. (nor how to send/write serial data)..

    Question: Where does the 4505 BASE number come from? (cant really see the .fla code... but do a little bit at the end, could use some formatting! LOL)

    So where does that socket number base come from?, and why add the COM port number to it? And how does that translate to when things are on the RPi?

    I dont have the Arduino IDE on the RPi.. so cant get a 'port #' like in your demo..


    So I'm a little unclear on the .fla code when it comes to set up for the RPi..


    However.. 'this'

    Code:
    server.onXML = function(data){
    	//do whatever
    }
    seems to be the piece I was looking for!..

  12. #12
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    * is there no way to edit a post anymore? (your own post even?)


    Anyways..

    I missed this line..

    Now run the swf I sent you on Linux pi browser and open up port 7777 to see the data coming in.
    So in the .fla edit the server connect line to be:

    Code:
    server.connect("127.0.0.1", 7777);
    or whatever port# I use in the socat params line here:

    Code:
    socat -d -d -d -d -x TCP-LISTEN:7777,reuseaddr,fork FILE:/dev/ttyACM0,b9600,raw
    * what I recall, havent checked right now, my usb/serial port name was: ttyACM0, updated in line above


    So from beginning to end, for an RPi..

    * once I have SSH'd into my RPi.. (or opened a terminal from within the desktop itself)


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


    Install socat on my RPi:
    Code:
    sudo apt-get install socat

    Configure socat to use a specific device and port#: (in this example it is using port# 7777 and my USB as serial line: ttyACM0)
    Code:
    socat -d -d -d -d -x TCP-LISTEN:7777,reuseaddr,fork FILE:/dev/ttyACM0,b9600,raw
    Arduino example to send out serial data:

    Code:
    void setup() {
        Serial.begin(9600);
      
        Serial.println('1');
        Serial.print('\0');
        Serial.flush();
        delay(500);
    }
    
    void loop() {
        //listen for any incoming serial data to parse 
    }

    Flash example:

    reading incoming data:
    Code:
    server.onXML = function(data){
    	//do whatever
    }
    sending data out:
    Code:
    server.send(stringVar + "\n \r \o");
    I assume the "\n \r \o" is needed for a terminating character? (null byte?)

    Is this is correct and works, I thank you very much Alloy Bacon!

    This was much easier than I was expecting when I first researched this.

    (now I need to get a test rig up and see if it works!!)

    Thanks

    -whispers

  13. #13
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    * is there no way to edit a post anymore? (your own post even?)


    Anyways..

    I missed this line..

    Now run the swf I sent you on Linux pi browser and open up port 7777 to see the data coming in.
    So in the .fla edit the server connect line to be:

    Code:
    server.connect("127.0.0.1", 7777);
    or whatever port# I use in the socat params line here:

    Code:
    socat -d -d -d -d -x TCP-LISTEN:7777,reuseaddr,fork FILE:/dev/ttyACM0,b9600,raw
    * what I recall, havent checked right now, my usb/serial port name was: ttyACM0, updated in line above


    So from beginning to end, for an RPi..

    * once I have SSH'd into my RPi.. (or opened a terminal from within the desktop itself)


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


    Install socat on my RPi:
    Code:
    sudo apt-get install socat

    Configure socat to use a specific device and port#: (in this example it is using port# 7777 and my USB as serial line: ttyACM0)
    Code:
    socat -d -d -d -d -x TCP-LISTEN:7777,reuseaddr,fork FILE:/dev/ttyACM0,b9600,raw
    Arduino example to send out serial data:

    Code:
    void setup() {
        Serial.begin(9600);
      
        Serial.println('1');
        Serial.print('\0');
        Serial.flush();
        delay(500);
    }
    
    void loop() {
        //listen for any incoming serial data to parse 
    }

    Flash example:

    reading incoming data:
    Code:
    server.onXML = function(data){
    	//do whatever
    }
    sending data out:
    Code:
    server.send(stringVar + "\n \r \o");
    I assume the "\n \r \o" is needed for a terminating character? (null byte?)

    If this is correct and works, I thank you very much Alloy Bacon!

    This was much easier than I was expecting when I first researched this.

    (now I need to get a test rig up and see if it works!!)

    Thanks

    -whispers

  14. #14
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    *I see I dup posted! LOL.. too bad I'm not a moderator in this section..

    just wanted to post the code in the .fla example as well so it all stayed together:

    Install socat on my RPi:
    Code:
    sudo apt-get install socat

    Configure socat to use a specific device and port#: (in this example it is using port# 7777 and my USB as serial line: ttyACM0)

    Code:
    socat -d -d -d -d -x TCP-LISTEN:7777,reuseaddr,fork FILE:/dev/ttyACM0,b9600,raw

    Code:
    
    Full Example Code:
    
    
    socket_connect_btn.onRelease=function(){
    	server.close();
    	server.connect("127.0.0.1", 7777); //user port# from socat params on RPi
    }
    
    
    send_btn.onRelease = function(){
    	server.send(stringVar + "\n \r \0");
    }
    
    
    server.onConnect = function(result){
    	if(result){
    		//connected
    	}else{
    		//not connected
    	}
    
    }
    
    server.onClose = function(){
    	//disconnected
    	
    }
    
    
    server.onXML = function(incomingData){
    	//parse incoming data
    	//does it come one character at a time? or a whole string?
    
    	//display to text field
    	someTextField.text += incomingData;
    	
    
    }

  15. #15
    Client Software Programmer AS3.0's Avatar
    Join Date
    Apr 2011
    Posts
    1,404
    nice, yeah it should work once you test it, 45055+com port is how I designed the program to work for windows just like 7777 on Linux I put that number as choice.

    and on Linux for the escape characters "\n \r \0" you might get away without using some of those, I just put them all so you get the message for sure.

    Yeah you set up the socat line correctly,

    //does it come one character at a time? or a whole string?

    You can use whole characters to replace the "1" on arduino but don't remove the flush or nullbyte messages, and you can send messages faster on arduino by reducing the 500ms delay I put.


    but change your arduino program to this, so it keeps sending the 1's:
    PHP Code:
    void setup() {
    Serial.begin(9600);
    }

    void loop() {
    Serial.println('1');
    Serial.print('\0');
    Serial.flush();
    delay(500);

    you can even change "9600" on arduino program and socat line to: 115200 and remove the delay(500); for max read/write speed but it might freeze your pi because that's to fast, you get like thousands of messages per second
    Last edited by AS3.0; 01-31-2019 at 11:11 AM.

  16. #16
    Senior Member whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,756
    Thanks for clarifying..

    Hoping to give it a shot this weekend. once I get some down time to play with my project.

    I dont anticipate sending any data from the Flash side back to the Arduino.. but good to know how to do it.. as well and know about the terminating character.


    I was asking about the incoming string/serial data...

    because on the Arduino side.. you only get one character at a time.. and you need to handle that data usually by having SOP and EOP (start/end of packet) delimiters to know when the packet/data is complete and can start to be parsed..

    I saw this in your code:
    Code:
    data_in.text = num++;
    if(num % 13 == 0){
    	data_field.text = '';
    }
    And was wondering why you had a 'counter' going on?

    ie: The use of the modulo operator in there?

    What are you checking for/against?

  17. #17
    Client Software Programmer AS3.0's Avatar
    Join Date
    Apr 2011
    Posts
    1,404
    "What are you checking for/against? "

    in the video, using modulo helps clear the text field when count is a multiple of 13, so I can keep noticing new messages on the text field when its full.


    example use of arduino sending messages to flash:
    Last edited by AS3.0; 01-31-2019 at 12:01 PM.

  18. #18
    Client Software Programmer AS3.0's Avatar
    Join Date
    Apr 2011
    Posts
    1,404
    example of flash sending messages to arduino:

  19. #19
    Client Software Programmer AS3.0's Avatar
    Join Date
    Apr 2011
    Posts
    1,404
    for browser:

    https://www.macromedia.com/support/d...manager04.html

    add swf file path to the edit locations to pass security issues

  20. #20

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center