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
Mycila::JSY Class Reference
Collaboration diagram for Mycila::JSY:

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_CHANGE , EVT_READ_ERROR , EVT_READ_TIMEOUT ,
  EVT_READ_PEER
}
 
enum class  Mode { UNKNOWN , AC , DC }
 
typedef std::function< void(EventType eventType)> 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)
 

Data Fields

Data data
 Access the runtime JSY data.
 

Detailed Description

Definition at line 86 of file MycilaJSY.h.

Member Typedef Documentation

◆ Callback

std::function<void(EventType eventType)> Mycila::JSY::Callback

Definition at line 306 of file MycilaJSY.h.

Member Enumeration Documentation

◆ BaudRate

enum Mycila::JSY::BaudRate : uint32_t

Definition at line 88 of file MycilaJSY.h.

◆ EventType

enum class Mycila::JSY::EventType
strong

Definition at line 106 of file MycilaJSY.h.

◆ Mode

enum class Mycila::JSY::Mode
strong

Definition at line 119 of file MycilaJSY.h.

Constructor & Destructor Documentation

◆ ~JSY()

Mycila::JSY::~JSY ( )
inline

Definition at line 308 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
serialThe serial port to use
rxPinRX board pin connected to the TX of the JSY
txPinTX board pin connected to the RX of the JSY
baudRateThe baud rate of the JSY. If set to BaudRate::UNKNOWN, the baud rate is automatically detected
destinationAddressThe address of the device to communicate with (1-255) or MYCILA_JSY_ADDRESS_BROADCAST for all devices
modelThe model of the JSY. If set to MYCILA_JSY_MK_UNKNOWN, the model is automatically detected
asyncIf true, the JSY will be read in a separate task (default: false)
coreThe core to use for the async task (default: MYCILA_JSY_ASYNC_CORE)
stackSizeThe stack size of the async task (default: MYCILA_JSY_ASYNC_STACK_SIZE)
pauseTime in milliseconds to wait between each read in async mode (default: MYCILA_JSY_ASYNC_READ_PAUSE_MS)

Definition at line 624 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
serialThe serial port to use
rxPinRX board pin connected to the TX of the JSY
txPinTX board pin connected to the RX of the JSY
asyncIf true, the JSY will be read in a separate task (default: false)
coreThe core to use for the async task (default: MYCILA_JSY_ASYNC_CORE)
stackSizeThe stack size of the async task (default: MYCILA_JSY_ASYNC_STACK_SIZE)
pauseTime 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 321 of file MycilaJSY.h.

◆ end()

void Mycila::JSY::end ( )

Ends the JSY communication.

Definition at line 713 of file MycilaJSY.cpp.

◆ getBaudRate()

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

Definition at line 498 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 504 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 527 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 1302 of file MycilaJSY.cpp.

◆ getMaxAvailableBaudRate() [2/2]

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

Definition at line 1308 of file MycilaJSY.cpp.

◆ getMinAvailableBaudRate() [1/2]

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

Definition at line 1279 of file MycilaJSY.cpp.

◆ getMinAvailableBaudRate() [2/2]

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

Definition at line 1285 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 398 of file MycilaJSY.h.

◆ getModelName() [1/2]

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

Definition at line 400 of file MycilaJSY.h.

◆ getModelName() [2/2]

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

Get the name of the JSY model.

Parameters
modelThe 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 1617 of file MycilaJSY.cpp.

◆ getRXPin()

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

Definition at line 495 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 532 of file MycilaJSY.h.

◆ getTXPin()

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

Definition at line 496 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 1325 of file MycilaJSY.cpp.

◆ isBaudRateSupported() [2/2]

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

Definition at line 1331 of file MycilaJSY.cpp.

◆ isConnected()

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

Definition at line 535 of file MycilaJSY.h.

◆ isEnabled()

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

Definition at line 497 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 446 of file MycilaJSY.h.

◆ read() [2/2]

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

Read the JSY values.

Parameters
addressThe 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 454 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 414 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
addressThe 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 422 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 384 of file MycilaJSY.h.

◆ readModel() [2/2]

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

Reads the JSY model.

Parameters
addressThe 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 1115 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 461 of file MycilaJSY.h.

◆ resetEnergy() [2/2]

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

Reset the energy counters of the JSY.

Parameters
addressThe 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
baudRateThe 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 480 of file MycilaJSY.h.

◆ setBaudRate() [2/2]

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

Change the baud rate of the JSY.

Parameters
addressThe address of the device to change (1-255) or MYCILA_JSY_ADDRESS_BROADCAST for all devices
baudRateThe 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 1335 of file MycilaJSY.cpp.

◆ setCallback()

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

Definition at line 537 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
addressThe address of the device to change (1-255) or MYCILA_JSY_ADDRESS_BROADCAST for the broadcast address
newAddressThe 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 1339 of file MycilaJSY.cpp.

◆ setDeviceAddress() [2/2]

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

Set a new address for a device.

Parameters
newAddressThe 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 367 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
modeThe 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 430 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
addressThe address of the device to set (1-255) or MYCILA_JSY_ADDRESS_BROADCAST for all devices
modeThe 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 439 of file MycilaJSY.h.

Field Documentation

◆ data

Data Mycila::JSY::data

Access the runtime JSY data.

Definition at line 543 of file MycilaJSY.h.


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