Documentation forKiwi CatTools

Example Generic Script

The script below is a more complete framework which you can use as a starting point for your external scripts. This script works in the following way:

  1. Send a command to the device.
  2. Wait until the device finishes the output generated by the command and returns the device prompt.
  3. Parse the stored output from the device and take appropriate action.

Depending on what you need to achieve you may want to add additional mults to the localSendCommandSingle function. By adding matching case statements, you can respond to output from the device not handled by the standard device script.

Option Explicit
' The starting place for the external script is always Function Main.
Function Main(inputString)
	Dim commandResult
	Dim processBufferResult
	Main = ""
	' Call the function to send the command to the device. In this case we are using input string as the command.
	commandResult = localSendCommandSingle(inputString)
	' If the command was processed OK then take action.
	If commandResult Then
		processBufferResult = ProcessBuffer()
		If processBufferResult Then
		' Take action based on the result of processing the buffer
		End If
	End If
End Function
			
Function localSendCommandSingle(CmdToSend)
' This is a simplified version of the send command single activity used in the main CatTools client.
' The idea is that it can be used to handle specific output not catered for by the main script.	
	Dim retval
	Dim Mult(20)
	Dim Choices
	Dim StoredBuffer
	localSendCommandSingle = False
	StoredBuffer = ""
	' Set up Mults - The text returned from the device is checked for any of the mults and
	' if a match is found different actions are taken depending on the mult.
	Mult(1) = "--More--"
	Mult(2) = "Invalid Command"
	' Custom mults can be inserted here
	' Mult(3) = "Device specific mult"
	Mult(18) = cl.DeviceVTYPrompt
	Mult(19) = cl.DeviceEnablePrompt
	Mult(20) = cl.DeviceConfigPrompt
	Choices = 20 'the number of mults
			
	' Clear the buffer
	cl.flushrxbuffer

	' Send the command to the device (but dont press enter yet)
	If cl.WaitForEcho Then
		If cl.SendAndWaitForEcho(CmdToSend) = False Then
			cl.Log 4, "Did not receive echo of " & CmdToSend
			Exit Function
		End If
	Else
		cl.sendData CmdToSend
	End If

	' We dont want to record the command being sent or the echo so clear the buffer ready for a reply from device
	cl.flushrxbuffer

	' Send <cr> to execute the command
	cl.sendData vbCr

	' Process return results
	cl.Log 4, "Waiting for a response to: " & CmdToSend
	Do
		' Wait for a response from the device
		If cl.WaitForTime = 0 Or cl.WaitForTime = "" Then
			' If the user has not specified a WaitForTime
			retval = cl.WaitForMultData(Mult, Choices, cl.RecDataTimeOut * 5)
		Else
			' If the user has specified a WaitForTime
			retval = cl.WaitForMultData(Mult, Choices, cl.WaitForTime)
		End If

		' Store any output from the device
		StoredBuffer = StoredBuffer & cl.RxBuffer

		' Analyze results for the first matching mult found
		Select Case retval
		Case 0
		' No valid data received
			If 2 > 0 Then
				cl.Log 2, "Did not receive expected response to command: " & CmdToSend
			End If
			Exit Do
		Case 1
			' --more-- prompt found so send a cr to get the next block of data
			cl.sendData vbCr
		Case 2
			' Invalid command - error with syntax
			If 2 > 0 Then
				cl.Log 2, "Error with syntax: " & CmdToSend
			End If
			Exit Do
		'Case 3
			' Take action based on the "Device specific mult" found.
			' This may involve sending a command or keystrokes to the device.
			' You may also need to flush the buffer before or after the above by using a cl.FlushRxBuffer command.
			' Note: You may not want to exit the loop at this point because you will want to leave the device ready
			' to receive another command so you should ensure you are at a device prompt when you exit the loop.
		Case 18, 19, 20
			' Prompt found so the device has finished its output so exit the loop.
			localSendCommandSingle = True
			Exit Do
		End Select
	Loop
	' Put the total output of the command in the RxBuffer so that it is available for use elsewhere.
	cl.RxBuffer = StoredBuffer
End Function
			
Function ProcessBuffer()
	' Do what ever processing of the data in cl.RXBuffer you need to here
	ProcessBuffer = True
End Function