Not able to read Input registers via Modbus in ESP-IDF

R

rdkulk

I have a code which has different functions for reading and writing holding registers and coils and reading input registers. Of these 5 functions, the function for reading input registers is not working. According to the error message the CID declaration is wrong but it seems right. Can anybody please help me with what is wrong here?

The error I am getting:

E (449) MB_CONTROLLER_MASTER: mbc_serial_master_get_parameter: The requested cid(2) is not configured correctly. Check data dictionary for correctness.
E (459) MB_CONTROLLER_MASTER: mbc_master_get_parameter(74): Master get parameter failure, error=(0x102) (ESP_ERR_INVALID_ARG).
E (469) MASTER_TEST: Characteristic #2 (Length) read failed, err = 0x102 (ESP_ERR_INVALID_ARG).

The function call:

float test1 = master_read_input_register(2);

Read Input function and CID definition:

Code:
enum {
CID_HOLD_DATA_0 = 0, // Unique identifier for the 'Length' parameter (for reading)
CID_HOLD_DATA_1, // Unique identifier for the 'sending data' parameter (for writing)
CID_INPUT_DATA_0, // Unique identifier for the 'Length' parameter in input registers
CID_COIL_0, // Unique identifier for the coil
CID_COUNT
};

const mb_parameter_descriptor_t device_parameters[] = {
{ CID_HOLD_DATA_0, STR("Length"), STR("cm"), 1, MB_PARAM_HOLDING, 775, 2,
HOLD_OFFSET(holding_data0), PARAM_TYPE_FLOAT, 4, OPTS_NO_LIMIT, PAR_PERMS_READ_WRITE_TRIGGER },
{ CID_HOLD_DATA_1, STR("sending data"), STR("words.."), 1, MB_PARAM_HOLDING, 775, 2, // Same address
HOLD_OFFSET(holding_data1), PARAM_TYPE_FLOAT, 4, OPTS_NO_LIMIT, PAR_PERMS_READ_WRITE_TRIGGER },
{ CID_INPUT_DATA_0, STR("Length"), STR("cm"), 1, MB_PARAM_INPUT, 770, 2,
INPUT_OFFSET(input_data0), PARAM_TYPE_FLOAT, 4, OPTS_NO_LIMIT, PAR_PERMS_READ },
{ CID_COIL_0, STR("Coil_0"), STR("state"), 1, MB_PARAM_COIL, 522, 1, // Address 522, 1-bit size
0, PARAM_TYPE_U8, 1, OPTS_NO_LIMIT, PAR_PERMS_READ_WRITE_TRIGGER }
};

//read input register
float master_read_input_register(uint16_t cid) {
esp_err_t err = ESP_OK;
float value = NAN; // Default to NAN to indicate an error if read fails
const mb_parameter_descriptor_t* param_descriptor = NULL;
bool alarm_state = false;

ESP_LOGI(TAG, "Start reading input register for CID: %u...", cid);

// Get parameter descriptor for the provided CID
err = mbc_master_get_cid_info(cid, &param_descriptor);

if ((err != ESP_ERR_NOT_FOUND) && (param_descriptor != NULL) && param_descriptor->mb_param_type == MB_PARAM_INPUT) {
void* temp_data_ptr = master_get_param_data(param_descriptor);
assert(temp_data_ptr);

uint8_t type = 0;
err = mbc_master_get_parameter(cid, (char*)param_descriptor->param_key,
(uint8_t*)temp_data_ptr, &type);

if (err == ESP_OK) {
uint16_t raw_value = *(uint16_t*)temp_data_ptr;
ESP_LOGI(TAG, "Raw value = %u", raw_value);
value = (float)raw_value; // Convert raw value to float
ESP_LOGI(TAG, "Characteristic #%u %s (%s) value = %f read successfully.",
param_descriptor->cid,
param_descriptor->param_key,
param_descriptor->param_units,
value);

// Check if value is within the expected range
if ((value > param_descriptor->param_opts.max) || (value < param_descriptor->param_opts.min)) {
ESP_LOGW(TAG, "Value is out of range: %f", value);
alarm_state = true; // Set alarm if value is out of range
return NAN; // Return NAN if the value is out of range
}
} else {
ESP_LOGE(TAG, "Characteristic #%u (%s) read failed, err = 0x%x (%s).",
param_descriptor->cid,
param_descriptor->param_key,
(int)err,
(char*)esp_err_to_name(err));
}
} else {
ESP_LOGE(TAG, "Parameter descriptor not found or invalid type for CID: %u", cid);
}

if (alarm_state) {
ESP_LOGI(TAG, "Alarm triggered by CID #%u.", param_descriptor->cid);
}

return value;
}
 

Unreplied Threads

When an algebra isomorphism preserves positive involution

Let $A$ be a $K$-algebra where $K$ is a field with a unique ordering. We say a $K$-linear involution $*$ is positive if the map $A \to K$ via $a \mapsto tr(a^*a)$ is positive definite with respect to the ordering. Here, $tr(a)$ is the trace of the left multiplication map $a:x \mapsto ax$.

Suppose there is a $K$-algebra isomorphism $$\varphi: A \to B.$$

If there is a unique (up to isomorphism) positive involution in $A$ and $B$, can we say the involution must be preserved by the isomorphism $\varphi$: $$\varphi: (A, *_A) \to (B, *_B)?$$

Motivation:​


My question is motivated from representation theory. When $W$ is a real irreducible representation (irrep) of a finite group $G$, then $D:=End_G(W)$ is a division algebra by Schur's lemma. Additionally, Frobenius theorem on real associative division algebras implies that $D$ is isomorphic to either the reals $\mathbb{R}$, complexes $\mathbb{C}$, or quaternions $\mathbb{H}$. Let's call this isomorphism $\varphi$.

Suppose $W$ is endowed with an $G$-invariant inner product (i.e. $\langle g\cdot u, g\cdot v \rangle=\langle u , v \rangle$ for all $u,v \in W$ and $g \in G$). So, $W$ is an orthogonal irrep, and $D$ has the involution that acts as the adjoint corresponding to the $G$-invariant inner product. We know that $\mathbb{R}$, $\mathbb{C}$, and $\mathbb{H}$ all have involution. Furthermore, they are normed division algebras. The involution is the trivial map in $\mathbb{R}$, complex conjugate in $\mathbb{C}$, and the standard involution in $\mathbb{H}$ $\left((a+ib+jc+dk)^*=a-ib-jc-dk\right).$ We even do not need to define the involution in $\mathbb{R}$, $\mathbb{C}$, and $\mathbb{H}$ because the involution must be positive when we want to correspond involution to adjoint and there is a unique positive involution up to isomorphism in real central division algebras. My original question is how to prove that $\varphi$ preserves involution. Is this even true?

problem with armature after mirroring part of object

first of all, I'm totally new to blender, but couldn't find my answer after searching a lot. here is my problem in blender 4.2: in object edit mode, I've duplicated left shoulder top armor, mirrored, moved over right shoulder.

copied image

now the problem is; in pose mode if i rotate or modify left shoulder bone, that right mirrored armor part is moving too as in image:

bone rotate

I've tried to separate all object parts, then clear all parents from it, re-assign right shoulder bone as parent. but still it move with left shoulder bone as well as right shoulder bone.

any help appreciated.

blender file:

ps: is there anyway to select a bone and see which objects assigned to that bone? I know about weights and vertex groups, but in this object, non assigned to mirrored object.

What the garlic is that pt.2? (Plant identification help needed)

  • Derptastic
  • Social
  • Replies: 0
I have sown some garlic cloves in a pot (I only have a balcony, don't judge). And... something came out of the pot, but it's not garlic, and I'm very curious what it might be: Mystery plant Mystery plant, image two

I even mistook it for garlic initially, but it's completely inedible, and in fact, can barely be chewed through in any manner - the leaves are pretty tough. As far as I could tell by rummaging in the ground, there are no cloves to this beastie, and the roots seem to go quite far down. Google Lens identifies that as Chives, but I can guarantee you it's not (I actually do have chives, in a pot beside this one). In this case, you can see some actual garlic that caught on, chilling in the background, wondering what kind of neighbor is that. It definitely feels like a weed, but I still wanted to find out what it could be before it goes out.

Any educated guesses?

What would happen if you use warm base on a compressor ice cream machine?

  • Lenny Markus
  • Social
  • Replies: 0
Note: This question is for an ice cream machine WITH a compressor

Pretty much all recipes for ice cream/gelato call for completely chilling the mixture before starting to churn.

I get that for "passively" cooled machines (compressorless) it's important, so that you don't loose any of the pre-cooling you've done to the hardware.

Does it actually matter for a compressor-based machine? The machine can certainly cool it down without a hitch, but would it impact the final texture?

Attempting to simplify Fiege-Fiat-Shamir Identification

  • deeplyconfused
  • Technology
  • Replies: 0
My understanding of the Fiege-Fiat-Shamir protocol, sourced from "RSA and Public-Key Cryptography" by Richard A. Mollin is as below:

  1. A third party chooses two large primes $p$ and $q$, sharing $n = pq$.
  2. Alice has a secret value $s_a$ and shares a number $t_a = s_a^2 \mod n$.
  3. Alice picks a random $m \in \mathbb{N}$ and sends $w = m^2 \mod n$ to Bob.
  4. Bob picks a challenge $c \in \{0, 1\}$ and sends that to Alice.
  5. Alice computes $r = ms_a^c \mod m$ and sends that to Bob.
  6. Bob computes $r^2 = m^2s_a^{2c}$, and he can compare that to the publicly known $wt_a^2$, which should be identical if Alice does indeed know $s_a$. The security of this protocol is based on the fact that it is difficult to solve quadratic modular congruences with unfactored moduli.

My text elaborates that there is a method that an attacker can use to impersonate Alice with a 50% success rate, so this is done $a$ times and the probability that this works becomes $2^{-a}$.



If my understanding of this is correct, then one could use a similar protocol, but without the 50% chance of failure:

  1. As before, a third party selects $p$ and $q$, sharing $n = pq$.
  2. Alice picks a random $m$ and sends $w = m^2 \mod n$ to Bob.
  3. Alice sends $r = ms_a \mod n$ to Bob.
  4. Bob computes $r^2 \mod n$ and confirms that it's equal to $mt_a$.

Again, because neither $w$ nor $t_a$ are easy to compute, this seems secure.

I assume that this doesn't work. Why not? Why does Fiege-Fiat-Shamir require that Bob send a challenge?

Zencash uses your passphrase to identify AND unlock a wallet - how is this secure?

When looking into Zencash I stumbled into myzenwallet.io (by the Zencash creators), which gives you the option to enter a passphrase to generate a wallet (seems normal), but then after creating your wallet you can come back later and open your wallet by simply re-entering your passphrase again... this was unexpected and had me not only wondering about how it worked, but also wondering whether whatever means were used to achieve this would remain secure in the future.

Given that I don't need to identify the resource I'm unlocking, but rather just hand over the passphrase, I'm left to assume that their system generates a token by hashing my passphrase a number of times to generate my "master address" or "account ID" (I just made those terms up, because Zencash gives you many addresses, so I also assume you have some sort of master address / account ID), and then also using that same passphrase to lock / authenticate (not to encrypt though, right?) the wallet.

What common proverb does this string refer to?

  • matt_rule
  • Technology
  • Replies: 0
What common proverb is referenced by this three-character string?

ᚷᛖᚨ
Top