From 87117ad6029dd9c633b062d4ddd397e08925f66b Mon Sep 17 00:00:00 2001 From: Obe Van Lierde Date: Tue, 7 Nov 2023 17:51:09 +0100 Subject: [PATCH] strange error line 22 --- project/Core/Src/modbus-tcp.c | 71 +++++++++-------------------------- 1 file changed, 18 insertions(+), 53 deletions(-) diff --git a/project/Core/Src/modbus-tcp.c b/project/Core/Src/modbus-tcp.c index a0fcf6d..d3f4c44 100644 --- a/project/Core/Src/modbus-tcp.c +++ b/project/Core/Src/modbus-tcp.c @@ -5,64 +5,29 @@ char tcp_buffer[1024]; -struct Data_Modbus {//registers to hold the data of the modbus - uint16_t reg_00;// - uint16_t reg_01;// - uint16_t reg_03;// -}; +#define MAX_REG 25 -struct Data_Modbus datamodbus; - -/* -static err_t echo_recv( void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err ) -{ - int i; - int len; - char *pc; - - if ( err == ERR_OK && p != NULL ) - { - tcp_recved( pcb, p->tot_len ); - pc = (char *)p->payload; - len =p->tot_len; - - for( i=0; i tcp_sndbuf( pcb ) ) - len= tcp_sndbuf( pcb ); - - tcp_write( pcb, tcp_buffer, len, 0 ); - tcp_sent( pcb, NULL ); - } - else - { - pbuf_free( p ); - } - - if( err == ERR_OK && p == NULL ) - { - echo_close( pcb ); - } - - return ERR_OK; -} -*/ +uint16_t registers[MAX_REG]; static err_t modbus_incomming_data(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err){ - int i; - int len; - char *pc; - printf("data incomming\n"); + u16_t len; + if (p != NULL){ + printf("data not null\n"); + //here im going to procces the modbusdata + len = p->tot_len; + //putting the bufer in the register array + for(int i=0; ipayload[i];//getting the error "void value not ignored as it ought to be" on this line + } + + if(registers[7] == 0x10){// Check if it's a Modbus Write Multiple Registers request (0x10) + printf("in writing multiple register mode\n"); + } + } else if (err == ERR_OK){ + tcp_close(pcb);//when everithing was ok close the tcpconnection + } return ERR_OK; }