Consider the following fields; The ModbusReadGroup classis part of my project, so I can change it as needed;
ModbusReadGroup<bool> coilsReadGroup = new ModbusReadGroup<bool>();
ModbusReadGroup<bool> discreteInputsReadGroup = new ModbusReadGroup<bool>();
ModbusReadGroup<short> inputRegisterReadGroup = new ModbusReadGroup<short>();
ModbusReadGroup<short> holdingRegisterReadGroup = new ModbusReadGroup<short>();
No consider my ugly way of trying to use them;
private
void readTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e){
// Read any coils if (coilsReadGroup != null){
bool[] _coils = new bool[coilsReadGroup.Length];fieldTalk.readCoils(1, coilsReadGroup.StartAddress, _coils);
coilsReadGroup.setValues(_coils);
}
// Read any discrete inputs if (discreteInputsReadGroup != null)
{
bool[] _inputs = new bool[discreteInputsReadGroup.Length];fieldTalk.readInputDiscretes(1, discreteInputsReadGroup.StartAddress, _inputs);
discreteInputsReadGroup.setValues(_inputs);
}
// Read any input registers if (inputRegisterReadGroup != null)
{
short[] _registers = new short[inputRegisterReadGroup.Length];fieldTalk.readInputRegisters(1, inputRegisterReadGroup.StartAddress, _registers);
inputRegisterReadGroup.setValues(_registers);
}
// Read any holding registers if (holdingRegisterReadGroup != null)
{
short[] _registers = new short[holdingRegisterReadGroup.Length];fieldTalk.readMultipleRegisters(1, holdingRegisterReadGroup.StartAddress, _registers);
holdingRegisterReadGroup.setValues(_registers);
}
I feel like I should be able to put it all in an arraylist and do a for each, but I'm not sure what to do with the different array datatypes (short of making them objects and doing a bunch of memory sucking conversions. It seems like I should be able to define the array datatype based on the datatype used for the generic (ModbusReadGroup<>), but I'm not having luck with that.
Any ideas
Thanks