This FAQ will explain how PowerShell can be used to communicate with the REST server on the BB-400. 

PowerShell

PowerShell is a command line shell and scripting language using the .NET framework, developed by Microsoft. This FAQ will explain how PowerShell can be used on Windows only, for further information regarding PowerShell and other operating systems please refer to the guides available on the PowerShell website here.

PowerShell can be started by holding the the Windows key+R, typing in 'powershell' and then clicking on OK.

http://www.brainboxes.com/files/pages/support/faqs/bb-400-faqs/How-to-communicate-with-rest-server-on-the-bb-400-via-powershell-Windows-Run-Box.png

 The PowerShell command prompt looks like this:

http://www.brainboxes.com/files/pages/support/faqs/bb-400-faqs/How-to-communicate-with-rest-server-on-the-bb-400-via-powershell-Windows-PowerShell.png

 

REST Commands

The REST API uses two kinds of requests: GET, to receive, and POST, to modify, information regarding the IO line status. These requests can be used by PowerShell to receive and modify information regarding the BB-400's IO line status.  

GET requests

GET requests allow the user to receive the status of the IO lines on the BB-400. The following examples show some GET commands to obtain information about the BB-400's IO lines.

1. To get the IO lines status

(Invoke-WebRequest 'http://192.168.0.85:9000/io').Content

Output:

{
    "inputs": [
        1,
        0,
        0,
        0,
        0,
        0,
        0,
        0
    ],
    "outputs": [
        0,
        1,
        1,
        1,
        1,
        1,
        1,
        1
    ]
}

2. To get the input state of the IO lines

(Invoke-WebRequest 'http://192.168.0.85:9000/io/inputs').Content

Output:

[
    1,
    0,
    0,
    0,
    0,
    0,
    0,
    0
]

3. To get the input state of a selected IO line

(Invoke-WebRequest 'http://192.168.0.85:9000/io/inputs/0').Content

Output:

1

4. To get the output states of the IO lines

(Invoke-WebRequest 'http://192.168.0.85:9000/io/outputs').Content

Output:


[
    0,
    1,
    1,
    1,
    1,
    1,
    1,
    1
]

5. To get the output state of a selected IO line.

(Invoke-WebRequest 'http://192.168.0.85:9000/io/outputs/0').Content

Output:

0

POST requests

POST requests can be used to modify information, the following examples show how the user can set the status of the IO lines.

1. To set the output states of the IO lines

Invoke-WebRequest 'http://192.168.0.85:9000/io/outputs' -Method POST -Body "[1,1,1,1,1,1,1,1]"

Output:

StatusCode        : 200
StatusDescription : OK
Content           :
RawContent        : HTTP/1.0 200 OK
                    Content-Type: application/json
                    Date: Mon, 12 Nov 2018 14:03:49 GMT
                    Server: BaseHTTP/0.6 Python/3.5.3


Forms             : {}
Headers           : {[Content-Type, application/json], [Date, Mon, 12 Nov 2018 14:03:49 GMT],
                    [Server, BaseHTTP/0.6 Python/3.5.3]}
Images            : {}
InputFields       : {}
Links             : {}
ParsedHtml        : mshtml.HTMLDocumentClass
RawContentLength  : 0

Adding parentheses and the ".StatusCode" command will return only the status code as an output:

(Invoke-WebRequest 'http://192.168.0.85:9000/io/outputs' -Method POST -Body "[1,1,1,1,1,1,1,1]").StatusCode

Output:

200

2. To set the output state of a selected IO line.

(Invoke-WebRequest 'http://192.168.0.85:9000/io/outputs/0' -Method POST -Body "0").StatusCode

Output:

200