Code 2 is a modbus error code for illegal address. The Opto22 subroutines are expecting modbus “registers” (which are 1 based) not “addresses” (which are 0 based). So if you are requesting address 50512, then you need to pass in 50513 as the register.