LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Modbus code for Power meter not working

Thanks. I ran the code and it did work, however I did find that when I put in N- number of Holding registers, The Output of Typecast reduces the output to half. eg, for 8 register, I see 4 from the typecast. Can you explain to me what this is doing?  Also I have the D6300 and D6500 Omega Modules. I used register address 40049 in each module to access holding register 1, but I keep getting Modbus exception Error code 2 as shown in the attach. Any help on getting this resolved will be greatly appreciated.I have also attached Data sheet cutouts for the two D-Modules.

0 Kudos
Message 41 of 57
(1,260 Views)

Of course.  It takes 2 registers to give the data for 1 single precision number.  So if you ask for 8 registers, you will get 4 numbers.

 

If you have parameters that only need 1 register  (such as if they were integers), then you wouldn't be running them through the typecast conversion to single precision.

 

Register 40049 accesses  Data Channel 1.  (not sure why you call that holding register 1)  It says 0-FFFF.  It looks like instead of that being a signed 16-bit integer (two-s complement, in which case you could typecast to an I16),  it is an integer where 0 is x8000.  So take the U16 value and subtract 32768 (the decimal value for x8000).

 

At least that is what the D6300 says.  The D6500 says it is says Analog Out Channel 1 and -FS  (Full scale?) is 0 and +FS is FFFF.  Which is a completely different way of writing it, but it is the same result.  (Also, Odd is that the D6300 is read only, and the D6500 is read/write.)

 

I highly recommend you read up more on modbus, but also articles on how numbers are represented in computer memory.

0 Kudos
Message 42 of 57
(1,258 Views)

Thanks RavensFan for the Information and Help so far and to your question, yes, the D6500 is a Read and Write Model. Can you please help withy the below questions based on your email.

  1. For the D6300 and D6500, what kind of register should be used in the Vi (Read Input Registers, Read Holding Registers, Write Single Registers, write Multiple Registers, etc.)
  2. What Register address values should be used? ( I have attached the entire documentation for the D-series module). I tried Starting Register Address 7281 (40049-32768 = 7281) and it never worked.
  3. If possible, Can you please modify the earlier VI you sent for these two different cases especially for the D6500 where we need to write to the module the value of current (4-20mA) or % of 20mA needed to open a device
0 Kudos
Message 43 of 57
(1,246 Views)

I didn't say subtract 32768 from the address.

 

You subtract 32768 from the value that you get from that address.

 

Here is the VI modified with first read doing a single precision float and typecast pairs of U16 registers into single precision.  Second read taking the U16 value as described in your last manual, offseting the value as the manual describes.  Then dividing so that it gives the fraction of the full scale range.  You can multiply as necessary to scale it to any engineering units.

0 Kudos
Message 44 of 57
(1,243 Views)

Hello RavensFan,

Attached is the result when I ran the code. It makes no sense to me. Any help?

0 Kudos
Message 45 of 57
(1,227 Views)

Do you understand the difference between an integer and a floating point number and how they are represented in memory?  It seems like you don't.

 

In the first read, you are reading 8 registers.  These registers happen to point to a group of 16-bit integer parameters related to the analog values.  Each register represents a single U16 integer.  So why are you using the process I showed you earlier that applies to single precision floating point numbers?  (That is where two register are combined to give you a 32-bit, 4 byte) value that needs to be typecast to a single precision float.)

 

In the second read you are also reading 8 registers, basically the same group.  Here you are properly interpreting them as integers like I showed you in the recent messages.  It looks like most of them are maxed out at 65535.  Probably analog input channels that are not connected to anything and floating high.  One is 8202 which would convert to -0.749 x full scale value according to the way they describe the register in the manual where zero is in the middle at hex8000.

 

The one thing I'm not certain of is whether the start address is correct.  In the first read, you start with register 49,  in the second register 48.  By standard practice, if you were looking for register 40049, you'd drop the beginning 4 and and subtract 1.  So entering 48 would be correct.  I don't know if you have something connected to analog input #1, or analog input #2 to know if the 8202 value is showing up in the correct spot.  If the Omega manual follows normal Modbus practices, I believe you have something connected to analog input 2 that is at about -75% of full scale range.

0 Kudos
Message 46 of 57
(1,225 Views)

RavenFan,

Yes I have a Thermocouple attached to D6300 Channel 2 (Register address = 40050)and nothing attached to Channel 1 and from Channel 3 to Channel 7. The Value as seen on the earlier attachment was 8202 which I believe is decimal. My question is why do we have to change to hex? If the Module range is 0-FFFF (which is equal to 0-65535 decimal), then the temp can be read as

(8202/65535) X  FS. The thermocouple I am using as shown below says Temp Limit is 2150 F. So, going by this, the temp can be calculated as =  ((8202/65535)  X 2150) = 147.2F. This is quite very high and did not match the measured temp using a Fluke temperature measuring instrument. Not sure if this is right.

0 Kudos
Message 47 of 57
(1,220 Views)

Datasheet of Tc attached.

0 Kudos
Message 48 of 57
(1,219 Views)

Yes. 8202 is a decimal number.  That means that it is 8202/65536 of the way between the bottom of the channel range 0, or x0000,  and the top of the range 65535 or x FFFF.  The manual on page 31 says it is "offset by x8000".  That means that "zero" is in the middle of that range.  You say "My question is why do we have to change to hex?"  No where are we changing anything to hex.  We are just working with numbers, whether those numbers are described in decimal format or hex format, it doesn't matter.  As long as you understand how numbers work.

 

For that module on page 31.  I don't know how you translate a thermocouple input to a range.  Thermocouples don't have a "zero".  They are generally in the millivolt range, sometimes positive, sometimes negative.

 

I suggest you contact Omega to find out more about how temperatures read by the thermocouple translate to values in that register, and translate back to deg C, or deg F, or whatever you want to see on your screen.  Pages 31-34 talk about other registers related to scaling and t/c type, and a rather complicated procedure to calibrate the inputs.  If you need help, then contact Omega.

 

For some reason, the manual you attached doesn't really talk about ranges.  But I did see this link on Omega http://www.omega.com/pptst/D6000_SERIES.html.  It says a J-type has a range of -200 deg C to 760 deg C.  Let's assume that is correct and it does map to the 0-65535 or 0-xFFFF range.  Take 8202 divide by 65536.  You have 0.125.  Your span is 960 deg C and it starts at -200.  So .125*960 - 200 is -80 deg C.  Does that value mean anything to you?

 

Call Omega.

0 Kudos
Message 49 of 57
(1,215 Views)

Thanks RavensFan. I was able to get things working. I am very appreciative of all your efforts.

0 Kudos
Message 50 of 57
(1,189 Views)