Sub Main ' 06jun16 See http://neutronoptics.com/ascom.html ' Run as Administrator CMD: with no arguments, selects camera and sets camera options ' cscript ASCap.vbs [DriverID] [FITS filename] [Exposure secs] [nBin] [Temperature] ' Under 64-bit Windows, use C:\windows\syswow64\cscript.exe ASCap.vbs [arguments...] ' Requires the ASCOM Platform http://www.ascom-standards.org/ and an ASCOM camera driver DLL ' Uses FITLS.DLL and an ASCOM camera to capture FITS images suitable for display in ImageJ ' Copyright ©2012 Alan Hewat. May be copied for non-commercial use provided this notice is displayed. ' Thanks to Miguel Lopes (Brightstar ASCOM), Bret McKee (sxASCOM) & Chris Rowland (Atik ASCOM) ' Thanks to Michael F. Toups for pointing out that "image.ImageArray = camera.ImageArray" ' should be replaced by an intermediate "animage = camera.ImageArray" statement ' That allows this script to work for Win-7, Win-8 and Win-10 Dim camera Dim image Dim animage If WScript.Arguments.Count < 2 Then 'Choose the camera and set its options DriverID="" If WScript.Arguments.Count > 0 Then DriverID=WScript.Arguments.Item(0) Set Chooser = CreateObject("DriverHelper.Chooser") Chooser.DeviceType = "Camera" DriverID = Chooser.Choose(DriverID) Set camera = CreateObject(DriverID) On Error Resume Next Err.Clear camera.Connected = True If Err.Number <> 0 Then WScript.Echo ("ERROR: Unable to connect to camera "+DriverID) Err.Clear Exit sub End If On Error Goto 0 End If If WScript.Arguments.Count < 3 Then Wscript.Echo("Syntax: cscript ASCap.vbs "+DriverID+" [Filename.FITS] [Exposure secs] [nBin] [Temperature]") Exit sub End If ' Otherwise elect and Expose the camera and write the result to a FITS file DriverID = WScript.Arguments.Item(0) ' First argument is the camera name (DriverID) filename = WScript.Arguments.Item(1) ' Second argument is the FITS file name to create exposuretime = WScript.Arguments.Item(2) ' Third argument is the exposure time seconds Set objFSO=CreateObject("Scripting.FileSystemObject") ' Set a file for writing out the results in the background ndir=InStrRev(filename, "\") outFile=Left(filename,ndir)+DriverID+".txt" Set objFile = objFSO.CreateTextFile(outFile,True) Set camera = CreateObject(DriverID) On Error Resume Next Err.Clear camera.Connected = True If Err.Number <> 0 Then WScript.Echo ("ERROR: Unable to connect to camera "+DriverID) objFile.Write "ERROR: Unable to connect to camera "+DriverID & vbCrLf Err.Clear Exit sub End If On Error Goto 0 If WScript.Arguments.Count > 3 Then nBin = CInt(Wscript.Arguments.Item(3)) ' Fourth argument is the Bin mode If nBin>1 Then MaxBinX=camera.MaxBinX if nBin>MaxBinX Then nBin=MaxBinX WScript.Echo ("Binning reset to MaxBinX="+cstr(MaxBinX)) objFile.Write "Binning reset to MaxBinX="+cstr(MaxBinX) & vbCrLf End If WScript.Echo ("Binning: "+cstr(nBin)) objFile.Write "Binning: "+cstr(nBin) & vbCrLf camera.NumX = Int(Camera.CameraXSize/nBin) camera.NumY = Int(Camera.CameraYSize/nBin) camera.BinX = nBin camera.BinY = nBin End If If WScript.Arguments.Count > 4 Then sTemperature = CSng(WScript.Arguments.Item(4)) ' Fifth argument is the set Temperature If camera.CanSetCCDTemperature Then camera.CoolerOn = True camera.SetCCDTemperature = sTemperature WScript.Echo ("Set Temperature: "+cstr(sTemperature)) objFile.Write "Set Temperature: "+cstr(sTemperature) & vbCrLf End If End If End If exposurestarttime = Now ' Expose now for the given time camera.StartExposure exposuretime, True WScript.Echo ("Exposing (s): "+cstr(exposuretime)) objFile.Write "Exposing (s): "+cstr(exposuretime) & vbCrLf While Not camera.ImageReady WScript.Sleep 100 Wend Set image = CreateObject("FITS.image") ' Create the ASCOM FITS driver object ' Fetch image array (raw pixel data) from the camera WScript.Echo ("Reading out Image") objFile.Write "Reading out Image" & vbCrLf animage = camera.ImageArray image.ImageArray = animage 'If Err.Number <> 0 Then ' Err.Clear ' animage = camera.ImageArray ' image.ImageArray = animage ' End If ' Set some properties for our new FITS file image.Camera = camera.Description image.ExposureInterval = exposuretime image.ExposureStartTime = exposurestarttime If WScript.Arguments.Count > 4 Then If camera.CanSetCCDTemperature Then WScript.Echo ("CCDTemperature: "+CStr(camera.CCDTemperature)) objFile.Write "CCDTemperature: "+CStr(camera.CCDTemperature) & vbCrLf image.CCDTemperature = camera.CCDTemperature If camera.CanGetCoolerPower Then WScript.Echo ("CoolerPower: "+CStr(camera.CoolerPower)) objFile.Write "CoolerPower: "+CStr(camera.CoolerPower) & vbCrLf End If objFile.Close End If End If ' Finally create the new FITS file image.WriteToFile filename WScript.Echo ("Image written to File: "+filename) End Sub '--- Main '---