Ping a device

depsdeps Junior MemberPosts: 27
I need to know online\offline status of a SAT tuner by Ethernet. There is no standart command like a PING in Netlinx, so I'm using
IP_CLIENT_OPEN command and looking at error I'm receiving: if it is 6 - Connection refused - device is Online, if another - Offline. It works correctly few days, and then becomes unstable. May be too much tryings to open connection.
Maybe somebody knows another ways to ping?

Comments

  • JasonSJasonS If I had known it was going to be that kind of party... Posts: 228
    It is not ideal, but you can have the AMX master telnet into itself and send the ping command to your device. I just tried it on my master running 4.1.400 firmware, and the ping responds much faster than it used to. You don't need to send the "msg on" command after you connect.
    Welcome to NetLinx v4.1.400 Copyright AMX LLC 2012
    >ping 8.8.8.8
    8.8.8.8 is alive.
    >ping 8.1.1.1
    8.1.1.1 did not respond.
    
  • depsdeps Junior Member Posts: 27
    JasonS wrote: »
    It is not ideal, but you can have the AMX master telnet into itself and send the ping command to your device.
    [/code]

    Thank you! How do I do it?
  • JasonSJasonS If I had known it was going to be that kind of party... Posts: 228
    Here is some very basic code off the top of my head to give you an idea...
    DEFINE_DEVICE
    
        LocalPort = 0:4:0 //Local IP Port
    
    DEFINE_FUNCTION Ping()
    {
        IP_CLIENT_OPEN(LocalPort.Port, '127.0.0.1', 23, IP_TCP)
    }
    
    DATA_EVENT [LocalPort]
    {
        ONLINE:
        {
            SEND_STRING LocalPort, "'ping 8.8.8.8', $0D"
        }
        STRING:
        {
            IF (FIND_STRING(Data.Text, 'is alive', 1))
            {
                //Success
            }
            ELSE IF (FIND_STRING(Data.Text, 'did not respond', 1)) 
            {
                //Fail
            }
            IP_CLIENT_CLOSE(LocalPort.Port)
        }
    }
    

    You will want to add more code for error trapping, port connection status, etc.
  • JasonSJasonS If I had known it was going to be that kind of party... Posts: 228
    Oops, I forgot to catch the login banner. You will want to make sure you don't close the port when you receive the "Welcome to NetLinx " message. Try this...
    DEFINE_DEVICE
    
        LocalPort = 0:4:0 //Local IP Port
    
    DEFINE_FUNCTION Ping()
    {
        IP_CLIENT_OPEN(LocalPort.Port, '127.0.0.1', 23, IP_TCP)
    }
    
    DATA_EVENT [LocalPort]
    {
        STRING:
        {
            IF  (FIND_STRING(Data.Text, 'Welcome to NetLinx', 1))
            {
                SEND_STRING LocalPort, "'ping 8.8.8.8', $0D"
            }
            ELSE 
            {
                IF (FIND_STRING(Data.Text, 'is alive', 1))
                {
                    //Success
                }
                ELSE IF (FIND_STRING(Data.Text, 'did not respond', 1)) 
                {
                    //Fail
                }
                IP_CLIENT_CLOSE(LocalPort.Port)
            }
        }
    }
    
  • depsdeps Junior Member Posts: 27
    Thank you, I'll try it!
Sign In or Register to comment.