### Navigation

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

# xchg Package

## `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.xchg.raw_xchg.``MasterXchg`(host_addr, port, protocol, opt_raw=True, opt_header=True, timeout=None, buf_size=4906)

  Bases: `json_link.xchg.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, add_header=True)

    Wrap message with a header and send out

  `setupXchg`()

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

  Bases: `json_link.xchg.raw_xchg.RawXchgError`

  Unable to send packet

  `code` = 1005

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

  Bases: `builtins.OSError`

  Base class for exceptions in the raw_xchg module

  `code` = 1000

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

  Bases: `json_link.xchg.raw_xchg.RawXchgError`

  Malformed or incorrect header

  `code` = 1003

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

  Bases: `json_link.xchg.raw_xchg.RawXchgError`

  No data read

  `code` = 1004

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

  Bases: `json_link.xchg.raw_xchg.RawXchgError`

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

  `code` = 1002

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

  Bases: `json_link.xchg.raw_xchg.RawXchgError`

  Timeout waiting for reply

  `code` = 1001

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

  Bases: `json_link.xchg.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, add_header=True)

    Wrap message with a header and send out

  `setupXchg`()

    Setup (Internet) socket for Slave.

### Navigation

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