Документ взят из кэша поисковой машины. Адрес оригинального документа : http://www.astro.louisville.edu/software/sbig/archive/xmccd-4.1/xmccd-4.1e/docs/sbig/stx_http_camera_api.pdf
Дата изменения: Tue May 31 02:30:45 2011
Дата индексирования: Thu Feb 27 22:48:10 2014
Кодировка:

Поисковые слова: п п п п п п п п п п п п п п п п п п п п п п п п п п п п п
SBIG STX HTTP Camera API
24 March 2011 Version 1.00.1

Santa Barbara Instrument Group 147A Castilian Drive Santa Barbara, CA 93117 Phone: (805) 571-7244 Fax: (805) 571-1147 EMail: sbig@sbig.com Web: www.sbig.com


Santa Barbara Instrument Group

STX HTTP Camera API

Introduction.................................................................................................................................... 1 HTTP Communication .................................................................................................................. 2
HTTP Version ................................................................................................................................... 2 HTTP Request Method ..................................................................................................................... 2
URI Length ..........................................................................................................................................................2 URI Character Encoding ......................................................................................................................................2

Example HTTP Conversation ........................................................................................................... 3 HTTP Status Codes ........................................................................................................................... 3 HTTP Content ................................................................................................................................... 3 HTTP Command Interval ................................................................................................................. 4

Application Programming Interface (API) ................................................................................... 5
Function Description Conventions.................................................................................................... 5 Imaging CCD..................................................................................................................................... 6
I I I I I I I I m m m m m m m m a a a a a a a a i i i i i i i i ge ge ge ge ge ge ge ge r r r r r r r r Get Settings ....... Set Settings ....... State .................. Data Binary ....... Data FITS.......... Image Ready ..... Start Exposure ... Abort Exposure . Get Settings ....... Set Settings........ State .................. Data Binary ....... Data FITS .......... Image Ready ..... Start Exposure ... Abort Exposure . Gui Gui Gui Gui Gui Gui Gui Gui d d d d d d d d e e e e e e e e r r r r r r r r .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. e .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ... ... ... ... ... ... ... ... .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .... .... .... .... .... .... ..1 ..1 .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 6 7 8 8 9 9 0 1 2 3 4 4 5 5 6 7 8 9 0 0 1 1 2 3 4 5 6 7 8 9 0 1 2 3
i

Internal Guide CCD ........................................................................................................................ 12
Gu Gu Gu Gu Gu Gu Gu Gu d d d d d d d d er er er er er er er er n n n n n n n n

External Guide CCD ....................................................................................................................... 18
Ext Ext Ext Ext Ext Ext Ext Ext e e e e e e e e r r r r r r r r al al al al al al al al Get Settings ... Set Settings .... State ............... Data Binary .... Data FITS ...... Image Ready .. Start Exposure Abort Exposur ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... .....

Camera ............................................................................................................................................ 24
Filter State .................. Get Filter Settings ...... Change Filter .............. Set Filter Name .......... Pulse Guide ................ Is Pulse Guiding ......... Pulse Guide Get Time AO Guide ................... AO Status ................... Get FITS Settings .......
24 March 2011

..................... ..................... ..................... ..................... ..................... ..................... Remaining... ..................... ..................... .....................

..... ..... ..... ..... ..... ..... ..... ..... ..... .....

..... ..... ..... ..... ..... ..... ..... ..... ..... .....


Santa Barbara Instrument Group

STX HTTP Camera API

Set FITS Settings ...............................................................................................................................................34 Description .........................................................................................................................................................35 Version Numbers ...............................................................................................................................................35

Example Source Code .................................................................................................................. 36
Reading a Value .............................................................................................................................. 36 Downloading an Image.................................................................................................................... 37 Full Featured Example.................................................................................................................... 38

More Example Conversations ..................................................................................................... 41
Multiple Parameter Get .................................................................................................................. 41 No Valid Parameter Error .............................................................................................................. 41 Successful Conversion with No Data .............................................................................................. 42

Revision History ........................................................................................................................... 43

24 March 2011

ii


Santa Barbara Instrument Group

STX HTTP Camera API

Introduction
The STX HTTP Camera API allows communication to the camera over Ethernet connections using the standard HTTP protocol. The HTTP protocol allows the STX camera to be controlled across a variety of PC platforms without any special driver requirements. This API is in addition to the "Classic API" using the SBIG Driver Library.

24 March 2011

1


Santa Barbara Instrument Group

STX HTTP Camera API

HTTP Communication
The HTTP communication protocol is a text based communication over standard Ethernet sockets. This standard communication protocol is implemented in several Web Browsers available on PCs, but is also simple enough to be used without a Web Browser. Any programming language with access to a TCP/IP sockets interface can create the messages required to communicate using the HTTP communication protocol.

HTTP Version
The STX implements a web server using the HTTP/1.0 protocol.

HTTP Request Method
All the API calls use the GET request method for simplicity. All parameters are appended to the Uniform Resource Identifier (URI) using the standard URI scheme. This is where a question mark ("?") character is used to indicate the end of the address and the beginning of the parameter list. Then each parameter is separated by an ampersand ("&") character. This is an example URI with multiple parameters:
http://1.1.1.1/api/ImagerSetSettings.cgi?BinX=2&BinY=2

In this example, the API call is to ImagerSetSettings.cgi. There are two parameters passed to the function: BinX, and BinY. Each parameter is assigned a value.

URI Length
The STX interface supports a maximum URI length of 8192 characters. There is no specific maximum length specified in the HTTP standard. Thus various tools/applications that implement HTTP may not support URIs that are as long as the camera can support. However, the maximum length of any URI in this API is still considerably shorter than the maximum URI lengths supported in many standards. But the URI length should be a consideration when making any API calls.

URI Character Encoding
The URI has some reserved characters. Any time a reserved character needs to be included in the URI, it must be percent encoded. The reserved characters and the associated percent encoded value are shown here:
! %21 * %2A ` %27 ( %28 ) %29 ; %3B : %3A @ %40 & %26 = %3D + %2B $ %24 , %2C / %2F ? %3F % %25 # %23 [ %5B ] %5D space %20

This is an example URI showing the percent encoded values:
http://1.1.1.1/api/SetFITSSetting.cgi?ObjectName=California%20Nebula%20%28NGC1499%29

This will set the ObjectName parameter to "California Nebula (NGC1499)".

24 March 2011

2


Santa Barbara Instrument Group

STX HTTP Camera API

Example HTTP Conversation
A simple HTTP conversion between a client (PC) and the STX is shown here. This is the transaction that would take place with the following URI (after a TCP/IP socket connection):
http://1.1.1.1/api/ImagerState.cgi

Client request: GET /api/ImagerState.cgi HTTP/1.0

STX response: HTTP/1.0 200 OK Content-Type: text/plain Content-Length: 3 0

See the section More Example Conversations for more examples.

HTTP Status Codes
The STX only implements a few of the available HTTP status codes to indicate the result of the request. The used status codes are: 200 OK 400 Bad Request 404 Not Found All properly formed requests will result in the "200 OK" status code. Any unrecognized URI will result in the "404 Not Found" status code. Finally, any URI with invalid parameters or other malformed information will result in the "400 Bad Request" status code. When the "400 Bad Request" is returned, the data portion of the transfer will contain an error number and error text. Possible error numbers are listed with each appropriate API call.

HTTP Content
Any URI that returns text content does so with the content formatted only as plain text. There is no HTML formatting of the response text to simplify parsing on the client. API calls that return multiple values delimit values with a carriage return and line feed (CRLF). The HTTP header will show the Content Type set to "text/plain". Any URI that returns binary type data will show a Content Type set to "application/octet-stream" in the HTTP header. After the header is sent the binary data is streamed to the client. Each byte should be saved as part of the binary file. Do not discard CR or LF characters.

24 March 2011

3


Santa Barbara Instrument Group

STX HTTP Camera API

HTTP Command Interval
The embedded server in the STX camera is limited in its performance. As such, issuing commands at a very high rate can cause the STX response time to slow down. This is similar to a denial-of-service attack that can occur to web sites on the internet. HTTP commands should not be issued to the STX more frequently than one command every 50 milliseconds. This command interval results in 20 commands per second, which is still quite a high rate. There is not any functionality that should require this rate of setting or querying parameters. If numerous parameters need to be set or queried in a short period of time, it is better to group the parameters into a single HTTP Request if possible. If the computer controlling the STX camera is capable of sending commands more frequently than once every 50 milliseconds, a delay should be used to slow down the command interval.

24 March 2011

4


Santa Barbara Instrument Group

STX HTTP Camera API

Application Programming Interface (API)
The API is split into four sections. The first three sections contain functions specific to the Imaging CCD, Internal Guide CCD, and External Guide CCD. The last section contains general functions applicable to the entire camera.

Function Description Conventions
Each function can have required and/or optional parameters associated with it. Required parameters are shown in the URI. Optional parameters are shown surrounded by braces "[]". Some parameters can be assigned a value. In this case the parameter name should be followed by the equals ("=") character and then followed by the value to be set to the parameter. Some parameters cannot be assigned a value, but only queried. In this case, there should never be an equals ("=") character after the parameter's name.

24 March 2011

5


Santa Barbara Instrument Group

STX HTTP Camera API

Imaging CCD
Imager Get Settings
URI: /api/ImagerGetSettings.cgi?Param1[&Param2]...[&ParamX] Available parameters: Parameter
B B C C C C C C E F A M M M S S N N P P in in oo CD CD oo am am le ul mb ax ax ax ta ta um um ix ix X Y l T T l e e c l i A B B r r X Y e e er em em er ra ra tr We en DU in in tX tY S p p P X Y o l t X Y ta er er ow Si Si ns lC Te t a a e z z P a m e tu tu r e e er pa pe

Description
Binning value for the X axis Binning value for the Y axis Current cooler state: 0=Off, 1=On Current CCD temperature in degrees Celsius Current CCD temperature set point in degrees Celsius Current cooler power level in percent Width of the camera sensor in unbinned pixels Height of the camera sensor in unbinned pixels Gain of the CCD in electrons per A/D unit Full well capacity of the CCD in electrons Current ambient temperature in degrees Celsius Maximum ADU value the CCD will produce Maximum binning value for the X axis Maximum binning value for the Y axis Frame start position for the X axis in un-binned pixels Frame start position for the Y axis in un-binned pixels Frame width in un-binned pixels Frame height in un-binned pixels Pixel width in microns Pixel height in microns

re reSetpoint

ADU city rature

lSizeX lSizeY

Description: This function is used to query any of the parameters listed above. Any number of parameters can be included in a single call to the function. Returns: The values for the requested parameters will be returned in the order they were requested. Errors: If no valid parameters are included, a "400 Bad Request" error will be generated. Error Code
0x80001000

Description
No valid parameter.

Invalid parameters are ignored. Example:
http://1.1.1.1/api/ImagerGetSettings.cgi?CameraXSize&CameraYSize

24 March 2011

6


Santa Barbara Instrument Group

STX HTTP Camera API

Imager Set Settings
URI: /api/ImagerSetSettings.cgi?Param1=x[&Param2=x]...[&ParamX=x] Available parameters: Parameter
BinX BinY CoolerState CCDTemperatureSetpoint StartX StartY NumX NumY

Description
Binning value for the X axis Binning value for the Y axis Current cooler state CCD temperature set point in degrees C Frame start position for the X axis in un-binned pixels Frame start position for the Y axis in un-binned pixels Frame width in un-binned pixels Frame height in un-binned pixels

Valid Values
1t 1t 0= 1= -10 0t 1) 0t 1) 1t Sta 1t Sta o MaxB o MaxB Off On 0.0 to o (Cam inX inY

Default
1 1 0 = Off 25.0 0 0 CameraXSize CameraYSize

100.0 eraXSize ­

o (CameraYSize ­ o r o r ( tX ( tY CameraXSize ­ ) CameraYSize ­ )

Description: This function is used to set any of the parameters listed above. Any number of parameters can be included in a single call to the function. Returns: No data is returned. Errors: Parameters are parsed in the order they are listed above. If an invalid value is received, a "400 Bad Request" error will be generated and no further parsing is performed. Error Code
0 0 0 0 0 0 x8 x8 x8 x8 x8 x8 0 0 0 0 0 0 00 00 00 00 00 00 1 1 1 1 1 1 00 00 00 00 00 00 1 2 3 4 5 6

Description
BinX < 1 or > MaxBin BinY < 1 or > MaxBin StartX < 0 or > (CameraXSize StartY < 0 or > (CameraYSize NumX < 1 or > (CameraXSize NumY < 1 or > (CameraYSize ­ ­ ­ ­ 1) 1) StartX) StartY)

Invalid parameters are ignored. Note on NumX/NumY parameters. Changing the StartX/StartY value impacts the allowed limits of NumX/NumY. However, the values of NumX/NumY are never changed automatically. The values of NumX/NumY are limit checked when an exposure is started and "Bad parameter" is returned if their values are not valid. Example:
http://1.1.1.1/api/ImagerGetSettings.cgi?BinX=2&BinY=2&CoolerState=1

24 March 2011

7


Santa Barbara Instrument Group

STX HTTP Camera API

Imager State
URI: /api/ImagerState.cgi Available parameters: None. Description: This function queries the current state of the imaging CCD. Returns: Single integer representing the state of the CCD as shown: Value State
0 2 3 5 Id l e Exposing Reading out the CCD Error

Errors: None. Example:
http://1.1.1.1/api/ImagerState.cgi

Imager Data Binary
URI: /api/ImagerData.bin Available parameters: None. Description: This downloads the binary image data from the camera. Returns: A stream of binary image data. Data is 16-bits per pixel, little-endian (low byte first) format. The number of bytes sent to the client is equal to: (NumX/BinX)*(NumY/BinY)*2 Errors: None. Example:
http://1.1.1.1/api/ImagerData.bin

24 March 2011

8


Santa Barbara Instrument Group

STX HTTP Camera API

Imager Data FITS
URI: /api/Imager.FIT Available parameters: None. Description: This downloads the binary image data from the camera in FITS format. Returns: A stream of FITS format image data. The FITS header contains some user settable parameters. See the FITS Setup function. Errors: None. Example:
http://1.1.1.1/api/Imager.FIT

Imager Image Ready
URI: /api/ImagerImageReady.cgi Available parameters: None. Description: Queries the state of the image buffer in the camera. Returns: Single integer representing the state of the image buffer in the camera. Value State
0 1 No image available Image is available

Errors: None. Example:
http://1.1.1.1/api/ImagerImageReady.cgi

24 March 2011

9


Santa Barbara Instrument Group

STX HTTP Camera API

Imager Start Exposure
URI: /api/ImagerStartExposure.cgi?Duration=X&FrameType=Y[&DateTime=Z] Available parameters: Parameter
Duration FrameType

Description
Duration of the exposure in Seconds Frame type selection

Valid Values
0 0 1 2 3 .0 = = = = 1t Da Li Bi Fl o ??? rk ght as at Field

DateTime

Optional exposure Date/Time for FITS header Must be in the format: yyyy-mm-ddThh.mm.ss.sss Where: yyyy = year mm = month d d = d ay hh = hour mm = minute ss.sss = second to millisecond resolution If not set, the FITS header Date/Time will be set to: 2008-01-01T00:00:00.000

Description: Starts an exposure. Bias and Flat frame t ypes will only impact FITS headers. In all other aspects Bias is the same as Dark and Flat is the same as Light. Returns: No data is returned. Errors: If either required parameter is missing, or if the camera is busy, or if an invalid value is sent, a "400 Bad Request" error will be generated. Error Code
0x80001008 0x80001009 0x8000100a

Description
Camera is busy. Bad parameter. Parameter(s) missing.

Invalid parameters are ignored. Example:
http://1.1.1.1/api/ImagerStartExposure.cgi?Duration=300&FrameType=1

24 March 2011

10


Santa Barbara Instrument Group

STX HTTP Camera API

Imager Abort Exposure
URI: /api/ImagerAbortExposure.cgi Available parameters: None. Description: Aborts an exposure in progress. If no exposure is in progress, the abort is ignored. Returns: No data is returned. Errors: If the abort failed, a "400 Bad Request" error will be generated. Error Code
0x80001007

Description
Abort failed.

Invalid parameters are ignored. Example:
http://1.1.1.1/api/ImagerAbortExposure.cgi

24 March 2011

11


Santa Barbara Instrument Group

STX HTTP Camera API

Internal Guide CCD
Guider Get Settings
URI: /api/GuiderGetSettings.cgi?Param1[&Param2]...[&ParamX] Available parameters: Parameter
B B C C C C C E F A M M M S S N N P P in in oo CD oo am am le ul mb ax ax ax ta ta um um ix ix X Y l T l e e c l i A B B r r X Y e e er em er ra ra tr We en DU in in tX tY S p P X Y o l t X Y ta er ow Si Si ns lC Te t a e z z P a m e tu r e e er pa pe

Description
Binning value for the X axis Binning value for the Y axis Current cooler state: 0=Off, 1=On Current CCD temperature in degrees Celsius Currrent cooler power level in percent Width of the camera sensor in unbinned pixels Height of the camera sensor in unbinned pixels Gain of the CCD in electrons per A/D unit Full well capacity of the CCD in electrons Current ambient temperature in degrees Celsius Maximum ADU value the CCD will produce Maximum binning value for the X axis Maximum binning value for the Y axis Frame start position for the X axis in un-binned pixels Frame start position for the Y axis in un-binned pixels Frame width in un-binned pixels Frame height in un-binned pixels Pixel width in microns Pixel height in microns

re

ADU city rature

lSizeX lSizeY

Description: This function is used to query any of the parameters listed above. Any number of parameters can be included in a single call to the function. Returns: The values for the requested parameters will be returned in the order they were requested. Errors: If no valid parameters are included, a "400 Bad Request" error will be generated. Error Code
0x80001000

Description
No valid parameter.

Invalid parameters are ignored. Example:
http://1.1.1.1/api/GuiderGetSettings.cgi?CameraXSize&CameraYSize

24 March 2011

12


Santa Barbara Instrument Group

STX HTTP Camera API

Guider Set Settings
URI: /api/GuiderSetSettings.cgi?Param1=x[&Param2=x]...[&ParamX=x] Available parameters: Parameter
BinX BinY StartX StartY NumX NumY

Description
Binning value for the X axis Binning value for the Y axis Frame start position for the X axis in un-binned pixels Frame start position for the Y axis in un-binned pixels Frame width in un-binned pixels Frame height in un-binned pixels

Valid Values
1 1 0 1) 0 1) 1 St 1 St to MaxBinX to MaxBinY to (CameraXSize ­ to (CameraYSize ­ t a t a o rt o rt ( X ( Y CameraXSize ­ ) CameraYSize ­ )

Default Value
1 1 0 0 CameraXSize CameraYSize

Description: This function is used to set any of the parameters listed above. Any number of parameters can be included in a single call to the function. Returns: No data is returned. Errors: Parameters are parsed in the order they are listed above. If an invalid value is received, a "400 Bad Request" error will be generated and no further parsing is performed. Error Code
0 0 0 0 0 0 x8 x8 x8 x8 x8 x8 0 0 0 0 0 0 00 00 00 00 00 00 1 1 1 1 1 1 00 00 00 00 00 00 1 2 3 4 5 6

Description
BinX < 1 or > MaxBin BinY < 1 or > MaxBin StartX < 0 or > (CameraXSize StartY < 0 or > (CameraYSize NumX < 1 or > (CameraXSize NumY < 1 or > (CameraYSize ­ ­ ­ ­ 1) 1) StartX) StartY)

Invalid parameters are ignored. Note on NumX/NumY parameters. Changing the StartX/StartY value impacts the allowed limits of NumX/NumY. However, the values of NumX/NumY are never changed automatically. The values of NumX/NumY are limit checked when an exposure is started and "Bad parameter" is returned if their values are not valid. Example:
http://1.1.1.1/api/GuiderGetSettings.cgi?BinX=2&BinY=2&CoolerState=1

24 March 2011

13


Santa Barbara Instrument Group

STX HTTP Camera API

Guider State
URI: /api/GuiderState.cgi Available parameters: None. Description: This function queries the current state of the internal guider CCD. Returns: Single integer representing the state of the CCD as shown: Value State
0 2 3 5 Id l e Exposing Reading out the CCD Error

Errors: None. Example:
http://1.1.1.1/api/GuiderState.cgi

Guider Data Binary
URI: /api/GuiderData.bin Available parameters: None. Description: This downloads the binary image data from the camera. Returns: A stream of binary image data. Data is 16-bits per pixel, little-endian (low byte first) format. The number of bytes sent to the client is equal to: (NumX/BinX)*(NumY/BinY)*2 Errors: None. Example:
http://1.1.1.1/api/GuiderData.bin

24 March 2011

14


Santa Barbara Instrument Group

STX HTTP Camera API

Guider Data FITS
URI: /api/Guider.FIT Available parameters: None. Description: This downloads the binary image data from the camera in FITS format. Returns: A stream of FITS format image data. The FITS header contains some user settable parameters. See the FITS Setup function. Errors: None. Example:
http://1.1.1.1/api/Guider.FIT

Guider Image Ready
URI: /api/GuiderImageReady.cgi Available parameters: None. Description: Queries the state of the image buffer in the camera. Returns: Single integer representing the state of the image buffer in the camera. Value State
0 1 No image available Image is available

Errors: None. Example:
http://1.1.1.1/api/GuiderImageReady.cgi

24 March 2011

15


Santa Barbara Instrument Group

STX HTTP Camera API

Guider Start Exposure
URI: /api/GuiderStartExposure.cgi?Duration=X&FrameType=Y[&DateTime=Z] Available parameters: Parameter
Duration FrameType

Description
Duration of the exposure in Seconds Frame type selection

Valid Values
0 0 1 2 3 .0 = = = = 1t Da Li Bi Fl o r g a a ??? k ht s t Field

DateTime

Optional exposure Date/Time for FITS header Must be in the format: yyyy-mm-ddThh.mm.ss.sss Where: yyyy = year mm = month d d = d ay hh = hour mm = minute ss.sss = second to millisecond resolution If not set, the FITS header Date/Time will be set to: 2008-01-01T00:00:00.000

Description: Starts an exposure. Bias and Flat frame t ypes will only impact FITS headers. In all other aspects Bias is the same as Dark and Flat is the same as Light. Returns: No data is returned. Errors: If either required parameter is missing, or if the camera is busy, or if an invalid value is sent, a "400 Bad Request" error will be generated. Error Code
0x80001008 0x80001009 0x8000100a

Description
Camera is busy. Bad parameter. Parameter(s) missing.

Invalid parameters are ignored. Example:
http://1.1.1.1/api/GuiderStartExposure.cgi?Duration=11.7&FrameType=1

24 March 2011

16


Santa Barbara Instrument Group

STX HTTP Camera API

Guider Abort Exposure
URI: /api/GuiderAbortExposure.cgi Available parameters: None. Description: Aborts an exposure in progress. If no exposure is in progress, the abort is ignored. Returns: No data is returned. Errors: If the abort failed, a "400 Bad Request" error will be generated. Error Code
0x80001007

Description
Abort failed.

Invalid parameters are ignored. Example:
http://1.1.1.1/api/GuiderAbortExposure.cgi

24 March 2011

17


Santa Barbara Instrument Group

STX HTTP Camera API

External Guide CCD
External Guider Get Settings
URI: /api/ExtGuiderGetSettings.cgi?Param1[&Param2]...[&ParamX] Available parameters: Parameter
B B C C E F A M M M S S N N P P in in am am le ul mb ax ax ax ta ta um um ix ix X Y e e c l i A B B r r X Y e e ra ra tr We en DU in in tX tY X Y o l t X Y Si Si ns lC Te z z P a m e e erADU pacity perature

Description
Binning value for the X axis Binning value for the Y axis Width of the camera sensor in unbinned pixels Height of the camera sensor in unbinned pixels Gain of the CCD in electrons per A/D unit Full well capacity of the CCD in electrons Current ambient temperature in degrees Celsius Maximum ADU value the CCD will produce Maximum binning value for the X axis Maximum binning value for the Y axis Frame start position for the X axis in un-binned pixels Frame start position for the Y axis in un-binned pixels Frame width in un-binned pixels Frame height in un-binned pixels Pixel width in microns Pixel height in microns

lSizeX lSizeY

Description: This function is used to query any of the parameters listed above. Any number of parameters can be included in a single call to the function. Returns: The values for the requested parameters will be returned in the order they were requested. Errors: If no valid parameters are included, a "400 Bad Request" error will be generated. Error Code
0x80001000

Description
No valid parameter.

Invalid parameters are ignored. Example:
http://1.1.1.1/api/ExtGuiderGetSettings.cgi?CameraXSize&CameraYSize

24 March 2011

18


Santa Barbara Instrument Group

STX HTTP Camera API

External Guider Set Settings
URI: /api/ExtGuiderSetSettings.cgi?Param1=x[&Param2=x]...[&ParamX=x] Available parameters: Parameter
BinX BinY StartX StartY NumX NumY

Description
Binning value for the X axis Binning value for the Y axis Frame start position for the X axis in un-binned pixels Frame start position for the Y axis in un-binned pixels Frame width in un-binned pixels Frame height in un-binned pixels

Valid Values
1 1 0 1) 0 1) 1 St 1 St to MaxBinX to MaxBinY to (CameraXSize ­ to (CameraYSize ­ t a t a o rt o rt ( X ( Y CameraXSize ­ ) CameraYSize ­ )

Default Value
1 1 0 0 CameraXSize CameraYSize

Description: This function is used to set any of the parameters listed above. Any number of parameters can be included in a single call to the function. Returns: No data is returned. Errors: Parameters are parsed in the order they are listed above. If an invalid value is received, a "400 Bad Request" error will be generated and no further parsing is performed. Error Code
0 0 0 0 0 0 x8 x8 x8 x8 x8 x8 0 0 0 0 0 0 00 00 00 00 00 00 1 1 1 1 1 1 00 00 00 00 00 00 1 2 3 4 5 6

Description
BinX < 1 or > MaxBin BinY < 1 or > MaxBin StartX < 0 or > (CameraXSize StartY < 0 or > (CameraYSize NumX < 1 or > (CameraXSize NumY < 1 or > (CameraYSize ­ ­ ­ ­ 1) 1) StartX) StartY)

Invalid parameters are ignored. Note on NumX/NumY parameters. Changing the StartX/StartY value impacts the allowed limits of NumX/NumY. However, the values of NumX/NumY are never changed automatically. The values of NumX/NumY are limit checked when an exposure is started and "Bad parameter" is returned if their values are not valid. Example:
http://1.1.1.1/api/ExtGuiderGetSettings.cgi?BinX=2&BinY=2&CoolerState=1

24 March 2011

19


Santa Barbara Instrument Group

STX HTTP Camera API

External Guider State
URI: /api/ExtGuiderState.cgi Available parameters: None. Description: This function queries the current state of the external guider CCD. Returns: Single integer representing the state of the CCD as shown: Value State
0 2 3 5 Id l e Exposing Reading out the CCD Error

Errors: None. Example:
http://1.1.1.1/api/ExtGuiderState.cgi

External Guider Data Binary
URI: /api/ExtGuiderData.bin Available parameters: None. Description: This downloads the binary image data from the camera. Returns: A stream of binary image data. Data is 16-bits per pixel, little-endian (low byte first) format. The number of bytes sent to the client is equal to: (NumX/BinX)*(NumY/BinY)*2 Errors: None. Example:
http://1.1.1.1/api/ExtGuiderData.bin

24 March 2011

20


Santa Barbara Instrument Group

STX HTTP Camera API

External Guider Data FITS
URI: /api/ExtGuider.FIT Available parameters: None. Description: This downloads the binary image data from the camera in FITS format. Returns: A stream of FITS format image data. The FITS header contains some user settable parameters. See the FITS Setup function. Errors: None. Example:
http://1.1.1.1/api/ExtGuider.FIT

External Guider Image Ready
URI: /api/ExtGuiderImageReady.cgi Available parameters: None. Description: Queries the state of the image buffer in the camera. Returns: Single integer representing the state of the image buffer in the camera. Value State
0 1 No image available Image is available

Errors: None. Example:
http://1.1.1.1/api/ExtGuiderImageReady.cgi

24 March 2011

21


Santa Barbara Instrument Group

STX HTTP Camera API

External Guider Start Exposure
URI: /api/ExtGuiderStartExposure.cgi?Duration=X&FrameType=Y[&DateTime=Z] Available parameters: Parameter
Duration FrameType

Description
Duration of the exposure in Seconds Frame type selection

Valid Values
0 0 1 2 3 .0 = = = = 1t Da Li Bi Fl o ??? rk ght as at Field

DateTime

Optional exposure Date/Time for FITS header Must be in the format: yyyy-mm-ddThh.mm.ss.sss Where: yyyy = year mm = month d d = d ay hh = hour mm = minute ss.sss = second to millisecond resolution If not set, the FITS header Date/Time will be set to: 2008-01-01T00:00:00.000

Description: Starts an exposure. Bias and Flat frame t ypes will only impact FITS headers. In all other aspects Bias is the same as Dark and Flat is the same as Light. Returns: No data is returned. Errors: If either required parameter is missing, or if the camera is busy, or if an invalid value is sent, a "400 Bad Request" error will be generated. Error Code
0x80001008 0x80001009 0x8000100a

Description
Camera is busy. Bad parameter. Parameter(s) missing.

Invalid parameters are ignored. Example:
http://1.1.1.1/api/ExtGuiderStartExposure.cgi?Duration=2.52&FrameType=1

24 March 2011

22


Santa Barbara Instrument Group

STX HTTP Camera API

External Guider Abort Exposure
URI: /api/ExtGuiderAbortExposure.cgi Available parameters: None. Description: Aborts an exposure in progress. If no exposure is in progress, the abort is ignored. Returns: No data is returned. Errors: If the abort failed, a "400 Bad Request" error will be generated. Error Code
0x80001007

Description
Abort failed.

Invalid parameters are ignored. Example:
http://1.1.1.1/api/ExtGuiderAbortExposure.cgi

24 March 2011

23


Santa Barbara Instrument Group

STX HTTP Camera API

Camera
Filter State
URI: /api/FilterState.cgi Available parameters: None. Description: This function queries the current state of the Filter Selector. Returns: Single integer representing the state of the CCD as shown: Value State
0 1 2 Id l e Moving Error

Errors: None. Example:
http://1.1.1.1/api/FilterState.cgi

24 March 2011

24


Santa Barbara Instrument Group

STX HTTP Camera API

Get Filter Settings
URI: /api/GetFilterSetting.cgi?Param1[&Param2]...[&ParamX] Available parameters: Parameter
C C F F F F F F F F ur ur il il il il il il il il r r t t t t t t t t en en er er er er er er er er tFi tFi 1Na 2Na 3Na 4Na 5Na 6Na 7Na 8Na lter lterName me me me me me me me me

Description
Curre Curre Filter Filter Filter Filter Filter Filter Filter Filter ntly selected filter number ntly selected filter name 1 Name 2 Name 3 Name 4 Name 5 Name 6 Name 7 Name 8 Name

Description: This function queries the current values for the available Filter settings. Returns: The values for the requested parameters will be returned in the order they were requested. Errors: If no valid parameters are included, a "400 Bad Request" error will be generated. Error Code
0x80001000

Description
No valid parameter.

Invalid parameters are ignored. Example:
http://1.1.1.1/api/GetFilterSetting.cgi?CurrentFilter&Filter1Name

24 March 2011

25


Santa Barbara Instrument Group

STX HTTP Camera API

Change Filter
URI: /api/ChangeFilter.cgi?NewPosition=X Available parameters: Parameter
NewPosition

Description
Number of the filter to move to. Can be the currently selected filter.

Valid Values
0 for no filter or 1 through 8

Description: This function moves the Filter Selector to position the selected filter over the camera aperture. Returns: No data is returned. Errors: If the required parameter is missing, or if the Filter Selector is moving, or if an invalid value is sent, a "400 Bad Request" error will be generated. Error Code
0 0 0 0 0 x8 x8 x8 x8 x8 0 0 0 0 0 00 00 00 00 00 1 1 1 1 1 00 00 00 00 00 9 a b c d

Description
Bad parameter. Parameter(s) missing. Filter Selector is busy. Filter Selector not found. Filter Selector communication error.

Example:
http://1.1.1.1/api/ChangeFilter.cgi?NewPosition=0

24 March 2011

26


Santa Barbara Instrument Group

STX HTTP Camera API

Set Filter Name
URI: /api/SetFilterName.cgi?Param1=x[&Param2=x]...[&ParamX=x] Available parameters: Parameter
F F F F F F F F il il il il il il il il t t t t t t t t er er er er er er er er 1N 2N 3N 4N 5N 6N 7N 8N a a a a a a a a me me me me me me me me

Description

Valid Values

Default Value

Filter Name

Text, 16 characters max

"Empty"

Description: This function changes the name of the specified filter. When these parameters are changed, the new value is programmed into the camera's non-volatile Flash memory. This allows the camera to remember these parameters after power is removed. Returns: No data is returned. Errors: None. Invalid parameters are ignored. Example:
http://1.1.1.1/api/SetFilterName.cgi?Filter1=Luminance

24 March 2011

27


Santa Barbara Instrument Group

STX HTTP Camera API

Pulse Guide
URI: /api/PulseGuide.cgi?[DirectionX=W&DurationX=X][DirectionY=Y&DurationY=Z] Available parameters: Parameter
DirectionX DurationX DirectionY DurationY

Description
X Directional relay to close Duration of time to keep the X relay closed (in seconds) Y Directional relay to close Duration of time to keep the Y relay closed (in seconds)

Valid Values
0 = X+ 1 = X0.01s to 655.35s 0 = Y+ 1 = Y0.01s to 655.35s

Description: Closes relays for the specified time. One call can set either X or Y relays, or both. Each relay will remain closed for the time specified with that relay. If the requested relay is already activated, the activation time will be reset to the new requested time. Returns: No data is returned. Errors: If either required parameter is missing, or if an invalid value is sent, a "400 Bad Request" error will be generated. Error Code
0x80001009 0x8000100a

Description
Bad parameter. Parameter(s) missing.

Invalid parameters are ignored. Example:
http://1.1.1.1/api/PulseGuide.cgi?DirectionY=1&DurationY=10

24 March 2011

28


Santa Barbara Instrument Group

STX HTTP Camera API

Is Pulse Guiding
URI: /api/IsPulseGuiding.cgi Available parameters: None. Description: Queries the state of the relays. Returns: Single integer representing the state of the relays. Value State
0 1 No relay active One or more relays active

Errors: None. Example:
http://1.1.1.1/api/IsPulseGuiding.cgi

24 March 2011

29


Santa Barbara Instrument Group

STX HTTP Camera API

Pulse Guide Get Time Remaining
URI: /api/PulseGuideGetTimeRemaining.cgi?Param1[&Param2]...[&ParamX] Available parameters: Parameter
X X Y Y Pl Mi Pl Mi u n u n s us s us

Description
X+ XY+ YRelay Time Rel a y T i m e Relay Time Rel a y T i m e Remaining Remaining Remaining Remaining

Description: Queries the time remaining on all the relays. Returns: The values for the requested parameters will be returned in the order they were requested. Errors: If no valid parameters are included, a "400 Bad Request" error will be generated. Error Code
0x80001000

Description
No valid parameter.

Invalid parameters are ignored. Example:
http://1.1.1.1/api/PulseGuideGetTimeRemaining.cgi?XPlus&YMinus

24 March 2011

30


Santa Barbara Instrument Group

STX HTTP Camera API

AO Guide
URI: /api/AOGuide.cgi?XPosition=X&YPosition=Y Available parameters: Parameter
XPosition YPosition

Description
AO X Position AO Y Position

Valid Values
0 ( 0 ( t 50 t 50 o1 is o1 is 00 centered) 00 centered)

Description: Moves the AO device to the specified position. Both X and Y positions must be specified. Returns: No data is returned. Errors: If either required parameter is missing, or if an invalid value is sent, a "400 Bad Request" error will be generated. Error Code
0x80001009 0x8000100a

Description
Bad parameter. Parameter(s) missing.

Invalid parameters are ignored. Example:
http://1.1.1.1/api/AOGuide.cgi?XPosition=55&YPosition=42

24 March 2011

31


Santa Barbara Instrument Group

STX HTTP Camera API

AO Status
URI: /api/AOStatus.cgi Available parameters: None. Description: Queries the state of the AO device. Returns: Single integer representing the state of the AO. Value State
0 1 Id l e Moving

Errors: None. Example:
http://1.1.1.1/api/AOStatus.cgi

24 March 2011

32


Santa Barbara Instrument Group

STX HTTP Camera API

Get FITS Settings
URI: /api/GetFITSSetting.cgi?Param1[&Param2]...[&ParamX] Available parameters: Parameter
O O T F A A bj bs el L pe re ectName erver escope rture a

Description
Object Name field Observer field Telescope field Focal Length field Aperture Diameter field Aperture Area field

Description: This function queries the current values for the available FITS header fields. Returns: The values for the requested parameters will be returned in the order they were requested. Errors: If no valid parameters are included, a "400 Bad Request" error will be generated. Error Code
0x80001000

Description
No valid parameter.

Invalid parameters are ignored. Example:
http://1.1.1.1/api/GetFITSSetting.cgi?ObjectName&FL

24 March 2011

33


Santa Barbara Instrument Group

STX HTTP Camera API

Set FITS Settings
URI: /api/SetFITSSetting.cgi?Param1=X[&Param2=X]...[&ParamX=X] Available parameters: Parameter
O O T F A A bj bs el L pe re ectName erver escope rture a

Description
Object Name field Observer field Telescope field Focal Length field Aperture Diameter field Aperture Area field

Valid Values
Text, Text, Text, Floati Floati Floati 6 6 6 n n n 7 7 7 g g g chara chara chara point point point cters cters cters num num num m ax m ax m ax ber ber ber

Default Value
"Object Description" "STX Camera Operator" "Telescope Description" 2000.00 200.00 25000.00

Description: Sets any of the available FITS header fields. Used only for FITS files. All text parameters may contain any ASCII characters with values from decimal 32 through 126 (hexadecimal 20 through 7E). This is the same requirement as in the FITS standard. When these parameters are changed, the new value is programmed into the camera's non-volatile Flash memory. This allows the camera to remember these parameters after power is removed. Returns: No data is returned. Errors: None. Invalid parameters are ignored. Example:
http://1.1.1.1/api/SetFITSSetting.cgi?ObjectName=M27

24 March 2011

34


Santa Barbara Instrument Group

STX HTTP Camera API

Description
URI: /api/Description.cgi Available parameters: None. Description: Queries the camera model number. Returns: Text string containing the camera model number, e.g. "SBIG STX-16803". Errors: None. Example:
http://1.1.1.1/api/Description.cgi

Version Numbers
URI: /api/VersionNumbers.cgi Available parameters: None. Description: Queries the camera version numbers. Returns: Text string containing the camera version numbers, in the following order: Firmware Version Gate Array Version Imaging ROP Version Tracker ROP Version HTTP API Version Errors: None. Example:
http://1.1.1.1/api/VersionNumbers.cgi

24 March 2011

35


Santa Barbara Instrument Group

STX HTTP Camera API

Example Source Code
These examples are all written in Microsoft Visual Studio 2008 using the Visual C# Console Application template. To use these examples, create a new project called "STXWebAPITest" using the template. Replace all of the text in the Program.cs file with the text below. Finally change the IP address in the example from "1.1.1.1" to the IP address of your camera.

Reading a Value
usi usi usi usi usi usi ng ng ng ng ng ng Sy Sy Sy Sy Sy Sy stem; stem. stem. stem. stem. stem. Collections.Generic; Linq; Text; Net; IO; WebAPITest gram c void Main(string[] args) ttpWebRequest Request; tring CameraDescription;

namespace STX { class Pro { stati { H S

try { // Re } catch { Co Re } prepare the web page we will be asking for quest = (HttpWebRequest)WebRequest.Create("http://1.1.1.1/api/Description.cgi");

nsole.Write("Error creating request.\n"); quest = null;

// execute if (Request { try { Htt Str Cam Con sr. } catch { Con } }

the request != null)

pWebR eamRe eraDe sole. Close

espon ader scrip Write ();

se Re sr = tion Line(

spons new S = sr. Camer

e=( tream ReadL aDesc

HttpW Reade ine() ripti

ebResponse)Request.GetResponse(); r(Response.GetResponseStream()); ; on);

sole.Write("Error getting responce.\n");

Console.Write("Press any key to continue.\n"); Console.ReadKey(); } } }

24 March 2011

36


Santa Barbara Instrument Group

STX HTTP Camera API

Downloading an Image
usi usi usi usi usi usi ng ng ng ng ng ng Sy Sy Sy Sy Sy Sy stem; stem. stem. stem. stem. stem. Collections.Generic; Linq; Text; Net; IO; WebAPITest gram c void Main(string[] args) ttpWebRequest Request;

namespace STX { class Pro { stati { H

try { // Re } catch { Co Re } prepare the web page we will be asking for quest = (HttpWebRequest)WebRequest.Create("http://1.1.1.1/api/ImagerData.bin");

nsole.Write("Error creating request.\n"); quest = null;

// execute if (Request { try { Htt Str Str try {

the request != null)

pWebResponse Response = (HttpWebResponse)Request.GetResponse(); eam ImageStream = Response.GetResponseStream(); eam myFileStream = File.Create("ImagerData.bin");

int Byte int whil {

Lengt [] bu bytes e (by

h=1 ffer Read tesRe

6384; = new = Ima ad >

// 16384 bytes is the most the STX will send at once Byte[Length]; geStream.Read(buffer, 0, Length); 0)

myFileStream.Write(buffer, 0, bytesRead); bytesRead = ImageStream.Read(buffer, 0, Length); } } catch { Console.Write("Error saving file.\n"); } myFileStream.Close(); ImageStream.Close(); } catch { Console.Write("Error getting responce.\n"); } } Console.Write("Press any key to continue.\n"); Console.ReadKey(); } } }

24 March 2011

37


Santa Barbara Instrument Group

STX HTTP Camera API

Full Featured Example
usi usi usi usi usi usi ng ng ng ng ng ng Sy Sy Sy Sy Sy Sy stem; stem. stem. stem. stem. stem. Collections.Generic; Linq; Text; Net; IO; WebAPITest gram c void Main(string[] args) akeImage();

namespace STX { class Pro { stati { T

Console.Write("Press any key to continue."); Console.ReadKey(); } static void TakeImage() { bool RetVal = true; String Response = ""; if (RetVal) { Console.WriteLine("Setting imager parameters."); RetVal = PerformWebRequest("ImagerSetSettings.cgi?StartX=0&StartY=0&NumX=640&NumY=480", ref Response); } if (!R { Co re } else { Co Re } if (!R { Co re } else { in Co do { RetVal = PerformWebRequest("ImagerState.cgi", ref Response); if (RetVal) ImagerState = Convert.ToInt32(Response); } while ((ImagerState != 0) && (ImagerState != 5) && RetVal); // 0 is Idle, 5 is an error if (ImagerState == 5) // Got an error condition { Console.WriteLine("Imager State Error."); return; } } if (RetVal) { Console.WriteLine("Setting FITS parameters."); RetVal = PerformWebRequest("SetFITSSetting.cgi?ObjectName=M27&Observer=SBIG&Telescope=RC10", ref Response); } if (!R { Co re } else { Co Re } if (!R { Co re } else Co } const String HTTPAddressStart = "http://1.1.1.1/api/"; // Perform Web Request and return response in a string // This function is overloaded. static bool PerformWebRequest(String Address, ref String Response) etVal) nsole.WriteLine("Error setting FITS parameters."); turn; etVal) nsole.WriteLine("Error setting parameters."); turn;

nsole.WriteLine("Starting exposure."); tVal = PerformWebRequest("ImagerStartExposure.cgi?Duration=10&FrameType=1", ref Response);

etVal) nsole.WriteLine("Error starting exposure."); turn;

t ImagerState = 5; // 5 is an error condition nsole.WriteLine("Waiting for exposure to finish...");

nsole.WriteLine("Getting image FITS file."); tVal = PerformWebRequest("Imager.FIT", "Imager.FIT");

etVal) nsole.WriteLine("Error getting Imager.FIT."); turn;

nsole.WriteLine("All done.");

24 March 2011

38


Santa Barbara Instrument Group
{ HttpWebRequest Request; try { // Re } catch { // Re re } try { // Get response HttpWebResponse WebResponse = (HttpWebResponse)Request.GetResponse(); if (Web { // Str Res sr. } else { // Res ret } Response.StatusCode == HttpStatusCode.OK) Read eamRe ponse Close response text ader sr = new StreamReader(WebResponse.GetResponseStream()); = sr.ReadToEnd(); (); prepare the web page we will be asking for quest = (HttpWebRequest)WebRequest.Create(HTTPAddressStart + Address);

STX HTTP Camera API

Something failed sponse = ""; turn false;

Camera returned 400 or 404 ponse = ""; urn false;

} catch { // Something failed Response = ""; return false; } return true; } // Pe // Th stati { H rform Web Request and write the response to a file is function is overloaded. c bool PerformWebRequest(String Address, String FileName) ttpWebRequest Request;

try { // prepare the web page we will be asking for Request = (HttpWebRequest)WebRequest.Create(HTTPAddressStart + Address); } catch { // Something failed return false; } try { // Get response HttpWebResponse WebResponse = (HttpWebResponse)Request.GetResponse(); if (Web { // Str Str try { Response.StatusCode == HttpStatusCode.OK) Get data and dump into the file eam ImageStream = WebResponse.GetResponseStream(); eam myFileStream = File.Create(FileName);

int Byte // R int whil {

Lengt [] bu ead d bytes e (by

h=1 ffer ata b Read tesRe

6384; = new lock, = Ima ad >

// 1 Byte then geStr 0)

6384 [Leng writ eam.R

bytes is the most the STX will send at once th]; e data block ead(buffer, 0, Length);

myFil bytes } // All do myFileStr ImageStre } catch { // S myFi Imag retu }

eStream.Write(buffer, 0, bytesRead); Read = ImageStream.Read(buffer, 0, Length); ne, clean up eam.Close(); am.Close();

ometh leStr eStre rn fa

ing failed, close these and return eam.Close(); am.Close(); lse;

} else { // Camera returned 400 or 404 return false; } } catch

24 March 2011

39


Santa Barbara Instrument Group
{ // Something failed return false; } return true; } } }

STX HTTP Camera API

24 March 2011

40


Santa Barbara Instrument Group

STX HTTP Camera API

More Example Conversations
Multiple Parameter Get
Client request: GET /api/ImagerGetSettings.cgi?MaxADU&MaxBinX&MaxBinY &PixelSizeX HTTP/1.0

STX response: HTTP/1.0 200 OK Content-Type: text/plain Content-Length: 19 65535 9 9 9.00

No Valid Parameter Error
Client request: GET /api/ImagerGetSettings.cgi HTTP/1.0

STX response: HTTP/1.0 400 Bad Request Content-Type: text/plain Content-Length: 33 0x80001000 No valid parameter.

24 March 2011

41


Santa Barbara Instrument Group

STX HTTP Camera API

Successful Conversion with No Data
Client request: GET /api/ImagerSetSettings.cgi?BinX=1 HTTP/1.0

STX response: HTTP/1.0 200 OK Content-Type: text/plain Content-Length: 0

24 March 2011

42


Santa Barbara Instrument Group

STX HTTP Camera API

Revision History
This section details the recent changes to this specification since the initial release. Changes Incorporated in Version 1.00.1: · Added Revision History. · Added HTTP Command Interval restriction.

24 March 2011

43