Fixed bug in multi telegram readout with secondary address
- init slave before selecting secondary address
This commit is contained in:
parent
1fb68d1e05
commit
d12d7dd052
@ -25,7 +25,7 @@ static int debug = 0;
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
mbus_frame reply;
|
||||
mbus_frame *frame, reply;
|
||||
mbus_frame_data reply_data;
|
||||
mbus_handle *handle = NULL;
|
||||
|
||||
@ -84,8 +84,34 @@ main(int argc, char **argv)
|
||||
printf("Failed to set baud rate.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// init slave to get really the beginning of the records
|
||||
//
|
||||
|
||||
frame = mbus_frame_new(MBUS_FRAME_TYPE_SHORT);
|
||||
|
||||
if (frame == NULL)
|
||||
{
|
||||
fprintf(stderr, "Failed to allocate mbus frame.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
frame->control = MBUS_CONTROL_MASK_SND_NKE | MBUS_CONTROL_MASK_DIR_M2S;
|
||||
frame->address = MBUS_ADDRESS_BROADCAST_NOREPLY;
|
||||
|
||||
if (debug)
|
||||
printf("%s: debug: sending init frame\n", __PRETTY_FUNCTION__);
|
||||
|
||||
if (mbus_send_frame(handle, frame) == -1)
|
||||
{
|
||||
fprintf(stderr, "Failed to send mbus frame.\n");
|
||||
mbus_frame_free(frame);
|
||||
return 1;
|
||||
}
|
||||
|
||||
mbus_recv_frame(handle, &reply);
|
||||
|
||||
if (strlen(addr_str) == 16)
|
||||
{
|
||||
// secondary addressing
|
||||
|
@ -1548,37 +1548,6 @@ mbus_sendrecv_request(mbus_handle *handle, int address, mbus_frame *reply, int m
|
||||
return -1;
|
||||
}
|
||||
|
||||
//
|
||||
// init slave to get really the beginning of the records
|
||||
//
|
||||
|
||||
frame->control = MBUS_CONTROL_MASK_SND_NKE | MBUS_CONTROL_MASK_DIR_M2S;
|
||||
frame->address = address;
|
||||
|
||||
if (debug)
|
||||
printf("%s: debug: sending init frame\n", __PRETTY_FUNCTION__);
|
||||
|
||||
if (mbus_send_frame(handle, frame) == -1)
|
||||
{
|
||||
MBUS_ERROR("%s: failed to send mbus frame.\n", __PRETTY_FUNCTION__);
|
||||
mbus_frame_free(frame);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (mbus_recv_frame(handle, reply) == -1)
|
||||
{
|
||||
MBUS_ERROR("%s: Failed to receive M-Bus response frame.\n", __PRETTY_FUNCTION__);
|
||||
mbus_frame_free(frame);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (mbus_frame_type(reply) != MBUS_FRAME_TYPE_ACK)
|
||||
{
|
||||
MBUS_ERROR("%s: Unknown reply.\n", __PRETTY_FUNCTION__);
|
||||
mbus_frame_free(frame);
|
||||
return -1;
|
||||
}
|
||||
|
||||
frame->control = MBUS_CONTROL_MASK_REQ_UD2 |
|
||||
MBUS_CONTROL_MASK_DIR_M2S |
|
||||
MBUS_CONTROL_MASK_FCV |
|
||||
|
Loading…
x
Reference in New Issue
Block a user