Page 1 of 3 123 LastLast
Results 1 to 10 of 24
  1. #1
    Just muddling through...


    John UK's Avatar
    Join Date
    May 2012
    Location
    United Kingdom
    Posts
    25
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Detecting Link2_FS is connected.

    Hi.

    Is there a way to use code on an Arduino to detect that Link2_FS is connected to it?

    I have a board that has several switches and LEDs on it, one of which I want to use to indicate that Link2_FS is connected to it such that when I connect Link2_fs to the com port for the board the LED comes on and when I disconnect it, the LED goes out.

    I have had some luck with using;

    if(serial) ..... but this causes the LED to flash, presumably in time with the refresh time.

    I don't even know if I am looking at this in the right way if the truth be told.

    Any help would be great!

    J.

  2. #2
    150+ Forum Groupie BuzziBi's Avatar
    Join Date
    Mar 2013
    Location
    Norway
    Posts
    275
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Detecting Link2_FS is connected.

    For Link2fs to begin communicating with the simulator (through Arduino), you need the code to send or return something.
    If the code does not ask for information or send any, you do not get any information.
    But I guess this is the purpose with you using Link2fs, to send and receive information to / from the simulator (through Arduino).
    And when you start the simulator, you can simply ask for ie. compass heading.
    When (if) the compass heading is returned to Link2fs, you can command a led to light up.
    If there is no communication, the led will not light up.
    Life was hard, but then came Windows 7.
    Now we can fly! --------
    --------

  3. #3
    Just muddling through...


    John UK's Avatar
    Join Date
    May 2012
    Location
    United Kingdom
    Posts
    25
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Detecting Link2_FS is connected.

    Quote Originally Posted by BuzziBi View Post
    ... you can simply ask for ie. compass heading.
    ...
    Thanks, that sounds like it would do what I want. However I cant see how to do it!

  4. #4
    150+ Forum Groupie BuzziBi's Avatar
    Join Date
    Mar 2013
    Location
    Norway
    Posts
    275
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Detecting Link2_FS is connected.

    [QUOTEHowever I cant see how to do it![/QUOTE]
    I tested this, and it seams to work.
    The Led lights up when the connection is established
    Code:
    int CodeIn;// used on all serial reads
    
    String Heading;
    int Headingi;
    int connection = 13; // The led to check connection.  
    void setup() 
    {
      pinMode(connection, OUTPUT);
      
     Serial.begin(115200);   
    }
    
    
    void loop() {
      if (Serial.available()) {
        CodeIn = getChar();
        if (CodeIn == '<') {LESSTHAN();}// The first identifier is "<"
      }
    }
    
    
    char getChar()// Get a character from the serial buffer
    {
      while(Serial.available() == 0);// wait for data
      return((char)Serial.read());// Thanks Doug
    }
    
    
    void LESSTHAN(){    // The first identifier was "<"
    CodeIn = getChar(); // Get another character
      switch(CodeIn) {// Now lets find what to do with it
        case 'J'://Found the second identifier "Heading"
          Heading = "";
          Heading += getChar();
          Heading += getChar();
          Heading += getChar();
          Headingi = Heading.toInt(); // convert it to an integer (Thanks Phill)*/
          if (Headingi > 000 ){digitalWrite(13, HIGH);}else{digitalWrite(13, LOW);} 
        break;     
      }   
    }
    Life was hard, but then came Windows 7.
    Now we can fly! --------
    --------

  5. Thanks John UK thanked for this post
  6. #5
    Just muddling through...


    John UK's Avatar
    Join Date
    May 2012
    Location
    United Kingdom
    Posts
    25
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Detecting Link2_FS is connected.

    Quote Originally Posted by BuzziBi View Post
    [QUOTEHowever I cant see how to do it!
    I tested this, and it seams to work.
    The Led lights up when the connection is established
    [/QUOTE]

    Thanks this works just fine for switching on the light. However it stays on when Link2_FS is disconnected.

    I guess the way to do this would be to understand the wait time for the data refresh and to put the light out if no data is received in time.

    I have the the refresh time set to 5 seconds so I guess I would have to wait 6 seconds before switching off the light. Any ideas?

  7. #6
    75+ Posting Member



    Join Date
    Sep 2013
    Location
    California, USA
    Posts
    109
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Detecting Link2_FS is connected.

    How about extracting "Local FSX time" periodically and comparing the time with the last extraction. If it doesn't update, you are not connected.

  8. #7
    150+ Forum Groupie BuzziBi's Avatar
    Join Date
    Mar 2013
    Location
    Norway
    Posts
    275
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Detecting Link2_FS is connected.

    I was thinking of a way to flush the Serial (RX) after "digitalWrite(13, HIGH)"
    But have not found the solution yet!
    Life was hard, but then came Windows 7.
    Now we can fly! --------
    --------

  9. #8
    Just muddling through...


    John UK's Avatar
    Join Date
    May 2012
    Location
    United Kingdom
    Posts
    25
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Detecting Link2_FS is connected.

    Quote Originally Posted by SteveL View Post
    How about extracting "Local FSX time" periodically and comparing the time with the last extraction. If it doesn't update, you are not connected.
    I tried Var1 = millis() and then in the code buzzibee posted for using the lessthan J a second Variable Var2=millis().
    I then compared:- if (Var1 > Var2){switch off led} thinking that Var1 would always be less than var2 as it was assigned first in the loop until there was no response from the lessthen J.
    I couldn't get it to work but then I am new to this.

  10. #9
    150+ Forum Groupie BuzziBi's Avatar
    Join Date
    Mar 2013
    Location
    Norway
    Posts
    275
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Detecting Link2_FS is connected.

    Having spent all day trying to find out about this (one have to be a bit insane!)
    Even posted a question at the Arduino Forum: Can we get a led to light by serial communication? The answer(so far): You can not! due da...da....da...
    Or it will light up, but will not go off bacause the lack of connection, causes the arduino to just wait for next serial event. And as serial flush only flush the TX buffer, the RX that turned the LED on, still is in the buffer. (As I understand it!)
    I finally figured a way to at least register serial communication.
    You can flash led each time the Link2fs update.
    In the test I use 5 sec refresh time on the Link2fs and make the led light up for half a sec.
    (The delay(500).
    This works. The led goes on when receiving the Heading, stays on for half a sec and goes off, and repeats for as long as you are connecte to Link2fs.
    If you disconnect the Link2fs, the Heading will not be received and the light will stay off.

    SteveLs suggestion to use the "Local FSX time" , did not work for me bacause the Link2fs does not receive this if FSX is paused, and this made it cind of hard to find a way to create a code.

    Code:
    int CodeIn;// used on all serial reads
    
    String Heading;
    int Headingi;
    int connection = 13; // The led to check connection.
    
    void setup() 
    {
      pinMode(connection, OUTPUT);
      
     Serial.begin(115200);   
    }
    
    void loop() {
      if (Serial.available()) {
        CodeIn = getChar();
        if (CodeIn == '<') {LESSTHAN();}// The first identifier is "<"
      }
    }
    
    char getChar()// Get a character from the serial buffer
    {
      while(Serial.available() == 0);// wait for data
      return((char)Serial.read());// Thanks Doug
    }
    
    void LESSTHAN(){    // The first identifier was "<"
    CodeIn = getChar(); // Get another character
      switch(CodeIn) {// Now lets find what to do with it
        case 'J'://Found the second identifier "Heading"
          Heading = "";
          Heading += getChar();
          Heading += getChar();
          Heading += getChar();
          Headingi = Heading.toInt(); // convert it to an integer (Thanks Phill)*/
          
         if (Headingi > 000 )digitalWrite(connection, HIGH);
         delay(500);
       digitalWrite(connection, LOW); 
        break;     
      }   
    }
    If anyone finds another solution to this problem, I will be really disappointed in myself
    Life was hard, but then came Windows 7.
    Now we can fly! --------
    --------

  11. #10
    75+ Posting Member



    Join Date
    Sep 2013
    Location
    California, USA
    Posts
    109
    Contribute If you enjoy reading the
    content here, click the below
    image to support MyCockpit site.
    Click Here To Contribute To Our Site

    Re: Detecting Link2_FS is connected.

    Hi BuzziBi. Here's the way I think it would work:
    1. Save the last Local FSX time in the Arduino as "OLD TIME"
    2. When you read the next data request, if Link2fs is connected it will return a new time which is greater than the old time. record this as "NEW TIME"
    3. If no data is retrieved (Link2fs not connected), the time will not update. NEW TIME will not change.
    4. Test:
    if NEW TIME = OLD TIME, there is no connection. Turn lamp off.
    if NEW TIME > OLD TIME, there is a connection. Turn lamp on.
    5. Copy NEW TIME to OLD TIME
    6. Repeat.
    Steve

Page 1 of 3 123 LastLast