|
|
@ -100,6 +100,7 @@ gboolean mbcli_thread_cb_net(gpointer data) {
|
|
|
|
GtkWidget *textview = GTK_WIDGET (gtk_builder_get_object (_builder_, "cli_RawResult"));
|
|
|
|
GtkWidget *textview = GTK_WIDGET (gtk_builder_get_object (_builder_, "cli_RawResult"));
|
|
|
|
GtkTextBuffer *textbuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview));
|
|
|
|
GtkTextBuffer *textbuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview));
|
|
|
|
GtkTextIter start, end;
|
|
|
|
GtkTextIter start, end;
|
|
|
|
|
|
|
|
char *tmpdata = (char *) res->data;
|
|
|
|
|
|
|
|
|
|
|
|
std::string text;
|
|
|
|
std::string text;
|
|
|
|
float f1, f2;
|
|
|
|
float f1, f2;
|
|
|
@ -110,14 +111,40 @@ gboolean mbcli_thread_cb_net(gpointer data) {
|
|
|
|
gtk_text_buffer_get_end_iter(textbuffer, &end);
|
|
|
|
gtk_text_buffer_get_end_iter(textbuffer, &end);
|
|
|
|
gtk_text_buffer_delete(textbuffer, &start, &end);
|
|
|
|
gtk_text_buffer_delete(textbuffer, &start, &end);
|
|
|
|
|
|
|
|
|
|
|
|
if (res->fc == 1 | res->fc == 2) {
|
|
|
|
if (res->fc == 1 || res->fc == 2) {
|
|
|
|
text = "binary data";
|
|
|
|
//
|
|
|
|
|
|
|
|
// binary data
|
|
|
|
|
|
|
|
//
|
|
|
|
gtk_text_buffer_get_end_iter(textbuffer, &end);
|
|
|
|
gtk_text_buffer_get_end_iter(textbuffer, &end);
|
|
|
|
gtk_text_buffer_insert_with_tags_by_name(textbuffer, &end, text.c_str(), -1, "Addr", NULL);
|
|
|
|
gtk_text_buffer_insert_with_tags_by_name(textbuffer, &end, " Addr [HEX] Registers\n", -1, "Head", NULL);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < res->cnt; i++) {
|
|
|
|
|
|
|
|
if ((i % 32) == 0) {
|
|
|
|
|
|
|
|
if (i > 0) {
|
|
|
|
|
|
|
|
text += "\n";
|
|
|
|
|
|
|
|
gtk_text_buffer_get_end_iter(textbuffer, &end);
|
|
|
|
|
|
|
|
gtk_text_buffer_insert_with_tags_by_name(textbuffer, &end, text.c_str(), -1, "Data", NULL);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
text = "| ";
|
|
|
|
|
|
|
|
snprintf (tmp, 255, "%5d [%s] ", res->reg + i, to_hex16(res->reg+i).c_str());
|
|
|
|
|
|
|
|
gtk_text_buffer_get_end_iter(textbuffer, &end);
|
|
|
|
|
|
|
|
gtk_text_buffer_insert_with_tags_by_name(textbuffer, &end, tmp, -1, "Addr", NULL);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else if ((i % 16) == 0) text += " : ";
|
|
|
|
|
|
|
|
else if ((i % 8) == 0) text += " ";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (tmpdata[i/8] & (1<<i%8)) text += "1";
|
|
|
|
|
|
|
|
else text += "0";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_text_buffer_get_end_iter(textbuffer, &end);
|
|
|
|
|
|
|
|
gtk_text_buffer_insert_with_tags_by_name(textbuffer, &end, text.c_str(), -1, "Data", NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
else {
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// integer values (16bit words)
|
|
|
|
|
|
|
|
//
|
|
|
|
gtk_text_buffer_get_end_iter(textbuffer, &end);
|
|
|
|
gtk_text_buffer_get_end_iter(textbuffer, &end);
|
|
|
|
gtk_text_buffer_insert_with_tags_by_name(textbuffer, &end, " Addr RawData Integer Float Float(SW)\n", -1, "Head", NULL);
|
|
|
|
gtk_text_buffer_insert_with_tags_by_name(textbuffer, &end, " Addr RawData Integer Float Float(SW)\n", -1, "Head", NULL);
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < res->cnt; i++) {
|
|
|
|
for (int i = 0; i < res->cnt; i++) {
|
|
|
|
// add addr to textbuffer
|
|
|
|
// add addr to textbuffer
|
|
|
@ -134,7 +161,7 @@ gboolean mbcli_thread_cb_net(gpointer data) {
|
|
|
|
memcpy (((char*)&f2) + 2, &res->data[i], 2);
|
|
|
|
memcpy (((char*)&f2) + 2, &res->data[i], 2);
|
|
|
|
memcpy (((char*)&f2) + 0, &res->data[i+1], 2);
|
|
|
|
memcpy (((char*)&f2) + 0, &res->data[i+1], 2);
|
|
|
|
|
|
|
|
|
|
|
|
snprintf (tmp, 255, " | %6d | %9.3g | %9.5g", res->data[i], f1, f2);
|
|
|
|
snprintf (tmp, 255, " | %6d | %9.3g | %9.3g", res->data[i], f1, f2);
|
|
|
|
text = text + tmp;
|
|
|
|
text = text + tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
else {
|
|
|
@ -176,7 +203,6 @@ gboolean mbcli_thread_cb_error(gpointer data) {
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void displayerror (std::string error) {
|
|
|
|
void displayerror (std::string error) {
|
|
|
|
GtkWidget *dialog;
|
|
|
|
GtkWidget *dialog;
|
|
|
|
GtkWidget *window = GTK_WIDGET (gtk_builder_get_object (_builder_, "testmodbus-client"));
|
|
|
|
GtkWidget *window = GTK_WIDGET (gtk_builder_get_object (_builder_, "testmodbus-client"));
|
|
|
@ -228,6 +254,7 @@ void mbcli_cb_connect (GtkWidget *widget, gpointer data) {
|
|
|
|
netthread.Connect(gtk_entry_get_text(GTK_ENTRY(txthost)), gtk_entry_get_text(GTK_ENTRY(txtport)));
|
|
|
|
netthread.Connect(gtk_entry_get_text(GTK_ENTRY(txthost)), gtk_entry_get_text(GTK_ENTRY(txtport)));
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void mbcli_cb_disconnect (GtkWidget *widget, gpointer data) {
|
|
|
|
void mbcli_cb_disconnect (GtkWidget *widget, gpointer data) {
|
|
|
|
netthread.Disconnect();
|
|
|
|
netthread.Disconnect();
|
|
|
|
};
|
|
|
|
};
|
|
|
@ -260,6 +287,7 @@ int mbcli_get_refreshtime() {
|
|
|
|
return atoi(gtk_entry_get_text(GTK_ENTRY(rd_refresh)));
|
|
|
|
return atoi(gtk_entry_get_text(GTK_ENTRY(rd_refresh)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* returns the register
|
|
|
|
* returns the register
|
|
|
|
*/
|
|
|
|
*/
|
|
|
@ -286,8 +314,9 @@ int mbcli_get_unitid() {
|
|
|
|
return atoi(gtk_entry_get_text(GTK_ENTRY(rd_refresh)));
|
|
|
|
return atoi(gtk_entry_get_text(GTK_ENTRY(rd_refresh)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* returns status of the update button
|
|
|
|
* returns status of the update checkbox
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
int mbcli_get_update () {
|
|
|
|
int mbcli_get_update () {
|
|
|
|
GtkWidget *tb_update = GTK_WIDGET (gtk_builder_get_object (_builder_, "cli_Update"));
|
|
|
|
GtkWidget *tb_update = GTK_WIDGET (gtk_builder_get_object (_builder_, "cli_Update"));
|
|
|
@ -297,7 +326,17 @@ int mbcli_get_update () {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* sets the active button
|
|
|
|
* returns status of the reconnect checkbox
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
int mbcli_get_autoconnect () {
|
|
|
|
|
|
|
|
GtkWidget *tb_update = GTK_WIDGET (gtk_builder_get_object (_builder_, "cli_Reconnect"));
|
|
|
|
|
|
|
|
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(tb_update))) return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
* sets the update checkbox
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
void mbcli_set_update (int active) {
|
|
|
|
void mbcli_set_update (int active) {
|
|
|
|
GtkWidget *tb_update = GTK_WIDGET (gtk_builder_get_object (_builder_, "cli_Update"));
|
|
|
|
GtkWidget *tb_update = GTK_WIDGET (gtk_builder_get_object (_builder_, "cli_Update"));
|
|
|
@ -362,6 +401,7 @@ gboolean mbcli_refreshtimeout(gpointer data) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
else {
|
|
|
|
gtk_label_set_label(GTK_LABEL(rate), "- / -");
|
|
|
|
gtk_label_set_label(GTK_LABEL(rate), "- / -");
|
|
|
|
|
|
|
|
if (mbcli_get_autoconnect()) mbcli_cb_connect(NULL, NULL); // reconnect if needed
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|