diff --git a/Changelog b/Changelog
index bfec3af..5235c70 100644
--- a/Changelog
+++ b/Changelog
@@ -1,3 +1,7 @@
+2024-02-22:
+- fixed: length was not set on request.
+- showing last three status lines.
+
2023-11-21:
- fixed: on modbus tcp/ip the transaction id should always be 0
diff --git a/Makefile b/Makefile
index df25021..753fe68 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
.SILENT: help
-VERSION = 0.1.1
+VERSION = 0.1.2
-include Makefile.rules
@@ -92,6 +92,7 @@ buildwindows: clean
./copyshare.sh
mv *.dll TestModbus-Client-$(VERSION)/
mv share TestModbus-Client-$(VERSION)/
+ zip -r TestModbus-Client-$(VERSION)-win.zip TestModbus-Client-$(VERSION)/
-include $(DEPENDFILE)
diff --git a/client.cc b/client.cc
index 76d7a79..713b4ef 100644
--- a/client.cc
+++ b/client.cc
@@ -178,8 +178,7 @@ gboolean mbcli_thread_cb_net(gpointer data) {
}
- GtkWidget *statusbar = GTK_WIDGET (gtk_builder_get_object (_builder_, "cli_statusbar"));
- gtk_label_set_label(GTK_LABEL(statusbar), (char*)"got data");
+ mbcli_statusline ((char*)"got data");
free (res);
return FALSE;
@@ -216,16 +215,49 @@ void displayerror (std::string error) {
gtk_widget_destroy(dialog);
}
+/*
+ * display last four lines of error message
+ */
+#define STATUS_LEN 1024
+#define STATUS_LINES 2
+void mbcli_statusline(char *txt) {
+ char *oldoldtext, *oldtext;
+ char *p[STATUS_LINES], *l;
+ char newtext[STATUS_LEN];
+ int i;
+
+ for (i = 0; i < STATUS_LINES; i++) p[i] = NULL;
+
+ GtkWidget *statusbarold = GTK_WIDGET (gtk_builder_get_object (_builder_, "cli_statusbarold"));
+ GtkWidget *statusbar = GTK_WIDGET (gtk_builder_get_object (_builder_, "cli_statusbar"));
+ oldoldtext = (char*) gtk_label_get_text(GTK_LABEL(statusbarold));
+ oldtext = (char*) gtk_label_get_text(GTK_LABEL(statusbar));
+
+ for (l = oldoldtext; l != NULL; l = strchr(l+1, '\n')) {
+ for (i = 1; i < STATUS_LINES; i++) p[i-1] = p[i];
+ p[STATUS_LINES-1] = l;
+ }
+
+ if (p[0] != NULL) {
+ snprintf (newtext, STATUS_LEN, "%s\n%s", p[0]+1, oldtext);
+ }
+ else
+ snprintf (newtext, STATUS_LEN, "%s\n%s", oldoldtext, oldtext);
+
+ gtk_label_set_label(GTK_LABEL(statusbarold), (char*)newtext);
+ gtk_label_set_label(GTK_LABEL(statusbar), (char*)txt);
+}
+
+
/*
* network thread callback
*/
gboolean mbcli_thread_cb_status(gpointer data) {
- GtkWidget *statusbar = GTK_WIDGET (gtk_builder_get_object (_builder_, "cli_statusbar"));
mbcli_connect_btn_sensitive (netthread.GetState() == NWT_nothing);
if (data) {
- gtk_label_set_label(GTK_LABEL(statusbar), (char*)data);
+ mbcli_statusline ((char*)data);
free (data);
}
@@ -353,8 +385,8 @@ void mbcli_set_update (int active) {
* returns status of the dont_use_FC1516 button
*/
int mbcli_get_FC1516 () {
- GtkWidget *tb_update = GTK_WIDGET (gtk_builder_get_object (_builder_, "cli_dontuse_FC1516"));
- if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(tb_update))) return 1;
+// GtkWidget *tb_update = GTK_WIDGET (gtk_builder_get_object (_builder_, "cli_dontuse_FC1516"));
+// if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(tb_update))) return 1;
return 0;
}
@@ -386,28 +418,22 @@ gboolean mbcli_refreshtimeout(gpointer data) {
int unitid = mbcli_get_unitid();
int state = netthread.GetState();
- GtkWidget *statusbar = GTK_WIDGET (gtk_builder_get_object (_builder_, "cli_statusbar"));
- GtkWidget *rate = GTK_WIDGET (gtk_builder_get_object (_builder_, "cli_rate"));
- char txt[255];
-
printf ("%s:%d %s\n", __FILE__, __LINE__, __FUNCTION__);
if (state == NWT_running) {
num_requests++;
if (netthread.SendRequestRead(unitid, fc, reg, num) == 0) {
num_errors++;
- gtk_label_set_label(GTK_LABEL(statusbar), "busy, another request in progress");
+ mbcli_statusline ((char*)"Busy, another request in progress. Close connection.");
+ netthread.Disconnect();
}
else {
- gtk_label_set_label(GTK_LABEL(statusbar), "request send");
+ mbcli_statusline ((char*)"request send");
}
- snprintf (txt, 255, "%d / %d", num_errors, num_requests);
- gtk_label_set_label(GTK_LABEL(rate), txt);
}
- else {
- gtk_label_set_label(GTK_LABEL(rate), "- / -");
+ else
if (mbcli_get_autoconnect()) mbcli_cb_connect(NULL, NULL); // reconnect if needed
- }
+
//
diff --git a/client.h b/client.h
index 4c1c2a0..eb7efe9 100644
--- a/client.h
+++ b/client.h
@@ -43,7 +43,7 @@ void mbcli_set_update (int active);
int mbcli_get_FC1516 ();
void mbcli_readdata();
gboolean mbcli_refreshtimeout(gpointer data);
-
+void mbcli_statusline(char *);
std::string to_hex16 (int v);
G_MODULE_EXPORT void mbcli_cb_show(GtkWidget *widget, gpointer data);
diff --git a/nwthread.cc b/nwthread.cc
index 744edbc..f8c53ea 100644
--- a/nwthread.cc
+++ b/nwthread.cc
@@ -125,9 +125,10 @@ int NetworkThread::SendRequestRead(int unitid, int fc, int reg, int num) {
req_mbh.offset = reg;
req_mbh.number = num;
req_mbh.uid = unitid;
+ req_mbh.length = 6;
- printf ("%s:%d build request fc:%d offset:%d number:%d\n", __FILE__, __LINE__,
- req_mbh.fc, req_mbh.offset, req_mbh.number);
+ printf ("%s:%d build request lenght:%d fc:%d offset:%d number:%d\n", __FILE__, __LINE__,
+ req_mbh.length, req_mbh.fc, req_mbh.offset, req_mbh.number);
UnLock();
return 1;
@@ -184,7 +185,6 @@ void NetworkThread::GuiSendResult(char *buffer, int len, modbustcp_rq_header *mb
void NetworkThread::BuildAndSendReadReq(char *buffer, int size) {
char *pos;
- req_mbh.length = 0;
// req_mbh.transid++; // with modbus tcp/ip it should always be set to 0
req_mbh.transid = 0;
pos = modbustcp_pkt_headerrq(buffer, size, &req_mbh);
@@ -255,7 +255,9 @@ void NetworkThread::Thread() {
Lock();
printf ("read data\n");
len = tcp.Read(buffer, BUFFER_SIZE);
- if (len < 0) state = NWT_close;
+ if (len < 0) {
+ state = NWT_close;
+ }
else {
//
// we could get some data, if busy reset connection
@@ -263,6 +265,7 @@ void NetworkThread::Thread() {
// got data without request? - Protokol error
errno = EPROTO;
state = NWT_error;
+ UnLock();
break;
}
@@ -309,7 +312,7 @@ void NetworkThread::Thread() {
tcp.Close();
break;
case NWT_close:
- GuiSendStatustext((char*)"Connection Closed");
+ GuiSendStatustext("Connection Closed");
tcp.Close();
break;
default:
diff --git a/testmodbus-client.ui b/testmodbus-client.ui
index 8611653..6035b0f 100644
--- a/testmodbus-client.ui
+++ b/testmodbus-client.ui
@@ -10,6 +10,7 @@
255