Unless you are writing this (Gateway Module) and it does not sound
like you are, you simply need to create one Master and when you
request data put the slaveID all the Read Methods have an overide to
support 'slaveID' this is assuming you have a stup as follows.
[Your Master]---ethernet---[Device ID 1]----485---[Device ID 2]
Example
using (TcpClient client = new TcpClient("127.0.0.1", 502))
{
ModbusIpMaster master = ModbusIpMaster.CreateIp(client);
// read five input values NOTICE the 1(slaveID)
byte slave = 1;
ushort startAddress = 100;
ushort numInputs = 5;
bool[] inputsDEVICE01 = master.ReadInputs(slave,
startAddress, numInputs);
slave = 2;
bool[] inputsDEVICE02 = master.ReadInputs(slave,
startAddress, numInputs);
}
Hope this helps, just another quick note about addressing although I
assume you know this I always like to explain this when I give
examples on NModbus.
10000 or 100000 is implied by the [ReadInputs function] See Below:
In this example you are reading what would be documented as 10100 -
10105 or 10101 - 10106 Depending on how your device handles 0 offset.
Or possibly 100100 - 100101 for 6 digit although for NModbus the
request is the same.
Quick Info on Modbus Addressing-
[AKA 5 Digit Addressing]
0x Coil 00001-09999 Digital Output
1x Discrete Input 10001-19999 Digital Input [used in this example]
3x Input Register 30001-39999 Analog Input
4x Holding Register 40001-49999 Analog output
Translating references to addresses, reference 40001 selects the
holding register at address 0000. The reference 40001 will appear in
documentation and is used to define the Modbus register in the
location property of the functional block. The address 0000 will be
transmitted in the message packet. Addresses are often not directly
used by the application or the user.
On occasion, it is necessary to access more than 10,000 of a register
type. Based on the original convention, there is another defacto
standard that looks very similar. Additional register types and
reference ranges recognized by Babel Buster are as follows:
[AKA 6 Digit Addressing]
0x Coil 000001-065535
1x Discrete Input 100001-165535
3x Input Register 300001-365535
4x Holding Register 400001-465535
5 or 6 digit does not really matter just use the first number to
determine what method to call.
Tim-
> --
> You received this message because you are subscribed to the Google Groups "NModbus" group.
> To post to this group, send email to nmodbus...@googlegroups.com.
> To unsubscribe from this group, send email to nmodbus-discu...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/nmodbus-discuss?hl=en.
>
>
using (TcpClient client = new TcpClient("127.0.0.1", 502)) { ModbusIpMaster master = ModbusIpMaster.CreateTcp(client); // read five input values ushort startAddress = 100; ushort numInputs = 5; bool[] inputs = master.ReadInputs(startAddress, numInputs); for (int i = 0; i < numInputs; i++) Console.WriteLine("Input {0}={1}", startAddress + i, inputs[i] ? 1 : 0); } // output: // Input 100=0 // Input 101=0 // Input 102=0 // Input 103=0 // Input 104=0
Also just a quick note I hope it is clear to you that "127.0.0.1"
should be replace by your ethernet devices IP address.
Tim-
On Tue, Apr 12, 2011 at 11:24 AM, Big Brian
<brianh...@googlemail.com> wrote:
Yes, I would say it is very likely a holding register I pulled up some
documentation and that appears to be 'Phase Current 1'
There is a couple things to keep in mind, since this is using extended
6 digit addressing IE most SCADA systems would expect 451288 it is
also possible this is greater than 16bit [does not appear to be since
there is a 512 89 Available] but you may need to read 2 registers and
use bitconverter to get yourself a Int32 and also you may need to
scale this number[Although many devices put prescaled numbers into
extended registers and raw numbers in the standard modbus address
range], you will need to check the documentation for all of these.
- just saw the warning for that set of addresses CAUTION : using this
table involves multiplying values by transformation ratios.
You might want 50532 instead and read 2 registers.
Somthing Like
ushort[] ret = new ushort[]{1,0};
byte[] B1 = BitConverter.GetBytes(ret[0]);
byte[] B2 = BitConverter.GetBytes(ret[1]);
byte[] B3 = new byte[4];
Array.Copy(B1, 0, B3, 0, 2);
Array.Copy(B2, 0, B3, 2, 2);
int Final = BitConverter.ToInt32(B3,0);
but watch out for swaped registers[or if i have the ushorts backwords
in my sample heh]
Regards,
Tim-