### Navigation

- index
- modules |
- next |
- previous |
- JSON Link 0.9.2a documentation »
- json_link »
- json_link Package »

# json_link Package

## `json_link` Module

A python module for GridLAB-D data (JSON) link handshaking (over UDP and TCP)

Classes:
  MasterLink SlaveLink

Implemented Methods:

Notes:

- Should work with Python 2.6+ and 3.x. Tested with 2.7.2 and 3.3
- Currently only supports IPv4
- The SLAVE will handle connections from any number of masters, BUT since the

code is only single threaded each processing (including delay) are blocking. Hence, the SLAVE may miss packets if it is busy processing (or waiting to send) a different reply.

@author: Bryan Palmintier, NREL 2013

exception `json_link.json_link.json_link.``JsonLinkActionMismatchError`

  Bases: `json_link.json_link.json_link.JsonLinkError`

  Incorrect handshaking order

  `code` = 2006

exception `json_link.json_link.json_link.``JsonLinkBadWrapperError`

  Bases: `json_link.json_link.json_link.JsonLinkError`

  Malformed wrapper

  `code` = 2003

exception `json_link.json_link.json_link.``JsonLinkError`

  Bases: `builtins.OSError`

  Base class for exceptions in the gld_json_link module

  `code` = 2000

exception `json_link.json_link.json_link.``JsonLinkNoDataError`

  Bases: `json_link.json_link.json_link.JsonLinkError`

  Expected data is empty

  `code` = 2002

exception `json_link.json_link.json_link.``JsonLinkOldMsgError`

  Bases: `json_link.json_link.json_link.JsonLinkError`

  Received a message with id older than a previously processed message

  `code` = 2005

exception `json_link.json_link.json_link.``JsonLinkRemoteError`

  Bases: `json_link.json_link.json_link.JsonLinkError`

  received a (reasonably) well formed error packet from the remote machine

  `code` = 2004

exception `json_link.json_link.json_link.``JsonLinkTimeoutError`

  Bases: `json_link.json_link.json_link.JsonLinkError`

  Timeout waiting for reply

  `code` = 2001

class `json_link.json_link.json_link.``MasterLink`(run_timestep=1, run_delay=0.1, run_max=-1, **Xchg_args)

  Bases: `json_link.json_link.json_link._BaseLink`

  Implements a GridLAB-D JSON Link Master/client state machine

  `INIT_RECHECK_DELAY` = 1
  `beginState`(old_state)

    beginState state

  `decideInSchema`(old_state)

    decideInSchema state

  `decideOutSchema`(old_state)

    decideOutSchema state

  `description_dict` = {'modelname': '/usr/local/bin/sphinx-build', 'version': '0.9.2b', 'application': 'Generic_JSON_Link_Master'}
  `go`()

    Begin JSON link Master state machine execution

  `in_schema` = {'y0': 'double test_0.y', 'y1': 'double test_1.y', 'clock': 'timestamp global.clock'}
  `local_data` = None
  `out_schema` = {'clock': 'timestamp global.clock', 'x1': 'random test_1.y', 'x0': 'random test_0.x'}
  `remote_data` = None
  `response_str_in` = 'result'
  `response_str_out` = 'method'
  `runDoMaster`(old_state)

    Internal Process for master. This version creates a simple set of 2 data points

  `runState`(old_state)

    Run internal process and sync with remote

  `runWaitSyncReplyState`(old_state)

    (Master) wait for remote to reply with sync data

  `send_in_schema` = True
  `send_out_schema` = True
  `waitInSchemaReplyState`(old_state)

    waitInSchemaReplyState state

  `waitInitReplyState`(old_state)

    waitInitReplyState state

  `waitOutSchemaReplyState`(old_state)

    waitOutSchemaReplyState state

  `waitStartReplyState`(old_state)

    waitStartReplyState state

  `waitTermReplyState`(old_state)

    waitTermReplyState state

class `json_link.json_link.json_link.``SlaveLink`(run_timestep=1, run_delay=0.1, run_max=-1, **Xchg_args)

  Bases: `json_link.json_link.json_link._BaseLink`

  Implements a GridLAB-D JSON Link Slave/server state machine

  `beginState`(old_state)

    beginState state

  `description_dict` = {'remote': 'Generic GridLAB-D Slave Link', 'version': '0.9.2b'}
  `go`()

    Begin JSON link Slave state machine execution

  `in_schema` = None
  `out_schema` = None
  `preInitState`(old_state)

    preInitState state

  `remote_data` = None
  `response_str_in` = 'method'
  `response_str_out` = 'result'
  `runDoSlave`(old_state)

    Internal Process for slave. This version simply echos the current data

  `runState`(old_state)

    Run internal process and sync with remote

  `runWaitSyncState`(old_state)

    sync data with remote

  `rxIgnoreErr`()

    Robust message receive that ignores timeouts and other errors

  `sendError`(action, code=None, err_str='')

    Helper function to send error messages

  `waitStartState`(old_state)

    waitStartState state

`json_link.json_link.json_link.``dummyData`(schema)

  Build up dummy json data package based on the provided schema

## `raw_xchg` Module

A python module for GridLAB-D data (JSON) data exchange over UDP and TCP

Classes:
  MasterXchg SlaveXchg

Implemented Methods:

Notes:

  – Should work with Python 2.6+ and 3.x. Tested with 2.7.2 and 3.3 – Currently only supports IPv4 – The SLAVE will handle connections from any number of masters, BUT since the

  > code is only single threaded each processing (including delay) are blocking. Hence, the SLAVE may miss packets if it is busy processing (or waiting to send) a different reply.

@author: Bryan Palmintier, NREL 2013

class `json_link.json_link.raw_xchg.``MasterXchg`(host_addr, port, protocol, opt_verbose=True, opt_header=True, timeout=None, buf_size=4906)

  Bases: `json_link.json_link.raw_xchg._BaseXchg`

  Implements a low-level GridLAB-D (JSON) UDP/TCP Master/client link

  `response_code_in` = '200'
  `response_code_out` = '0'
  `send`(msg_out)

    Wrap message with a header and send out

  `setupXchg`()

exception `json_link.json_link.raw_xchg.``RawXchgCantSendError`

  Bases: `json_link.json_link.raw_xchg.RawXchgError`

  Unable to send packet

  `code` = 1005

exception `json_link.json_link.raw_xchg.``RawXchgError`

  Bases: `builtins.OSError`

  Base class for exceptions in the raw_xchg module

  `code` = 1000

exception `json_link.json_link.raw_xchg.``RawXchgHeaderError`

  Bases: `json_link.json_link.raw_xchg.RawXchgError`

  Malformed or incorrect header

  `code` = 1003

exception `json_link.json_link.raw_xchg.``RawXchgNoDataError`

  Bases: `json_link.json_link.raw_xchg.RawXchgError`

  No data read

  `code` = 1004

exception `json_link.json_link.raw_xchg.``RawXchgSetupError`

  Bases: `json_link.json_link.raw_xchg.RawXchgError`

  Problems setting up the communication (e.g. opening the socket)

  `code` = 1002

exception `json_link.json_link.raw_xchg.``RawXchgTimeoutError`

  Bases: `json_link.json_link.raw_xchg.RawXchgError`

  Timeout waiting for reply

  `code` = 1001

class `json_link.json_link.raw_xchg.``SlaveXchg`(host_addr, port, protocol, opt_verbose=True, opt_header=True, timeout=None, buf_size=4906)

  Bases: `json_link.json_link.raw_xchg._BaseXchg`

  Implements a low_level GridLAB-D (JSON) UDP/TCP Slave/server link

  `close`()

    Expanded close to handle our state flags

  `receive`()

    (Slave) wait to receive a packet, decode the header, and return data

  `response_code_in` = '0'
  `response_code_out` = '200'
  `send`(msg_out)

    Wrap message with a header and send out

  `setupXchg`()

    Setup (Internet) socket for Slave.

### Navigation

- index
- modules |
- next |
- previous |
- JSON Link 0.9.2a documentation »
- json_link »
- json_link Package »