MycilaJSY 13.0.0 Arduino / ESP32 library for the JSY1031, JSY-MK-163, JSY-MK-193, JSY-MK-194, JSY-MK-227, JSY-MK-229, JSY-MK-333 families single-phase and three-phase AC bidirectional meters from Shenzhen Jiansiyan Technologies Co, Ltd.

Loading...
Searching...
No Matches
Data Structures | Public Types | Public Member Functions | Static Public Member Functions
Mycila::JSY Class Reference

## Data Structures
class | Data
class | Metrics

## Public Types
enum | BaudRate : uint32_t { UNKNOWN = 0 , BAUD_1200 = 1200 , BAUD_2400 = 2400 , BAUD_4800 = 4800 , BAUD_9600 = 9600 , BAUD_19200 = 19200 , BAUD_38400 = 38400 }
enum class | EventType { EVT_READ , EVT_READ_ERROR , EVT_READ_TIMEOUT , EVT_READ_PEER }
enum class | Mode { UNKNOWN , AC , DC }
typedef std::function< void(EventType eventType, const Data &data)> | Callback

## Public Member Functions
void | begin (HardwareSerial &serial, int8_t rxPin, int8_t txPin, bool async, uint8_t core=MYCILA_JSY_ASYNC_CORE, uint32_t stackSize=MYCILA_JSY_ASYNC_STACK_SIZE, uint32_t pause=MYCILA_JSY_ASYNC_READ_PAUSE_MS)
| Initialize the JSY with the given RX and TX pins.
void | begin (HardwareSerial &serial, int8_t rxPin, int8_t txPin, BaudRate baudRate=BaudRate::UNKNOWN, uint8_t destinationAddress=MYCILA_JSY_ADDRESS_BROADCAST, uint16_t model=MYCILA_JSY_MK_UNKNOWN, bool async=false, uint8_t core=MYCILA_JSY_ASYNC_CORE, uint32_t stackSize=MYCILA_JSY_ASYNC_STACK_SIZE, uint32_t pause=MYCILA_JSY_ASYNC_READ_PAUSE_MS)
| Initialize the JSY with the given RX and TX pins.
void | end ()
| Ends the JSY communication.
bool | setDeviceAddress (uint8_t newAddress)
| Set a new address for a device.
bool | setDeviceAddress (uint8_t address, uint8_t newAddress)
| Set a new address for a device.
uint16_t | readModel ()
| Reads the JSY model.
uint16_t | readModel (uint8_t address)
| Reads the JSY model.
uint16_t | getModel () const
| Get the cached JSY model that was read during begin()
const char * | getModelName () const
Mode | readMode ()
| Reads the JSY mode (AC or DC). Some JSY are able to work with either AC or DC current.
Mode | readMode (uint8_t address)
| Reads the JSY mode (AC or DC). Some JSY are able to work with either AC or DC current.
bool | setMode (Mode mode)
| Set the JSY mode (AC or DC). Some JSY are able to work with either AC or DC current.
bool | setMode (uint8_t address, Mode mode)
| Set the JSY mode (AC or DC). Some JSY are able to work with either AC or DC current.
bool | read ()
| Read the JSY values.
bool | read (uint8_t address)
| Read the JSY values.
bool | resetEnergy ()
| Reset the energy counters of the JSY.
bool | resetEnergy (uint8_t address)
| Reset the energy counters of the JSY.
bool | setBaudRate (BaudRate baudRate)
| Change the baud rate of the JSY.
bool | setBaudRate (uint8_t address, BaudRate baudRate)
| Change the baud rate of the JSY.
gpio_num_t | getRXPin () const
gpio_num_t | getTXPin () const
bool | isEnabled () const
BaudRate | getBaudRate () const
uint8_t | getDestinationAddress () const
| Get the address used to send requests.
BaudRate | getMinAvailableBaudRate () const
BaudRate | getMaxAvailableBaudRate () const
| Get the maximum available baud rate supported by the current JSY model connected.
bool | isBaudRateSupported (BaudRate baudRate) const
| Check if a baud rate is supported by the current JSY model connected.
uint8_t | getLastAddress () const
| Get the address of the last device's response.
uint32_t | getTime () const
bool | isConnected () const
void | setCallback (Callback callback)

## Static Public Member Functions
static const char * | getModelName (uint16_t model)
| Get the name of the JSY model.
static BaudRate | getMinAvailableBaudRate (uint16_t model)
static BaudRate | getMaxAvailableBaudRate (uint16_t model)
static bool | isBaudRateSupported (uint16_t model, BaudRate baudRate)

## Detailed Description

Definition at line 85 of file MycilaJSY.h.

## Member Typedef Documentation

## ◆ Callback

typedef std::function<void(EventType eventType, const Data& data)> Mycila::JSY::Callback

Definition at line 337 of file MycilaJSY.h.

## Member Enumeration Documentation

## ◆ BaudRate

enum Mycila::JSY::BaudRate : uint32_t

Definition at line 87 of file MycilaJSY.h.

## ◆ EventType

enum class Mycila::JSY::EventType
| strong

Definition at line 105 of file MycilaJSY.h.

## ◆ Mode

enum class Mycila::JSY::Mode
| strong

Definition at line 116 of file MycilaJSY.h.

## Constructor & Destructor Documentation

## ◆ ~JSY()

Mycila::JSY::~JSY | ( |  | ) |
| inline

Definition at line 339 of file MycilaJSY.h.

## Member Function Documentation

## ◆ begin() [1/2]

void Mycila::JSY::begin | ( | HardwareSerial & | serial,
|  | int8_t | rxPin,
|  | int8_t | txPin,
|  | BaudRate | baudRate = BaudRate::UNKNOWN,
|  | uint8_t | destinationAddress = MYCILA_JSY_ADDRESS_BROADCAST,
|  | uint16_t | model = MYCILA_JSY_MK_UNKNOWN,
|  | bool | async = false,
|  | uint8_t | core = MYCILA_JSY_ASYNC_CORE,
|  | uint32_t | stackSize = MYCILA_JSY_ASYNC_STACK_SIZE,
|  | uint32_t | pause = MYCILA_JSY_ASYNC_READ_PAUSE_MS )

Initialize the JSY with the given RX and TX pins.

Parameters

  serial | The serial port to use
  rxPin | RX board pin connected to the TX of the JSY
  txPin | TX board pin connected to the RX of the JSY
  baudRate | The baud rate of the JSY. If set to BaudRate::UNKNOWN, the baud rate is automatically detected
  destinationAddress | The address of the device to communicate with (1-255) or MYCILA_JSY_ADDRESS_BROADCAST for all devices
  model | The model of the JSY. If set to MYCILA_JSY_MK_UNKNOWN, the model is automatically detected
  async | If true, the JSY will be read in a separate task (default: false)
  core | The core to use for the async task (default: MYCILA_JSY_ASYNC_CORE)
  stackSize | The stack size of the async task (default: MYCILA_JSY_ASYNC_STACK_SIZE)
  pause | Time in milliseconds to wait between each read in async mode (default: MYCILA_JSY_ASYNC_READ_PAUSE_MS)

Definition at line 643 of file MycilaJSY.cpp.

## ◆ begin() [2/2]

void Mycila::JSY::begin | ( | HardwareSerial & | serial,
|  | int8_t | rxPin,
|  | int8_t | txPin,
|  | bool | async,
|  | uint8_t | core = MYCILA_JSY_ASYNC_CORE,
|  | uint32_t | stackSize = MYCILA_JSY_ASYNC_STACK_SIZE,
|  | uint32_t | pause = MYCILA_JSY_ASYNC_READ_PAUSE_MS )
| inline

Initialize the JSY with the given RX and TX pins.

Parameters

  serial | The serial port to use
  rxPin | RX board pin connected to the TX of the JSY
  txPin | TX board pin connected to the RX of the JSY
  async | If true, the JSY will be read in a separate task (default: false)
  core | The core to use for the async task (default: MYCILA_JSY_ASYNC_CORE)
  stackSize | The stack size of the async task (default: MYCILA_JSY_ASYNC_STACK_SIZE)
  pause | Time in milliseconds to wait between each read in async mode (default: MYCILA_JSY_ASYNC_READ_PAUSE_MS)

Note
  The baud rate and model is automatically detected.

Definition at line 352 of file MycilaJSY.h.

## ◆ end()

void Mycila::JSY::end | ( |  | ) |

Ends the JSY communication.

Definition at line 732 of file MycilaJSY.cpp.

## ◆ getBaudRate()

BaudRate Mycila::JSY::getBaudRate | ( |  | ) | const
| inline

Definition at line 529 of file MycilaJSY.h.

## ◆ getDestinationAddress()

uint8_t Mycila::JSY::getDestinationAddress | ( |  | ) | const
| inline

Get the address used to send requests.

Returns
  The address used to send requests (1-255) or MYCILA_JSY_ADDRESS_BROADCAST (0) for all devices.

Definition at line 535 of file MycilaJSY.h.

## ◆ getLastAddress()

uint8_t Mycila::JSY::getLastAddress | ( |  | ) | const
| inline

Get the address of the last device's response.

Returns
  The address of the last device's response (1-255) or MYCILA_JSY_ADDRESS_UNKNOWN if no response was received.

Definition at line 558 of file MycilaJSY.h.

## ◆ getMaxAvailableBaudRate() [1/2]

Mycila::JSY::BaudRate Mycila::JSY::getMaxAvailableBaudRate | ( |  | ) | const

Get the maximum available baud rate supported by the current JSY model connected.

Returns
  The maximum available baud rate or BaudRate::UNKNOWN if no supported JSY connected

Definition at line 1297 of file MycilaJSY.cpp.

## ◆ getMaxAvailableBaudRate() [2/2]

Mycila::JSY::BaudRate Mycila::JSY::getMaxAvailableBaudRate | ( | uint16_t | model | ) |
| static

Definition at line 1303 of file MycilaJSY.cpp.

## ◆ getMinAvailableBaudRate() [1/2]

Mycila::JSY::BaudRate Mycila::JSY::getMinAvailableBaudRate | ( |  | ) | const

Definition at line 1274 of file MycilaJSY.cpp.

## ◆ getMinAvailableBaudRate() [2/2]

Mycila::JSY::BaudRate Mycila::JSY::getMinAvailableBaudRate | ( | uint16_t | model | ) |
| static

Definition at line 1280 of file MycilaJSY.cpp.

## ◆ getModel()

uint16_t Mycila::JSY::getModel | ( |  | ) | const
| inline

Get the cached JSY model that was read during begin()

Returns
  The JSY model or MYCILA_JSY_MK_UNKNOWN if the model cannot be read.

Definition at line 429 of file MycilaJSY.h.

## ◆ getModelName() [1/2]

const char * Mycila::JSY::getModelName | ( |  | ) | const
| inline

Definition at line 431 of file MycilaJSY.h.

## ◆ getModelName() [2/2]

const char * Mycila::JSY::getModelName | ( | uint16_t | model | ) |
| static

Get the name of the JSY model.

Parameters

  model | The JSY model

Returns
  The name of the JSY model (MYCILA_JSY_MK_163_NAME, MYCILA_JSY_MK_194_NAME, MYCILA_JSY_MK_333_NAME, MYCILA_JSY_MK_1031_NAME) or an empty string if the model is unknown

Definition at line 1605 of file MycilaJSY.cpp.

## ◆ getRXPin()

gpio_num_t Mycila::JSY::getRXPin | ( |  | ) | const
| inline

Definition at line 526 of file MycilaJSY.h.

## ◆ getTime()

uint32_t Mycila::JSY::getTime | ( |  | ) | const
| inline

Returns
  The time in milliseconds of the last successful read

Definition at line 563 of file MycilaJSY.h.

## ◆ getTXPin()

gpio_num_t Mycila::JSY::getTXPin | ( |  | ) | const
| inline

Definition at line 527 of file MycilaJSY.h.

## ◆ isBaudRateSupported() [1/2]

bool Mycila::JSY::isBaudRateSupported | ( | BaudRate | baudRate | ) | const

Check if a baud rate is supported by the current JSY model connected.

Returns
  true if the baud rate is supported, false if not or if no supported JSY connected

Definition at line 1320 of file MycilaJSY.cpp.

## ◆ isBaudRateSupported() [2/2]

bool Mycila::JSY::isBaudRateSupported | ( | uint16_t | model,
|  | BaudRate | baudRate )
| static

Definition at line 1326 of file MycilaJSY.cpp.

## ◆ isConnected()

bool Mycila::JSY::isConnected | ( |  | ) | const
| inline

Definition at line 566 of file MycilaJSY.h.

## ◆ isEnabled()

bool Mycila::JSY::isEnabled | ( |  | ) | const
| inline

Definition at line 528 of file MycilaJSY.h.

## ◆ read() [1/2]

bool Mycila::JSY::read | ( |  | ) |
| inline

Read the JSY values.

Returns
  true if the read was successful

Note
  This function is blocking until the data is read or the timeout is reached.

Definition at line 477 of file MycilaJSY.h.

## ◆ read() [2/2]

bool Mycila::JSY::read | ( | uint8_t | address | ) |
| inline

Read the JSY values.

Parameters

  address | The address of the device to read (1-255) or MYCILA_JSY_ADDRESS_BROADCAST for all devices

Returns
  true if the read was successful

Note
  This function is blocking until the data is read or the timeout is reached.

Definition at line 485 of file MycilaJSY.h.

## ◆ readMode() [1/2]

Mode Mycila::JSY::readMode | ( |  | ) |
| inline

Reads the JSY mode (AC or DC). Some JSY are able to work with either AC or DC current.

Returns
  The mode of the JSY, or Mode::UNKNOWN if there is an error mode cannot be read.

Note
  This function is blocking until the data is read or the timeout is reached.

Definition at line 445 of file MycilaJSY.h.

## ◆ readMode() [2/2]

Mode Mycila::JSY::readMode | ( | uint8_t | address | ) |
| inline

Reads the JSY mode (AC or DC). Some JSY are able to work with either AC or DC current.

Parameters

  address | The address of the device to read (1-255) or MYCILA_JSY_ADDRESS_BROADCAST for all devices

Returns
  The mode of the JSY, or Mode::UNKNOWN if there is an error mode cannot be read.

Note
  This function is blocking until the data is read or the timeout is reached.

Definition at line 453 of file MycilaJSY.h.

## ◆ readModel() [1/2]

uint16_t Mycila::JSY::readModel | ( |  | ) |
| inline

Reads the JSY model.

Returns
  The JSY model or MYCILA_JSY_MK_UNKNOWN if the model cannot be read.

Note
  This function is blocking until the data is read or the timeout is reached.

Definition at line 415 of file MycilaJSY.h.

## ◆ readModel() [2/2]

uint16_t Mycila::JSY::readModel | ( | uint8_t | address | ) |

Reads the JSY model.

Parameters

  address | The address of the device to read (1-255) or MYCILA_JSY_ADDRESS_BROADCAST for all devices

Returns
  The JSY model or MYCILA_JSY_MK_UNKNOWN if the model cannot be read.

Note
  This function is blocking until the data is read or the timeout is reached.

Definition at line 1135 of file MycilaJSY.cpp.

## ◆ resetEnergy() [1/2]

bool Mycila::JSY::resetEnergy | ( |  | ) |
| inline

Reset the energy counters of the JSY.

Returns
  true if the reset was successful

Note
  This function is blocking until the reset is confirmed or the timeout is reached.

Definition at line 492 of file MycilaJSY.h.

## ◆ resetEnergy() [2/2]

bool Mycila::JSY::resetEnergy | ( | uint8_t | address | ) |

Reset the energy counters of the JSY.

Parameters

  address | The address of the device to reset (1-255) or MYCILA_JSY_ADDRESS_BROADCAST for all devices

Returns
  true if the reset was successful

Note
  This function is blocking until the reset is confirmed or the timeout is reached.

Definition at line 1251 of file MycilaJSY.cpp.

## ◆ setBaudRate() [1/2]

bool Mycila::JSY::setBaudRate | ( | BaudRate | baudRate | ) |
| inline

Change the baud rate of the JSY.

Parameters

  baudRate | The new baud rate to set

Returns
  true if the baud rate was changed

Note
  This function is blocking until the change is confirmed or the timeout is reached.

Definition at line 511 of file MycilaJSY.h.

## ◆ setBaudRate() [2/2]

bool Mycila::JSY::setBaudRate | ( | uint8_t | address,
|  | BaudRate | baudRate )

Change the baud rate of the JSY.

Parameters

  address | The address of the device to change (1-255) or MYCILA_JSY_ADDRESS_BROADCAST for all devices
  baudRate | The new baud rate to set

Returns
  true if the baud rate was changed

Note
  This function is blocking until the change is confirmed or the timeout is reached.

Definition at line 1330 of file MycilaJSY.cpp.

## ◆ setCallback()

void Mycila::JSY::setCallback | ( | Callback | callback | ) |
| inline

Definition at line 568 of file MycilaJSY.h.

## ◆ setDeviceAddress() [1/2]

bool Mycila::JSY::setDeviceAddress | ( | uint8_t | address,
|  | uint8_t | newAddress )

Set a new address for a device.

Parameters

  address | The address of the device to change (1-255) or MYCILA_JSY_ADDRESS_BROADCAST for the broadcast address
  newAddress | The new address to set (1-255)

Returns
  true if the address was changed

Note
  The destination address is updated by this function if it was set to the old address.
  This function is blocking until the address is changed or the timeout is reached.

Definition at line 1334 of file MycilaJSY.cpp.

## ◆ setDeviceAddress() [2/2]

bool Mycila::JSY::setDeviceAddress | ( | uint8_t | newAddress | ) |
| inline

Set a new address for a device.

Parameters

  newAddress | The new address to set (1-255)

Returns
  true if the address was changed

Note
  The destination address is updated by this function if it was set to the old address.
  This function is blocking until the address is changed or the timeout is reached.

Definition at line 398 of file MycilaJSY.h.

## ◆ setMode() [1/2]

bool Mycila::JSY::setMode | ( | Mode | mode | ) |
| inline

Set the JSY mode (AC or DC). Some JSY are able to work with either AC or DC current.

Parameters

  mode | The mode to set

Returns
  true if the mode was set

Note
  This function is blocking until the mode is set or the timeout is reached.

Definition at line 461 of file MycilaJSY.h.

## ◆ setMode() [2/2]

bool Mycila::JSY::setMode | ( | uint8_t | address,
|  | Mode | mode )
| inline

Set the JSY mode (AC or DC). Some JSY are able to work with either AC or DC current.

Parameters

  address | The address of the device to set (1-255) or MYCILA_JSY_ADDRESS_BROADCAST for all devices
  mode | The mode to set

Returns
  true if the mode was set

Note
  This function is blocking until the mode is set or the timeout is reached.

Definition at line 470 of file MycilaJSY.h.

The documentation for this class was generated from the following files:

- src/MycilaJSY.h
- src/MycilaJSY.cpp