fixed length was not send on request

main
Steffen Pohle 2 years ago
parent 1d2b324485
commit 5ab0140ff5

@ -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

@ -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)

@ -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
}
//

@ -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);

@ -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:

@ -10,6 +10,7 @@
<property name="text" translatable="yes">255</property>
</object>
<object class="GtkWindow" id="testmodbus-client">
<property name="height-request">500</property>
<property name="can-focus">False</property>
<property name="icon">testmodbus-client.png</property>
<signal name="destroy" handler="gtk_main_quit" swapped="no"/>
@ -209,19 +210,61 @@
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<object class="GtkLabel" id="cli_statusbar">
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="margin-left">8</property>
<property name="margin-right">8</property>
<property name="margin-start">8</property>
<property name="margin-end">8</property>
<property name="margin-top">8</property>
<property name="margin-bottom">8</property>
<attributes>
<attribute name="style" value="normal"/>
<attribute name="weight" value="bold"/>
</attributes>
<property name="orientation">vertical</property>
<child>
<object class="GtkSeparator">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="margin-top">8</property>
<property name="orientation">vertical</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="cli_statusbarold">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="margin-left">8</property>
<property name="margin-right">8</property>
<property name="margin-start">8</property>
<property name="margin-end">8</property>
<property name="margin-top">8</property>
<property name="margin-bottom">1</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="cli_statusbar">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="margin-left">8</property>
<property name="margin-right">8</property>
<property name="margin-start">8</property>
<property name="margin-end">8</property>
<property name="margin-top">1</property>
<property name="margin-bottom">8</property>
<attributes>
<attribute name="style" value="normal"/>
<attribute name="weight" value="bold"/>
</attributes>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
@ -230,38 +273,10 @@
</packing>
</child>
<child>
<object class="GtkLabel" id="cli_rate">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">0 / 0</property>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="padding">5</property>
<property name="pack-type">end</property>
<property name="position">1</property>
</packing>
<placeholder/>
</child>
<child>
<object class="GtkLabel" id="Error / Requests:">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">end</property>
<property name="valign">center</property>
<property name="label" translatable="yes">Rate
Errors / Requests:</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="padding">5</property>
<property name="pack-type">end</property>
<property name="position">2</property>
</packing>
<placeholder/>
</child>
</object>
<packing>

Loading…
Cancel
Save