Hello. I am not an experianced user. A few years ago, I programmed a universal windows application as a mod bus client (running on a Rasperry pi). It worked fine. I have got my Labjack out of the shed again for another applicatin and am re-cycling the code (yes their may be libraries avaliable now but the existing solution is 99% fine).
My problem: when I write a value to register 9004 i can write fine.. Same code for 9304, it doesnt matter what i write - it always reverts to 0, even if it was already 1. I must be missing something....
I hope someone else can quickly spot my problem!
Thanks & regards
nmo
byte[] response = new byte[20];
byte[] write = { 0x00, 0x04, 0x00, 0x00, 0x00, 0x0B, 0x01, 0x10, 0x00, 0x00, 0x00, 0x02, 0x04, 0x00, 0x00, 0x00, 0x00 };
ushort address = 9304; //
byte[] byteArray = GetHexAddress(address);
write[8] = byteArray[0];//set the address
write[9] = byteArray[1];//set the address
write[16] = 0x01; // set 01 (0x01) to enable configA bu not working - always reverts to 0
server.Send(write); //set this
server.Receive(response);
address = 9004; //9002 is input 2 extended function index - set to 1 for K type thermocouple
byteArray = GetHexAddress(address);
write[8] = byteArray[0];//set the address
write[9] = byteArray[1];//set the address
write[16] = 0x16; // set 22 (0x16) to enable type k
server.Send(write); //set this
server.Receive(response);
Ok. after some sleep i figured it out! Even with 9004 set to 22, you cant set 9304 first. Set 9004 first, then set 9304 and it works!!
(problem solved)
Glad to hear you figured out the issue. AIN-EF is documented here:
https://labjack.com/support/datasheets/t-series/ain/extended-features
The AIN#_EF_INDEX registers (9004 is AIN2_EF_INDEX) need to set to a valid index before setting their corresponding AIN#_EF_CONFIG registers (9304 is AIN2_EF_CONFIG_A). Indexes are by default 0 (None/disabled). Without the index being set, the T7 does not allocate memory for that line and configuration values cannot be stored.
Also, keep in mind to check the responses for errors. If there is a Modbus error, you can read registers 55000 to 55028 for additional error information. We document that in the Error Responses section here:
https://labjack.com/support/software/api/modbus/protocol-details