Using the SLSC Web API

Overview

Starting from the 18.0 release, NI-SLSC creates a web server on the SLSC chassis and provides a web API to create web clients that communicate with the SLSC chassis. The web API supports various platforms, such as Linux and OS X, and different programming languages, such as LabVIEW, Python, C++, and C#.

Contents

Introduction to the Web API

You can configure the SLSC chassis by using the web API to create web clients that send HTTP POST requests to the URL of the web server on the SLSC chassis. The web server returns HTTP responses. The body of the HTTP request and response follows the JSON-RPC 2.0 Specification

The format of the URL of the web server is http://<IP address or hostname of the web server>/nislsc/call. For example, a URL can be http://10.144.160.151/nislsc/call, where 10.144.160.151 is the IP address of the web server. A URL can also be http://SLSC-12001-030FD4DE/nislsc/call, where SLSC-12001-030FD4DE is the hostname of the web server.

The following example shows the body of a request:

{
   "id": "1",
   "jsonrpc": "2.0",
   "method": "initializeSession",
   "params":
   {
       "devices": "SLSC-12001-030898C6-Mod2"
   }
}

The following table lists the members in the request. These members follow the JSON-RPC 2.0 specification.

Table 1. Members in a request of the SLSC web API

NameJSON Data TypeRequired or OptionalDescription
idString or Number (integer)RequiredIdentifier that the client establishes.
jsonrpcStringRequiredVersion of the JSON-RPC protocol and must be 2.0.
methodStringRequiredName of the method to invoke.
paramsObjectOptionalParameter values for the method. You may omit this member only if there are no parameters.

 

The following example shows the body of the response without errors:

{
   "id": "1",
   "jsonrpc": "2.0",
   "result":
   {
       "session_id": "_session99"
   }
}

The following examples show the body of the response with errors:

{
   "jsonrpc": "2.0",
   "id": null,
   "error": {
       "code": -32700,
       "message": "Invalid JSON was received by the server. An error occurred on the server while parsing the JSON text.  Details: Invalid value. Offset: 148"
   }
}

 

{
   "jsonrpc": "2.0",
   "id": "1",
   "error": {
       "code": -32000,
       "message": "SLSC error.",
       "data": {
           "nislsc_code": -250806,
           "nislsc_message": "The specified device was not found.  Device: SLSC-12001-030898C6-Mod2"
       }
   }
}

 

The following tables explain the members in the response. These members follow the JSON-RPC 2.0 specification.

Table 2. Members in a response of the SLSC web API without errors

NameJSON Data TypeDescription
idString or Number (integer)Same as the value of the id member in the request. If the JSON format of the request body is invalid, id returns null.
jsonrpcStringVersion of the JSON-RPC protocol and must be 2.0.
resultObjectResponse from the web server.

 

Table 3. Members in a response of the SLSC web API with errors

NameJSON Data TypeDescription
idString or Number (integer)Same as the value of the id member in the request. If the JSON format of the request body is invalid, id returns null.
jsonrpcStringVersion of the JSON-RPC protocol and must be 2.0.
errorObjectError that the web server returns.

 

The error member includes the following objects:

Table 4. Objects in the error member

NameJSON Data TypeDescription
codeNumber (integer)Number that indicates the error type.
messageStringShort description of the error.
dataObjectAdditional information about the error. This member also includes two objects: nislsc_code and nislsc_message. nislsc_code is a number that indicates the error code. nislsc_message indicates the description of the error.

 

Batch Request and Response

Following the JSON-RPC 2.0 specification, a batch request can send several methods in one request. However, the web server handles batch requests differently from the JSON-RPC 2.0 specification in the following ways:

  • The web server handles the methods in a batch request in sequence.
  • The web server can handle only one batch request at a time. When the web server is handling a batch request, any other single or batch request is blocked until the current batch request is complete. However, the web server can handle multiple single requests at a time.
  • If a method in the batch request returns an error, the web server returns errors for all methods that follow.

The following example shows a batch request:

[
   { "id": "2", "jsonrpc": "2.0", "method": "readRegister", "params": { "session_id": "_session0", "register_address": 256 } },
   { "id": "3", "jsonrpc": "2.0", "method": "getProperty:", "params": { "session_id": "_session0", "property": "NI.Debug.Led0Bool" } },
   { "id": "4", "jsonrpc": "2.0", "method": "executeCommand", "params": { "session_id": "_session0", "command": "NI.Debug.EnableLED0Immediate"} }
]

The following example shows the batch response without errors:

[
   { "id": "2", "jsonrpc": "2.0", "result": { "data": 128 } },
   { "id": "3", "jsonrpc": "2.0", "result": { "value": false } },
   { "id": "4", "jsonrpc": "2.0", "result": {} }
]

The following example shows the batch response with errors:

[
   { "id": "2", "jsonrpc": "2.0", "result": { "data": 128 } },
   { "id": "3", "jsonrpc": "2.0", "error": { "code": -32000, "message": "SLSC error", "data": { "nislsc_code": -250893, "nislsc_message": "Chassis power-on hours property write failed." } } },
   { "id": "4", "jsonrpc": "2.0", "error": { "code": -32001, "message": "Error occurred in previous request."} }
]

 

SLSC Web API Error Codes

The following table lists SLSC web API error codes. The JSON-RPC 2.0 specification defines all SLSC web API error codes except -32000 and -32001.

Table 5. SLSC web API error codes

CodeMessageDescription
-32700Parse errorThe JSON in the request is not valid.
-32600Invalid requestThe JSON in the request is not a valid Request object.
-32601Method not foundThe method does not exist or is not available.
-32602Invalid paramsInvalid method parameters.
-32603Internal errorInternal JSON-RPC error.
-32001SLSC errorAn error occurs in the previous request.
-32000SLSC errorSLSC error.

 

Enum Values

If the data type of a parameter in an HTTP request is enum, you can specify the parameter with a key or value. The key must be a String and the value must be a Number.

 

Static and Dynamic Properties

There are two categories of properties in the web API: static properties and dynamic properties. Static properties are defined by the SLSC driver, whereas dynamic properties are defined by the user of the SLSC device. You can find dynamic properties in the SLSC module capabilities. You can use the getDevicePropertyList method to get both static and dynamic properties.

 

Using the Default Value of a Parameter

To use the default value of a parameter, you can specify an alias for the parameter, remove the parameter, or specify an empty string for the parameter.

 

Specifying an Alias for a Parameter

You can specify an alias for the parameter to explicitly use the default value of a member. Aliases are special names that start with a $ sign:

  • $DefaultDevices–Default devices of the session.
  • $DefaultNVMEMAreas–Default NVMEM areas of the session.
  • $DefaultPhysChans–Default physical channels of the session.

The following example uses an alias to specify the default devices of the session:

{
   "id": "4",
   "jsonrpc": "2.0",
   "method": "connectToDevices",
   "params":
   {
       "session_id": "_session0",
       "devices": "$DefaultDevices"
   }
}

 

Removing a Parameter from a Request

The following example removes the devices parameter from the request to use the default devices of the session:

{
   "id": "4",
   "jsonrpc": "2.0",
   "method": "connectToDevices",
   "params":
   {

       "session_id": "_session0"
   }
}

 

Specifying an Empty String for a Parameter

The following example specifies an empty string for the parameter to use the default devices of the session:

{
   "id": "4",
   "jsonrpc": "2.0",
   "method": "connectToDevices",
   "params":
   {
       "session_id": "_session0",
       "devices": ""
   }
}

 

 

Web API Method Reference

You can use the following methods to manipulate the SLSC chassis and modules:

You can also refer to the attachment for examples of requests and responses, schema files, and default values.

 

abortSession

Cancels a method that blocks network communications. 

 

Parameters

ParameterRequired or OptionalJSON Data TypeDefault ValueDescription
session_idRequiredString ID of the session.

 

After aborting the session, the session handle remains valid, but methods that access network connections return errors. To recover from an aborted session, close the session and initialize a new one.

 

Example

The following example shows a request:

{
   "id": "3",
   "jsonrpc": "2.0",
   "method": "abortSession",
   "params":
   {
       "session_id": "_session0"
   }
}

The following example shows the response:

{
   "id": "3",
   "jsonrpc": "2.0",
   "result": {}
}

Back to Web API Method Reference 

closeSession

Closes an SLSC session.

 

Parameters

ParameterRequired or OptionalJSON Data TypeDefault ValueDescription
session_idRequiredString ID of the session.

 

Example

The following example shows a request:

{
   "id": "2",
   "jsonrpc": "2.0",
   "method": "closeSession",
   "params":
   {
       "session_id": "_session0"
   }
}

The following example shows the response:

{
   "id": "2",
   "jsonrpc": "2.0",
   "result": {}
}

Back to Web API Method Reference 

connectToDevices

Connects to an SLSC device.

 

Parameters

 

ParameterRequired or OptionalJSON Data TypeDefault ValueDescription
session_idRequiredString ID of the session.
devicesOptionalString or array of StringsDefault devices of the session

Device names. You can specify one or multiple devices.

If the data type is String, you can use comma-delimited format to specify multiple devices.

 

 

Example

The following example shows a request:

{
   "id": "4",
   "jsonrpc": "2.0",
   "method": "connectToDevices",
   "params":
   {
       "session_id": "_session0",
       "devices":
       [
           "SLSC-12001-030898C6-Mod1",
           "SLSC-12001-030898C6-Mod2"
       ]
   }
}

The following example shows the response:

{
   "id": "4",
   "jsonrpc": "2.0",
   "result": {}
}

Back to Web API Method Reference 

disconnectFromDevices

Closes network connections for one or multiple devices.

 

Parameters

ParameterRequired or OptionalJSON Data TypeDefault ValueDescription
session_idRequiredString ID of the session.
devicesOptionalString or array of StringsDefault devices of the session

Device names. You can specify one or multiple devices.

If the data type is String, you can use comma-delimited format to specify multiple devices.

 

If multiple devices share a network connection because they are in the same SLSC chassis, the network connection remains open until the last device is disconnected.

 

Example

The following example shows a request:

{
   "id": "5",
   "jsonrpc": "2.0",
   "method": "disconnectFromDevices",
   "params":
   {
       "session_id": "_session0",
       "devices":
       [
           "SLSC-12001-030898C6-Mod1",
           "SLSC-12001-030898C6-Mod2"
       ]
   }
}

The following example shows the response:

{
   "id": "5",
   "jsonrpc": "2.0",
   "result": {}
}

Back to Web API Method Reference

initializeSession

Initializes an SLSC session.

 

Parameters

ParameterRequired or OptionalJSON Data TypeDefault ValueDescription
devicesOptionalString or array of Strings 

Device names. You can specify one or multiple devices.

If the data type is String, you can use comma-delimited format to specify multiple devices.

physical_channelsOptionalString or array of Strings 

Physical channel names. You can specify one or multiple physical channels.

If the data type is String, you can use comma-delimited format to specify physical channels.

nvmem_areasOptionalString or array of Strings 

NVMEM area names. You can specify one or multiple NVMEM areas.

If the data type is String, you can use comma-delimited format to specify multiple NVMEM areas.

accessOptionalEnumReadWriteAccess mode to reserve devices.
reservation_groupOptionalString""Name of the group that allows multiple sessions to simultaneously reserve the same devices.
reservation_timeoutOptionalFloat0.0

Maximum amount of time, in seconds, to wait to reserve a device that has been reserved by other sessions with ReadWrite access.

To reserve a device that has been reserved by another session with ReadWrite access, you can close the session, unreserve the device, or use the same reservation group name as that of the device. You can directly reserve a device that has been reserved by another session with ReadOnly access.

If reservation_timeout is 0, this method returns an error when a session tries to reserve a module that has been reserved by another session.

force_reserveOptionalBooleanFalseWhether to force to close all sessions created by the web server that reserves this resource.

 

If reservation_timeout is greater than 0 and access is ReadWrite, a circular waiting may occur when multiple sessions try to reserve multiple devices. The following table shows a circular waiting that occurs when two sessions try to reserve two modules.

 

Session 1Session 2
Reserve module 1Reserve module 2
Try to reserve module 2Try to reserve module 1
Wait for module 2Wait for module 1

 

Both session 1 and session 2 return errors when timeout expires. To avoid the circular waiting, ensure that session 1 and session 2 reserve modules in the same order. If session 1 reserves module 1 first and then reserves module 2, ensure that session 2 also reserves module 1 first and then reserves module 2.

The following table shows the keys and values of the access parameter.

 

KeyValue
ReadOnly1
ReadWrite3

 

You can specify only one of the following three parameters in one request: devicesphysical_channels, and nvmem_areas. If you do not specify any of the three parameters, this method initializes the session with no resources.

The following table lists the return values.

 

Return ValueJSON Data TypeDescription
session_idStringID of the session.

 

Example

The following example shows a request without resources. You can also omit the params member.

{
   "id": "1",
   "jsonrpc": "2.0",
   "method": "initializeSession",
   "params": {}
}

The following example shows a request with resources:

{
   "id": "1",
   "jsonrpc": "2.0",
   "method": "initializeSession",
   "params":
   {
       "devices":
       [
           "SLSC-12001-030898C6-Mod2",
           "SLSC-12001-030898C6-Mod3"
       ],
       "access": "ReadWrite",
       "reservation_group": "nitest"
   }
}

The following example shows the response:

{
   "id": "1",
   "jsonrpc": "2.0",
   "result":
   {
       "session_id": "_session0"
   }
}

Back to Web API Method Reference 

renameDevice

Renames a device.

 

Parameters

ParameterRequired or OptionalJSON Data TypeDefault ValueDescription
session_idRequiredString ID of the session.
deviceRequiredString Device name. You can specify only one device name.
new_device_nameRequiredString New name for the device.

 

Example

The following example shows a request:

{
   "id": "9",
   "jsonrpc": "2.0",
   "method": "renameDevice",
   "params":
   {
       "session_id": "_session0",
       "device": "SLSC-12001-030898C6",
       "new_device_name": "SLSC-12001-TEST"
   }
}

The following example shows the response:

{
   "id": "9",
   "jsonrpc": "2.0",
   "result": {}
}

Back to Web API Method Reference

reserveDevices

Reserves one or multiple devices to prevent other sessions from accessing the devices. You must reserve a device before using it. To reserve a device that has been reserved by another session with ReadWrite access, you can close the session, unreserve the device, or use the same reservation group name as that of the device. You can directly reserve a device that has been reserved by another session with ReadOnly access.

 

Parameters

ParameterRequired or OptionalJSON Data TypeDefault ValueDescription
session_idRequiredString ID of the session.
devicesOptionalString or array of StringsDefault devices of the session

Device names. You can specify one or multiple devices.

If the data type is String, you can use comma-delimited format to specify multiple devices.

accessOptionalEnumReadWriteAccess mode to reserve devices.
reservation_groupOptionalString""Name of the group that allows multiple sessions to simultaneously reserve the same devices.
reservation_timeoutOptionalNumber (float)0.0

Maximum amount of time, in seconds, to wait to reserve a device that has been reserved by other sessions with ReadWrite access. 

If reservation_timeout is 0, this method returns an error when a session tries to reserve a module that has been reserved by another session.

If reservation timeout is -1, reservation timeout uses the value of the Session.ReservationTimeout property. 

 

The following table shows the keys and values of the access parameter.

 

KeyValue
ReadOnly1
ReadWrite3

 

If reservation_timeout is greater than 0 and access is ReadWrite, a circular waiting may occur when multiple sessions try to reserve multiple devices. The following table shows a circular waiting that occurs when two sessions try to reserve two modules.

 

Session 1Session 2
Reserve module 1Reserve module 2
Try to reserve module 2Try to reserve module 1
Wait for module 2Wait for module 1

 

Both session 1 and session 2 return errors when timeout expires. To avoid the circular waiting, ensure that session 1 and session 2 reserve modules in the same order. If session 1 reserves module 1 first and then reserves module 2, ensure that session 2 also reserves module 1 first and then reserves module 2.

 

Example

The following example shows a request:

{
   "id": "6",
   "jsonrpc": "2.0",
   "method": "reserveDevices",
   "params":
   {
       "session_id": "_session0",
       "devices":
       [
           "SLSC-12001-030898C6-Mod1",
           "SLSC-12001-030898C6-Mod2"
       ],
       "access": "ReadWrite",
       "reservation_group": "nitest"
   }
}

The following example shows the response:

{
   "id": "6",
   "jsonrpc": "2.0",
   "result": {}
}

Back to Web API Method Reference

resetDevices

Resets devices to default state. This method sends the specified modules a software reset signal, reinitializes module registers to their initial value, and rereads the module's non-volatile memory. If you specify a chassis, this method resets all modules in the chassis.

 

Parameters

ParameterRequired or OptionalJSON Data TypeDefault ValueDescription
session_idRequiredString ID of the session.
devicesOptionalString or array of StringsDefault devices of the session

Device names. You can specify one or multiple devices.

If the data type is String, you can use comma-delimited format to specify multiple devices.

 

Example

The following example shows a request:

{
   "id": "8",
   "jsonrpc": "2.0",
   "method": "resetDevices",
   "params":
   {
       "session_id": "_session0",
       "devices":
       [
           "SLSC-12001-030898C6-Mod1",
           "SLSC-12001-030898C6-Mod2"
       ]
   }
}

The following example shows the response:

{
   "id": "8",
   "jsonrpc": "2.0",
   "result": {}
}

Back to Web API Method Reference

unreserveDevices

Unreserves one or multiple devices so that other sessions can reserve them.

 

Parameters

ParameterRequired or OptionalJSON Data TypeDefault ValueDescription
session_idRequiredString ID of the session.
devicesOptionalString or array of StringsDefault devices of the session

Device names. You can specify one or multiple devices.

If the data type is String, you can use comma-delimited format to specify multiple devices.

 

Example

The following example shows a request:

{
   "id": "7",
   "jsonrpc": "2.0",
   "method": "unreserveDevices",
   "params":
   {
       "session_id": "_session0",
       "devices":
       [
           "SLSC-12001-030898C6-Mod1",
           "SLSC-12001-030898C6-Mod2"
       ]
   }
}

The following example shows the response:

{
   "id": "7",
   "jsonrpc": "2.0",
   "result": {}
}

Back to Web API Method Reference

commitProperties

Commits properties with pending changes to SLSC hardware. You must commit dynamic properties for the changes to take effect. You do not have to commit static properties because changes take effect immediately after you set static properties. If you set a property multiple times before you commit the property, this method commits only the last value. 

 

Parameters

ParameterRequired or OptionalJSON Data TypeDefault ValueDescription
session_idRequiredString ID of the session.
devicesOptionalString or array of StringsDefault devices of the session

Device names. You can specify one or multiple devices.

If the data type is String, you can use comma-delimited format to specify multiple devices.

physical_channelsOptionalString or array of StringsDefault physical channels of the session

Physical channel names. You can specify one or multiple physical channels.

If the data type is String, you can use comma-delimited format to specify multiple physical channels.

 

You can specify only one of the following two parameters in one request: devices and physical_channels. If you do not specify any of the two parameters, the method performs the following operation:

  • If the session is initialized with devices or physical channels, use default devices or physical channels of the session.

 

Example

The following example shows a request:

{
   "id": "14",
   "jsonrpc": "2.0",
   "method": "commitProperties",
   "params":
   {
       "session_id": "_session0",
       "devices":
       [
           "SLSC-12001-030898C6-Mod1",
           "SLSC-12001-030898C6-Mod2"
       ]
   }
}

The following example shows the response:

{
   "id": "14",
   "jsonrpc": "2.0",
   "result": {}
}

Back to Web API Method Reference

 

getDevicePropertyList

Lists all device properties. The following table lists the parameters of this method.

 

Parameters

ParameterRequired or OptionalJSON Data TypeDefault ValueDescription
session_idRequiredString ID of the session.
deviceOptionalStringDefault device of the sessionDevice name. You can specify only one device name.
physical_channelOptionalStringDefault physical channel of the sessionPhysical channel name. You can specify only one physical channel.
nvmem_areaOptionalStringDefault NVMEM area of the sessionNVMEM area name. You can specify only one NVMEM area.

 

You can specify only one of the following three parameters in one request: device, physical_channel, and nvmem_area. If you do not specify any of the three parameters, the method performs the following operation:

  • If the session is initialized with device or physical channel, use default device or physical channel of the session for device or physical_channel.

 

Example

The following example shows a request with the device parameter:

{
   "id": "11",
   "jsonrpc": "2.0",
   "method": "getDevicePropertyList",
   "params":
   {
       "session_id": "_session0",
       "device": "SLSC-12001-030898C6-Mod1"
   }
}

The following example shows the response:

{
   "id": "11",
   "jsonrpc": "2.0",
   "result":
   {
       "static_properties":
       [
           "Dev.CapsVersion",
           "Dev.Chassis",
           "Dev.Commands",
           "Dev.Descr",
           "Dev.Events",
           "Dev.FirmwareVersion",
           "Dev.HardwareVersion",
           "Dev.Modules",
           "Dev.NumSlots",
           "Dev.NVMEM.Areas",
           "Dev.NVMEM.Size",
           "Dev.PhysChans",
           "Dev.ProductCategory",
           "Dev.ProductName",
           "Dev.ProductNum",
           "Dev.Properties",
           "Dev.SerialNum",
           "Dev.SlotNum",
           "Dev.TCPIP.EthernetIP",
           "Dev.TCPIP.EthernetMAC",
           "Dev.TCPIP.Hostname",
           "Dev.VendorName",
           "Dev.VendorNum"
       ],
       "dynamic_properties":
       [
           "NI.DateCode",
           "NI.Debug.Alphabet",
           "NI.Debug.LED0Bool",
           "NI.Debug.LED1Bool",
           "NI.Debug.LED2Bool"
       ]
   }
}

Back to Web API Method Reference

getProperty

Gets properties for devices or physical channels.

 

Parameters

ParameterRequired or OptionalJSON Data TypeDefault ValueDescription
session_idRequiredString ID of the session.
devicesOptionalString or array of StringsDefault devices of the session

Device names. You can specify one or multiple devices.

If the data type is String, you can use comma-delimited format to specify multiple devices.

physical_channelsOptionalString or array of StringsDefault physical channels of the session

Physical channel names. You can specify one or multiple physical channels.

If the data type is String, you can use comma-delimited format to specify multiple physical channels.

nvmem_areasOptionalString or array of StringsDefault NVMEM areas of the session.

NVMEM area names. You can specify one or multiple NVMEM areas.

If the data type is String, you can use comma-delimited format to specify multiple NVMEM areas.

propertyRequiredString Name of the property.

 

You can specify only one of the following two parameters in one request: devices and physical_channels. If you do not specify any of the two parameters, the method performs operations in the following order:

  1. Searches for the property in the list of system properties and session properties. If the property belongs to system property or session property, this method gets the value of the property.
  2. If the property is not in the list of system properties and session properties and the session is initialized with devices, physical channels, or NVMEM areas, this method uses default devices, physical channels, or NVMEM areas of the session.

The following table lists the return values.

 

Return ValueJSON Data TypeMeaning
data_typeEnumData type of the property.
valueThe JSON data type depends on the data type of the property.Value of the property.

 

The following table lists keys and values for the data_type return value.

 

KeyValueJSON Data Type
Bool1Boolean
Double2Number (float)
Int323Number (integer)
Int644Number (integer)
String5String
UInt326Number (integer)
UInt647Number (integer)
BoolArray8Array of Booleans
DoubleArray9Array of Numbers (float)
Int32Array10Array of Numbers (integer)
Int64Array11Array of Numbers (integer)
StringArray12Array of Strings
UInt32Array13Array of Numbers (integer)
UInt64Array14Array of Numbers (integer)

 

Example

The following example shows a request to get properties from multiple devices:

{
   "id": "12",
   "jsonrpc": "2.0",
   "method": "getProperty",
   "params":
   {
       "session_id": "_session0",
       "devices":
       [
           "SLSC-12001-030898C6-Mod1",
           "SLSC-12001-030898C6-Mod2"
       ],
       "property": "NI.DebugLED0"
   }
}

The following example shows the response:

{
   "id": "12",
   "jsonrpc": "2.0",
   "result":
   {
       "data_type": "Bool",
       "value":
       [
           false,
           true
       ]
   }
}

The following example shows a request to get properties from multiple physical channels:

{
   "id": "12",
   "jsonrpc": "2.0",
   "method": "getProperty",
   "params":
   {
       "session_id": "_session0",
       "physical_channels":
       [
           "SLSC-12001-030898C6-Mod1/LED0",
           "SLSC-12001-030898C6-Mod1/LED1"
       ],
       "property": "NI.ChannelName"
   }
}

The following example shows the response:

{
   "id": "12",
   "jsonrpc": "2.0",
   "result":
   {
       "data_type": "String",
       "value":
       [
           "LED0",
           "LED1"
       ]
   }
}

Back to Web API Method Reference

getPropertyInformation

Gets all information of a property. 

 

Parameters

ParameterRequired or OptionalJSON Data TypeDefault ValueDescription
session_idRequiredString ID of the session.
deviceOptionalStringDefault device of the sessionDevice name. You can specify only one device name.
physical_channelOptionalStringDefault physical channel of the sessionPhysical channel name. You can specify only one physical channel.
nvmem_areaOptionalStringDefault physical channel of the sessionNVMEM area name. You can specify only one NVMEM area.
propertyRequiredString Name of the property.

 

You can specify only one of the following three parameters in one request: device, physical_channel, and nvmem_area. If you do not specify any of the three parameters, the method performs operations in the following order:

  1. Search for the property in the list of system properties and session properties. If the property belongs to system property or session property, this method gets the value of the property.
  2. If the property is not in the list of system properties and session properties and the session is initialized with devices, physical channels, or NVMEM areas, use default devices, physical channels, or NVMEM areas of the session.

 

Example

The following example shows a request for a static property:

{
 "id": "15",
 "jsonrpc": "2.0",
 "method": "getPropertyInformation",
 "params":
 {
   "session_id": "_session1",
   "device": "SLSC-12001-030FD4DE",
   "property": "Dev.FirmwareVersion"
 }
}

The following example shows the response for the static property:

{
   "jsonrpc": "2.0",
   "id": "15",
   "result": {
       "description": "Firmware Version",
       "document": "Indicates the firmware version for the device.",
       "data_type": "String",
       "access": "ReadOnly",
       "driver_defined": true,
       "pending_changes": false
   }
}

The following example shows a request for a dynamic property:

{
   "id": "15",
   "jsonrpc": "2.0",
   "method": "getPropertyInformation",
   "params":
   {
       "session_id": "_session0",
       "device": "SLSC-12001-030898C6-Mod2",
       "property": "NI.Debug.LED0Bool"
   }
}

The following example shows the response for the dynamic property:

{
   "id": "15",
   "jsonrpc": "2.0",
   "result": {
       "description": "One of 4 blue LEDs with Bool data type.",
       "documentation": "Towards back of module, under 2 caps, LED on far right",
       "unit": "",
       "min_value": false,
       "max_value": true,
       "access": "ReadWrite",
       "data_type": "Bool",
       "is_enum": false,
       "pending_changes": false
   }
}

Back to Web API Method Reference

getSessionPropertyList

Lists all session properties. The response of this method is static.

 

Parameters

ParameterRequired or OptionalJSON Data TypeDefault ValueDescription
session_idRequiredString ID of the session.

 

 

Example

The following example shows a request:

{
   "id": "10",
   "jsonrpc": "2.0",
   "method": "getSessionPropertyList",
   "params":
   {
       "session_id": "_session0"
   }
}

The following example shows the response:

{
   "id": "10",
   "jsonrpc": "2.0",
   "result":
   {
       "properties":
       [
           "Sys.Chassis",
           "Sys.DeviceProperties",
           "Sys.Devices",
           "Sys.Modules",
           "Sys.NVMEMAreaProperties",
           "Sys.PhysChanProperties",
           "Sys.SessionProperties",
           "Sys.SystemProperties",
           "Session.ConnectedDevices",
           "Session.DefaultDevices",
           "Session.DefaultNVMEMAreas",
           "Session.DefaultPhysChans",
           "Session.ReservedDevices"
       ]
   }
}

Back to Web API Method Reference

setProperty

Sets properties for devices or physical channels. You must commit dynamic properties for the changes to take effect. You do not have to commit static properties. You can set only one property for one or multiple devices or physical channels.

 

Parameters

ParameterRequired or OptionalJSON Data TypeDefault ValueDescription
session_idRequiredString ID of the session.
devicesOptionalString or array of StringsDefault devices of the session

Device names. You can specify one or multiple devices.

If the data type is String, you can use comma-delimited format to specify multiple devices.

physical_channelsOptionalString or array of StringsDefault physical channels of the session

Physical channel names. You can specify one or multiple physical channels.

If the data type is String, you can use comma-delimited format to specify multiple physical channels.

propertyRequiredString Name of the property.
valueRequiredThe JSON data type depends on the data type of the property. Value of the property.

 

You can specify only one of the following two parameters in one request: devices and physical_channels. If you do not specify any of the two parameters, this method performs operations in the following order:

  1. Search for the property in the list of system properties and session properties. If the property belongs to system property or session property, this method sets the value of the property.
  2. If the property is not in the list of system properties and session properties and the session is initialized with devices or physical channels, use default devices or physical channels of the session.

 

Example

The following example shows a request:

{
   "id": "13",
   "jsonrpc": "2.0",
   "method": "setProperty",
   "params":
   {
       "session_id": "_session0",
       "property": "NI.DebugLED0",
       "devices":
       [
           "SLSC-12001-030898C6-Mod1",
           "SLSC-12001-030898C6-Mod2"
       ],
       "value":
       [
           true,
           false
       ]
   }
}

The following example shows the response:

{
   "id": "13",
   "jsonrpc": "2.0",
   "result": {}
}

Back to Web API Method Reference

executeCommand

Executes command on one or more devices or physical channels.

 

Parameters

ParameterRequired or OptionalJSON Data TypeDefault ValueDescription
session_idRequiredString ID of the session.
devicesOptionalString or array of StringsDefault devices of the session

Device names. You can specify one or multiple devices.

If the data type is String, you can use comma-delimited format to specify multiple devices.

physical_channelsOptionalString or array of StringsDefault physical channels of the session

Physical channel names. You can specify one or multiple physical channels.

If the data type is String, you can use comma-delimited format to specify multiple physical channels.

commandRequiredString Name of command to execute.
timeoutOptionalNumber (float)10.0Maximum amount of time, in seconds, to wait for the operation to complete.

 

You can specify only one of the following two parameters in one request: devices and physical_channels.

 

Example

The following example shows a request:

{
   "id": "17",
   "jsonrpc": "2.0",
   "method": "executeCommand",
   "params":
   {
       "session_id": "_session0",
       "devices":
       [
           "SLSC-12001-030898C6-Mod1",
           "SLSC-12001-030898C6-Mod2"
       ],
       "command": "NI.EnableLed0Immediate",
       "timeout": 10.0
   }
}

The following example shows the response:

{
   "id": "17",
   "jsonrpc": "2.0",
   "result": {}
}

Back to Web API Method Reference

getCommandInformation

Gets all information of a command. 

 

Parameters

ParameterRequired or OptionalJSON Data TypeDefault ValueDescription
session_idRequiredString ID of the session.
deviceOptionalStringDefault device of the sessionDevice name. You can specify only one device name.
physical_channelOptionalStringDefault physical channel of the sessionPhysical channel name. You can specify only one physical channel.
commandRequiredString Name of command.

 

You must specify one and only one of the following two parameters in one request: device and physical_channel.

 

Example

The following example shows a request:

{
   "id": "18",
   "jsonrpc": "2.0",
   "method": "getCommandInformation",
   "params":
   {
       "session_id": "_session0",
       "device": "SLSC-12001-030898C6-Mod2",
       "command": "NI.EnableLed0Immediate"
   }
}

The following example shows the response:

{
   "id": "18",
   "jsonrpc": "2.0",
   "result": {
       "description": "Enable LED 0 and complete immediately.",
       "documentation": "Enable LED 0 and complete immediately (doc)."
   }
}

Back to Web API Method Reference

getCommandList

Lists all commands of a device or physical channel. 

 

Parameters

ParameterRequired or OptionalJSON Data TypeDefault ValueDescription
session_idRequiredString ID of the session.
deviceOptionalStringDefault device of the sessionDevice name. You can specify only one device name.
physical_channelOptionalStringDefault physical channel of the sessionPhysical channel name. You can specify only one physical channel.

 

You can specify only one of the following two parameters in one request: device and physical_channel.

 

Example

The following example shows a request to get all commands of a device:

{
   "id": "16",
   "jsonrpc": "2.0",
   "method": "getCommandList",
   "params":
   {
       "session_id": "_session0",
       "device": "SLSC-12001-030898C6-Mod1"
       ]
   }
}

The following example shows the response:

{
   "id": "16",
   "jsonrpc": "2.0",
   "result":
   {
       "commands":
       [
           "NI.EnableLed0Immediate",
           "NI.EnableLed0Delay",
           "NI.EnableLed0Poll",
           "NI.Event0TimerExpirationInterrupt",
           "NI.Event1TimerExpirationInterrupt",
           "NI.Event2TimerExpirationInterrupt",
           "NI.Event3TimerExpirationInterrupt"
       ]
   }
}

The following example shows a request to get all commands of a physical channel:

{
   "id": "16",
   "jsonrpc": "2.0",
   "method": "getCommandList",
   "params":
   {
       "session_id": "_session0",
       "physical_channel": "SLSC-12001-030898C6-Mod1/EventCounter0"
   }
}

The following example shows the response:

{
   "id": "16",
   "jsonrpc": "2.0",
   "result":
   {
       "commands":
       [
           "NI.EventCounter.Run",
           "NI.EventCounter.RunAsync",
           "NI.EventCounter.RunAndPoll"
       ]
   }
}

Back to Web API Method Reference

commitNvmemAreas

Commits pending changes to hardware for one or multiple NVMEM areas. If you set the same address multiple times before you commit the value, this method only commits the last value.

 

Parameters

ParameterRequired or OptionalJSON Data TypeDefault ValueDescription
session_idRequiredString ID of the session.
nvmem_areasOptionalString or array of StringsDefault NVMEM areas of the session

NVMEM area name. You can specify one or multiple NVMEM area names.

If the data type is String, you can use comma-delimited format to specify multiple NVMEM areas.

devicesOptionalString or array of StringsDefault devices of the session

Device name. You can specify one or multiple devices.

If the data type is String, you can use comma-delimited format to specify multiple devices.

 

Example

The following example shows a request:

{
   "id": "23",
   "jsonrpc": "2.0",
   "method": "commitNvmemAreas",
   "params":
   {
       "session_id": "_session0",
       "nvmem_areas":
       [
           "SLSC-12001-030898C6-Mod1/identification",
           "SLSC-12001-030898C6-Mod1/capabilities"
       ]
   }
}

The following example shows the response:

{
   "id": "23",
   "jsonrpc": "2.0",
   "result": {}
}

Back to Web API Method Reference

getNvmemBytes

Reads the specific number of bytes starting from the given address within an NVMEM area. 

 

Parameters

ParameterRequired or OptionalJSON Data TypeDefault ValueDescription
session_idRequiredString ID of the session.
nvmem_areaOptionalStringDefault NVMEM area of the sessionNVMEM area name. You can specify only one NVMEM area name.
addressRequiredNumber (integer) Starting address within the NVMEM area to read data.
sizeRequiredNumber (integer) Number of bytes to read from the starting address within the NVMEM area.

 

The following table lists the return value of this method.

 

Return ValueData TypeMeaning
next_addressNumber (integer)Starting address plus data size. You can use this value when accessing continuous fields.

 

Example

The following example shows a request:

{
   "id": "21",
   "jsonrpc": "2.0",
   "method": "getNvmemBytes",
   "params":
   {
       "session_id": "_session0",
       "nvmem_area": "SLSC-12001-030898C6/raw",
       "address": 65536,
       "size": 16
   }
}

The following example shows the response:

{
   "id": "21",
   "jsonrpc": "2.0",
   "result": {
       "data": [37, 80, 68, 70, 45, 49, 46, 213, 183, 23, 92, 12, 255, 255, 255, 255],
       "next_address": 65537
   }
}

Back to Web API Method Reference

setNvmemBytes

Sets the number of bytes of data to write to the given address within an NVMEM area. If you set the same address multiple times before you commit the value, this method only commits the last value. Some areas in the NVMEM of an SLSC module may be protected. You need to specify a serial number and password to write to protected areas. The following table lists the parameters of this method.

 

Parameters

ParameterRequired or OptionalJSON Data TypeDefault ValueDescriptionSupported NI-SLSC Version
session_idRequiredString ID of the session.18.0 or later
nvmem_areaOptionalStringDefault NVMEM area of the sessionNVMEM area name. You can specify only one NVMEM area name.18.0 or later
addressRequiredNumber (integer) Starting address within the NVMEM area to read data.18.0 or later
dataRequiredArray of Numbers (8-bit) Number of bytes to read from the starting address within the NVMEM area.18.0 or later
passwordOptionalStringEmpty stringPassword of the NVMEM area. Do not specify this input if the NVMEM area is not protected.18.5 or later
serial_numberOptionalStringEmpty stringSerial number of the hardware. Do not specify this input if the NVMEM area is not protected.18.5 or later

 

The following table lists the return value of this method.

 

Return ValueData TypeMeaning
next_addressNumber (integer)Data address plus data size. You can use this value when accessing continuous fields.

 

Example

The following example shows a request:

{
   "id": "22",
   "jsonrpc": "2.0",
   "method": "setNvmemBytes",
   "params":
   {
       "session_id": "_session0",
       "nvmem_area": "SLSC-12001-030898C6/raw",
       "address": 65536,
       "data": [37, 80, 68, 70, 45, 49, 46, 82, 93, 23, 92, 12, 255, 255, 255, 255]
   }
}

The following example shows the response:

{
   "id": "22",
   "jsonrpc": "2.0",
   "result":
   {
       "next_address": 65537
   }
}

Back to Web API Method Reference

 

readRegister

Reads the register of a device.

 

Parameters

ParameterRequired or OptionalJSON Data TypeDefault ValueDescription
session_idRequiredString ID of the session.
deviceOptionalStringDefault device of the sessionDevice name. You can specify only one device name.
addressRequiredNumber (integer) Register address.
sizeRequiredEnum Size of data in bits.

 

The following table lists values for the size parameter. The size member does not have keys.

ValueJSON Data Type
8Number (integer)
16Number (integer)
32Number (integer)
64Number (integer)

 

The following table lists the return values of this method:

 

Return ValueData TypeMeaning
next_addressNumber (integer)Address of the next register.
dataNumber (integer)Data of the register.

 

Example

The following example shows a request:

{
   "id": "19",
   "jsonrpc": "2.0",
   "method": "readRegister",
   "params":
   {
       "session_id": "_session0",
       "device": "SLSC-12001-030898C6",
       "address": 256,
       "size": "64"
   }
}

The following example shows the response:

{
   "id": "19",
   "jsonrpc": "2.0",
   "result":
   {
       "next_address": 257,
       "data": 1
   }
}

Back to Web API Method Reference

writeRegister

Writes data to the register of a device.

 

Parameters

ParameterRequired or OptionalJSON Data TypeDefault ValueDescription
session_idRequiredString ID of the session.
deviceOptionalStringDefault device of the sessionDevice name. You can specify only one device name.
addressRequiredNumber (integer) Register address.
sizeRequiredEnum Register size in bits.
dataRequiredNumber (integer) Data to write to the register.

 

The following table lists values for the size parameter. The size member does not have keys.

ValueJSON Data Type
8Number (integer)
16Number (integer)
32Number (integer)
64Number (integer)

 

The following table lists the return value of this method.

 

Return ValueData TypeMeaning
next_addressNumber (integer)Address of the next register.

 

Example

The following example shows a request:

{
   "id": "20",
   "jsonrpc": "2.0",
   "method": "writeRegister",
   "params":
   {
       "session_id": "_session0",
       "device": "SLSC-12001-030898C6",
       "address": 256,
       "size": "64",
       "data": 512
   }
}

The following example shows the response:

{
   "id": "20",
   "jsonrpc": "2.0",
   "result":
   {
       "next_address": 257
   }
}

Back to Web API Method Reference

Using the Web API with Various Programming Languages

You can use the web API with various programming languages to create a web client to configure the SLSC device:

You can also refer to the attachment for the example code.

 

Using the Web API with LabVIEW

The following example uses the web API with LabVIEW. The POST VI sends a POST request to the web server. The web server returns the response in the response output.

 

Back to Using the Web API with Various Programming Languages

Using the Web API with Python

The following example uses the web API with Python 2.7. The example sends a POST request to the web server and reads the HTTP response.

# coding = utf-8
# using python 2.7
import urllib2
import json
json_text = '''{
"id": "1",
"jsonrpc": "2.0",
"method": "initializeSession",
"params":
{
   "access": "ReadWrite",
   "devices": "SLSC-12001-030BE71A",
   "force_reserve": true
}
}'''

request = urllib2.Request("http://10.144.160.151/nislsc/call",json_text)
response = urllib2.urlopen(request)
data = json.load(response)

if data.has_key('error'):
   if data['error'].has_key('data'):
       print(data['error']['data']['nislsc_message'])
   else:
       print(data['error']['message'])
else:
   print("session id = {}".format(data['result']['session_id']))

Back to Using the Web API with Various Programming Languages

Using the Web API with C++

HTTP support is not included in the C++ Standard Library. You can use some open-source libraries on github.com to use the web API with C++.

You can refer to the attachment for the example that uses the web API with C++ to send a POST request to the web server and read the HTTP response. The library for HTTP support that the example uses is from the embeddedRest repository at https://github.com/fnc12/embeddedRest.  

Back to Using the Web API with Various Programming Languages

Using the Web API with C#

You can refer to the attachment for the example that uses the web API with C# to send a POST request to the web server and read the HTTP response. 

Back to Using the Web API with Various Programming Languages

Downloads

Was this information helpful?

Yes

No