Modbus TCP error code 12

Hi, sometimes my modbus tcp subroutine will get the error code of 12 and it not able to get data from the field device, however, when I reupload the same program, everything works fine back. I check with the error code list mentioned it was due to 'The description argument is missing or too long. The maximum size for a description is 127 characters. ’ May I have more information above this error and how I can solve for this issue? thank you.

The error code 12 you are referencing is about designing subroutines - this will not be your error at runtime.

Error code 12 at runtime is “Invalid table index.”

Which means the code is trying to read or write to an index which is greater than the size of the table you are using.

When looking back to the code and table, the register number start from 258 and read for 23 values which the size is far smaller compare to the table length I used. However, as I mentioned above, when I try to reupload the same program, the error does not happen again but when the field device turn off and turn on again, the error showed. Any solution I can still apply to try solve this?

What does the Parameters table look like? What is the length of that table?

The parameter table is 10 which follow as the modbus tcp subroutine template

Where do you see the error code? Is it in the Message Log or somewhere else?

I’ve seen this before and I can’t quite remember. If you are getting 12 and not a -12 then the 12 has significant meaning. Can’t recall what it is. Like the number of the illegal register, or some other clue to what the problem is…

I saw the error code when right click and select inspect the variable ‘n04AsIntStatusChi’ and it show me error code 12.

The error code just show 12 not -12

That is not an opto error code.

Do you know how to set a breakpoint and step through the code? The only thing tricky about stepping through the modbus subs is setting a breakpoint in a way that you don’t get a ‘timeout’.
Find out where the 12 is being set.

The 12 could be the exception code returned by the slave device. I think that is where I’ve seen this before.

Ya true, the 12 should be an exception code. I do know how to use the breakpoint, can u explain further or guide me how should I tackle with this? thank you in advance

My guess is that you are asking for invalid registers for the device. I would start by just reading 1 or 2 registers, not 23. Get it so that always works. Then increase the number of registers until you get the error. Often devices have gaps in their register map and you need to separate the reads in several calls, skipping the gaps. 12 might turn out to be the index of the first invalid register.