Ping a device
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?
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?
0
Comments
Thank you! How do I do it?
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.
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) } } }