02-15-2022 09:10 AM
@billko wrote:
@vanceblake wrote:
Hi RTSLVU,
Thank you for your help. I've just realized that I have been working away at an issue from base camp when people have already built a helicoter that could take me halfway up the mountain lol. I'm looking at example codes online (which can be a risky proposition as I've learned from the past), but if my understanding is correct my current code would be from the perspective of the client (master)
But to further that analogy, you learn a lot more by getting yourself halfway up the mountain than if you took the helicopter!
Absolutely! Things like;
All kinds of stuff that is "nice to know."
02-15-2022 09:43 AM - edited 02-15-2022 09:56 AM
Hi billko,
Aint that the truth! So I am switching my code into Modbus VIs, but there are few things that are unclear:
1) I am using a new serial master to connect with my sensor. When it asks for the unit ID what does that mean? Is it the serial number of the sensor?
2) I am trying to read the input registers. The memory map I was provided says the read input registers address is 4. Is that the starting address?
3) If I want to read the first 11 input registers, I put in the number 11, but since I am using RTU should everything be in hexadecimal format/display?
4) If I index into the output which is an array of the stored register values, is the whole response stored there meaning I would have to select the relevant bytes again and untangle them from a string like I did with NI-VISA previously?
I have attached the updated code. The format of the Gas PPM requests in hex is as follows 1504 138B 0001 CRC: 4670 The first number is the slave address which is 15, the second is the function code which I am guessing corresponds to the memory map location, the starting address is 13 (MSB) 8B (LSB), and the input registers to read is 00 (MSB) 01 (LSB).
02-15-2022 10:26 AM - edited 02-15-2022 10:31 AM
@vanceblake wrote:
Hi billko,
Aint that the truth! So I am switching my code into Modbus VIs, but there are few things that are unclear:
1) I am using a new serial master to connect with my sensor. When it asks for the unit ID what does that mean? Is it the serial number of the sensor?
The unit ID is the Modbus address your device is using
2) I am trying to read the input registers. The memory map I was provided says the read input registers address is 4. Is that the starting address?
Yes
3) If I want to read the first 11 input registers, I put in the number 11, but since I am using RTU should everything be in hexadecimal format/display?
Use "read holding registers" Start address = 4 number of registers to read = 11
Hex/decimal numeric format is up to you
4) If I index into the output which is an array of the stored register values, is the whole response stored there meaning I would have to select the relevant bytes again and untangle them from a string like I did with NI-VISA previously?
Each register will be returned as an element of the array in the order they were read, Modbus returns 16bit unsigned integers, so you might have to combine more than one register and then scale the result and convert to a floating point to get an actual value. BTW: This should all be in the manual
I have attached the updated code. The format of the Gas PPM requests in hex is as follows 1504 138B 0001 CRC: 4670 The first number is the slave address which is 15, the second is the function code which I am guessing corresponds to the memory map location, the starting address is 13 (MSB) 8B (LSB), and the input registers to read is 00 (MSB) 01 (LSB).
I will have to take a look at your code
As I said above use "read holding registers" not "read input registers"
02-15-2022 10:47 AM
Hi RTSLVU,
Thanks for getting back to me. That's my bad I was working from an online example which used read input registers. I am attaching the memory map because I don't think I'm explaining the document clearly. It shows how the sensor memory is layed out and the locations of all the address.
I'm confused because when I was using VISA each coil, input and holding register had its on specific address as I modeled with the Gas PPM command above (starting address MSB+LSB). So, I guess I am not understanding how that information is accounted for in the Modbus library VI functions?
02-15-2022 11:03 AM
Okay I took a quick look at your document...
Lets say you want to read FOOBAR1 and FOOBAR2
Using "Read Holding Registers"
Start address = 5020(decimal)
Number of registers to read = 2
That will return an array with FOOBAR1 in element 0 and FOOBAR2 in element 1
Notice that some of the registers only give you one address but the next holding register is two addresses away
For instance TICO_SIG is two registers starting at register address 5005(decimal). So you have to again read two registers
02-15-2022 11:33 AM
Okay, now I understand what you mean. So if I want the Gas PPM and Temp Signal, I need to read from starting address 5003 and include all the registers in between the two registers I desire. I also need to take that into account when I am using index array to get those specific values from the output array. I am attaching another document that shows sample commands and responses. It says to use Modbus Read Input Registers function. Should I be using the decimal versions of everything in Labview?
02-15-2022 11:53 AM
@vanceblake wrote:
Okay, now I understand what you mean. So if I want the Gas PPM and Temp Signal, I need to read from starting address 5003 and include all the registers in between the two registers I desire. I also need to take that into account when I am using index array to get those specific values from the output array. I am attaching another document that shows sample commands and responses. It says to use Modbus Read Input Registers function. Should I be using the decimal versions of everything in Labview?
You are getting it! I might have been confused about input vs. holding registers in my responses, but in general use the function that matches what you are reading (holding register, input register, coil, etc.) the process is basically the same as the Modbus library takes care of the details.
Decimal versus Hex is really personal preference as it's all binary inside.
But in my experience using Hex was easier to keep track of things as the register map of my device was all in Hex
BTW: I suggest you use "Show radix" on your constants to make it clear what numbers are HEX
Also one of the things I did when I first started out was to create a VI to get the measurements I wanted.
02-15-2022 12:15 PM
Hi RTSLVU,
Thanks so much for all your help with this question! I have been staring at the memory map wondering why I needed it when I was using NI-VISA all this time lol. And I agree that would simplify this process because I would always have all the relevant registers already preloaded into an array and would just have access them as needed through either a user input or and automatc system.
02-15-2022 02:58 PM
That is a great example RTSLVU!
Personally I prefer a strictly typed Ring control, since they can be sparse, and show the numeric display in the most convenient radix. Maps didn't exist the last time I created a device specific MODBUS implementation but, a Map of Ring values and value deltas would lookup width easily.