A Forum run by Enthusiasts of MidNite Solar

Charge Controllers and Clippers => The "Classic" charge controller => Topic started by: zoneblue on January 18, 2016, 10:24:43 PM

Title: 2079 Network stack...
Post by: zoneblue on January 18, 2016, 10:24:43 PM
Ok so something new has occured. 11 days ago i fitted the new MNLP. After 5 days up time newmodbusd starting returning error code 4, which caused a new socket to be requested (and which reconnects for one second then repeats). Its been running in that state for the last 6 days. Code 4 is caused by the C below. This is Ross W's code which i added the error checking to (in order to get to cleanly reconnect after controller reboots).

Ive rebooted it and normal stack behavior resumed. Ill run this as is again until this reoccurs at which point ill remove the MNLP to see if that is the cause.

/**
* MODBUS_READ_REGISTERS
* Reads modbus registers via network socket
* Store in buffer array.
*
* @arg: (int) addr   , starting *register*
* @arg: (int) number , number of 16-bit registers to read
* @arg: (int) offset , where registers to be stored in the buffer
* @return (int) 0 ok, >0 fail
*
*/
int modbus_read_registers(int addr, int number, int offset) {
id[0]=0;               // Transaction ID MSB
id[1]=2;               // Transaction ID LSB
id[2]=0;               // modbus protocol 0 MSB
id[3]=0;               // modbus protocol 0 LSB
id[4]=0;               // bytes following MSB
id[5]=6;               // bytes following LSB
id[6]=255;             // ident
id[7]=3;               // read multiple registers/addresses
id[8]= (addr-1)>>8;    // starting address (MSB)
id[9]= (addr-1)&0xff;  // starting address (LSB)
id[10]=0;              // Addresses to read (MSB)
id[11]=number;         // Addresses to read (LSB)

//open a new network socket to the classic
if (!sock && classic_connect()) return(1);

//socket request
if (write(sock,&id, 12) != 12) return(2);

//read modbus encapsulation
len= read(sock, id, 7);
if (len<0) return(3);

//read response code and bytecount
len= read(sock, id, 2);
if (len<2 || (id[0]) != 3 || (id[1]&0xff) != number<<1) {
return(4); //socket reply error
}

//read response as advised
n= id[1]&0xff;           // number of bytes to read
len= read(sock, buf+(offset)*2, n);
if (len <0) return(5);

return(0);
}


[2015-01-08 09:11:09] - Creating socket...
[2015-01-08 09:11:09] - Socket successful
[2015-01-13 19:12:11] - Creating socket...
[2015-01-13 19:12:11] - Socket connect failed
[2015-01-13 19:12:11] - Modbus read error
[2015-01-13 19:12:12] - Creating socket...
[2015-01-13 19:12:12] - Socket connect failed
[2015-01-13 19:12:12] - Modbus read error
[2015-01-13 19:12:13] - Creating socket...
[2015-01-13 19:12:13] - Socket connect failed
[2015-01-13 19:12:13] - Modbus read error
[2015-01-13 19:12:14] - Creating socket...
[2015-01-13 19:12:14] - Socket connect failed
[2015-01-13 19:12:14] - Modbus read error
[2015-01-13 19:12:15] - Creating socket...
[2015-01-13 19:12:15] - Socket connect failed
[2015-01-13 19:12:15] - Modbus read error
[2015-01-13 19:12:16] - Creating socket...
[2015-01-13 19:12:16] - Socket connect failed
[2015-01-13 19:12:16] - Modbus read error
[2015-01-13 19:12:17] - Creating socket...
[2015-01-13 19:12:17] - Socket connect failed
[2015-01-13 19:12:17] - Modbus read error
[2015-01-13 19:12:18] - Creating socket...
[2015-01-13 19:12:18] - Socket connect failed
[2015-01-13 19:12:18] - Modbus read error
[2015-01-13 19:12:19] - Creating socket...
Title: Re: 2079 Network stack...
Post by: dgd on January 19, 2016, 03:52:05 AM
Zb,
Have you tried letting the socket stay connected ?  even just for several  minutes or a fixed repeat count of register set retreivals?
With Libmodbus and Cygwin (*nix system emultor/file system) on W10 compiled with g++ seems to hold the connection for an hour or so but I eventualy get a SOC error and Libmodbus seems to restart the link ( I don't yet quite understand if its a W10 issue or a lib issue or something else)

dgd
Title: Re: 2079 Network stack...
Post by: zoneblue on January 19, 2016, 01:17:44 PM
Up until recently it did stay connected, only breaking the connection when the controller WDT reset. Since 2074 teh resets stopped, and i was able to confirm that the modbus connectuon was watertight. Then i did four seperate manual reboots, one for each combination of the old MNLP, new MNLP, 2074 and 2079. It only started doing this after i fitted the new MNLP with 2079. That might be a coincidence though. Ill keep an eye on it.

I also dont understand Ross modbus read code well enough to say whether that error test for code 4 is actually an fatal error or not.
Title: Re: 2079 Network stack...
Post by: Westbranch on January 19, 2016, 02:29:07 PM
ZB, do you have access to a MNGP.  Your 4 way test might up a difference with 2079...

off topic, I managed to hit f12 while typing this comment and I see there is a debugger  in the pop up window...  any body know how it works or how to read what shows?
Title: Re: 2079 Network stack...
Post by: zoneblue on January 19, 2016, 05:12:31 PM
I dont, but i might order one in my next naws order, just to do some more testing.
Title: Re: 2079 Network stack...
Post by: zoneblue on February 06, 2016, 12:28:46 AM
This issue has reoccured 10 days after the reboot.  I guess ill try removing the MNLP, and try another reboot.


2016-01-19 15:13:02] - Socket successful
[2016-01-19 15:13:03] - Modbus read error
[2016-01-19 15:13:04] - Creating socket...
[2016-01-19 15:13:04] - Socket successful
[2016-01-19 15:13:05] - Modbus read error
[2016-01-19 15:13:06] - Creating socket...
[2016-01-19 15:13:23] - Socket successful
[2016-01-29 13:57:49] - Modbus read error
[2016-01-29 13:57:50] - Creating socket...
[2016-01-29 13:57:50] - Socket successful
[2016-01-29 13:57:51] - Modbus read error
[2016-01-29 13:57:52] - Creating socket...
[2016-01-29 13:57:52] - Socket successful
[2016-01-29 13:57:53] - Modbus read error
[2016-01-29 13:57:54] - Creating socket...
Title: Re: 2079 Network stack...
Post by: Westbranch on February 06, 2016, 12:38:27 PM
ZB, it is not exactly the same as the above post...  there is one line missing, in /red...???

2015-01-08 09:11:09] - Creating socket...
[2015-01-08 09:11:09] - Socket successful
[2015-01-13 19:12:11] - Creating socket...
[2015-01-13 19:12:11] - Socket connect failed
[2015-01-13 19:12:11] - Modbus read error
[2015-01-13 19:12:12] - Creating socket...
[2015-01-13 19:12:12] - Socket connect failed