Harmonitron
Programmer
I have an industrial weigh scales that makes each weight reading available on a TCP/IP server (or UDP server - I'm not sure of the correct terminology). The following script listens for the data and, in the full version, stores each reading in the database. The script works well until the scales is powered down or there is a break in the network connection, etc.
First, how do I detect if the connection is lost?
Second, what's the best way to restore?
Many thanks,
First, how do I detect if the connection is lost?
Second, what's the best way to restore?
Many thanks,
Code:
'======================================================================
'Language: VBScript can run on Windows WHS
'Use: cscript scriptname.vbs
'======================================================================
'Requires: w3sockets.dll
'Download: [URL unfurl="true"]http://tech.dimac.net/default3.asp?M=FreeDownloads/Menu.asp&P=FreeDownloads/FreeDownloadsstart.asp[/URL]
'Documentation: [URL unfurl="true"]http://www.dimac.net/Products/FreeProducts/w3Sockets/Reference/Refstart.htm[/URL]
'Description ==========================================================
'Opens a TelNet connection to listen to a TCP/IP server.
'Data received is displayed one line at a time.
'======================================================================
telnethost = "192.168.1.5:9000"
'Create the telnet connection.
Dim oSocket, iErr, sSocketText
sSocketText = ""
Set oSocket = CreateObject("Socket.TCP")
oSocket.DoTelnetEmulation = True
oSocket.TelnetEmulation = "TTY"
oSocket.Host = telnethost
oSocket.Open
'Main loop
Do
On Error Resume Next
sSocketText = Trim(oSocket.GetLine)
If Err.Number <> 0 Then
'GetLine times out with error 0x8000FFFF after a minute with no comms.
WScript.Echo Time() & "... waiting for data from server."
End If
If sSocketText > "" Then
WScript.Echo sSocketText
End If
Loop
oSocket.Close 'Script never reaches this line.