NI Labs Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

NI LabVIEW Modbus API Discussion

I mean the console reports an exception code 0x00000300 (might not have the number of preceeding zeros correct) and the interactive deployment reports lost contact with target etc.... Whilst hyperterminal fills up with the dumps - and reboots. Sometimes it reboots into LVRT somtimes into safe mode.

I have a service request in.

0 Kudos
Message 21 of 527
(7,231 Views)

Ah okay, yeah, that is well beyond my ability to help. A service request is the right route. Can you email the name of the AE who owns your request so I can keep tabs on them? The issue you are encountering is related to 2011, not to what software you have installed on the target. I can say with some confidence that upgrading to 2012 will resolve it, but I know that probably doesn't help.

Edit: re the service request, if you haven't already done so already the easiest path is to get a hyperterm dump, along with any dumps in the /tmp folder on the target that reference errors (check the creation date).

0 Kudos
Message 22 of 527
(7,231 Views)

Hi All,

Due to some hardware constraints of my existing modules, we are planning to shift to NI hardware i.e,cRIO and also to communicate to NI hardware through modbus TCP. I am new to labview and currently undergoing core 1 training. I am using LV 2013 and downloaded the latest modbus libraries. plan is to use the crio as modbus slave, time being i am using my PC as modbus slave and accordingly have used the modbus slave vi and established the communication between my modbus client and the LV slave. they are communicating well and response is good.

Now, while using the modbus slave vi, i have not created any registers, i guess everything is done internally by the code. Now when i connect my hardware in near future, what is the procedure to implement the same modbus slave functionality in real time. please let me know the steps, i will try to study and implement it.

0 Kudos
Message 23 of 527
(7,231 Views)

sridhar2247 wrote:

Hi All,

Due to some hardware constraints of my existing modules, we are planning to shift to NI hardware i.e,cRIO and also to communicate to NI hardware through modbus TCP. I am new to labview and currently undergoing core 1 training. I am using LV 2013 and downloaded the latest modbus libraries. plan is to use the crio as modbus slave, time being i am using my PC as modbus slave and accordingly have used the modbus slave vi and established the communication between my modbus client and the LV slave. they are communicating well and response is good.

Now, while using the modbus slave vi, i have not created any registers, i guess everything is done internally by the code. Now when i connect my hardware in near future, what is the procedure to implement the same modbus slave functionality in real time. please let me know the steps, i will try to study and implement it.

I would simply try moving the vi you have from the My Computer target to the cRIO target, and press play. So long as you are not using function blocks that cannot be deployed on the cRIO - it should work. The example in the new Modbus library - as mentioned by smithd, contains user/front panel events - and so will not work on the cRIO.

0 Kudos
Message 24 of 527
(7,231 Views)

smithd wrote:

Ah okay, yeah, that is well beyond my ability to help. A service request is the right route. Can you email the name of the AE who owns your request so I can keep tabs on them? The issue you are encountering is related to 2011, not to what software you have installed on the target. I can say with some confidence that upgrading to 2012 will resolve it, but I know that probably doesn't help.

Edit: re the service request, if you haven't already done so already the easiest path is to get a hyperterm dump, along with any dumps in the /tmp folder on the target that reference errors (check the creation date).

I forwarded the hyperterminal dump, the vi, and the snapshot of the cRIO's software payload.

I do have LV2013 on another PC here, and a 9068 target. I had planned on using those (one or both) this am, while they chew on my data.

Email with AE's name sent.

0 Kudos
Message 25 of 527
(7,231 Views)

Hello again Daniel

I am working through my test tool and I now need to deal with master and slave exceptions. I am creating a Modbus master which will interrogate a slave running on embedded hardware.

I need to monitor exceptions returned by the slave: i.e. illegal function, illegal address, illegal data and failure (MODBUS Application Protocol Specification V1.1b3 Section 7.0). Do you generate an error or warning for these that I need to intercept and reset? If so, what are the error codes? Ideally we would also monitor exceptions at the master - (i.e. slave packets which are error free but contain the wrong response - this only happens when there is an error in the slave protocol).

And finally, you mentioned that it would not be difficult to implement function code 08 and the subfunction codes within. What is the process for doing this?

Thanks again for the help

Regards

Ray

0 Kudos
Message 26 of 527
(7,229 Views)

I have a customer asking if the NI slave supports Modbus Function Code 22: Mask Write Register

In looking through the Slave function blocks I see a Masked Write Holding Registers,  but in my thinking that would be for me to use for the data going out to the master.

If my customer's master polls the NI slave with a function code 22 - will it work?




0 Kudos
Message 27 of 527
(7,229 Views)

I would simply try moving the vi you have from the My Computer target to the cRIO target, and press play. So long as you are not using function blocks that cannot be deployed on the cRIO - it should work. The example in the new Modbus library - as mentioned by smithd, contains user/front panel events - and so will not work on the cRIO.

Yes, that should work for any VI in the library

I forwarded the hyperterminal dump, the vi, and the snapshot of the cRIO's software payload.

I do have LV2013 on another PC here, and a 9068 target. I had planned on using those (one or both) this am, while they chew on my data.

Email with AE's name sent.

Got it, thanks. I'll follow up with her

I am working through my test tool and I now need to deal with master and slave exceptions. I am creating a Modbus master which will interrogate a slave running on embedded hardware.

I need to monitor exceptions returned by the slave: i.e. illegal function, illegal address, illegal data and failure (MODBUS Application Protocol Specification V1.1b3 Section 7.0). Do you generate an error or warning for these that I need to intercept and reset? If so, what are the error codes? Ideally we would also monitor exceptions at the master - (i.e. slave packets which are error free but contain the wrong response - this only happens when there is an error in the slave protocol).

And finally, you mentioned that it would not be difficult to implement function code 08 and the subfunction codes within. What is the process for doing this?

-Function code 8 would be implemented by following the pattern of one of the other master requests. All of the data transfer is handled by the library so you would just need to implement the logic for that particular code. I'll try to put together a template for you but it definitely won't happen today.

-All the error handling you mentioned is already built in. Modbus errors are always thrown as 538180+the modbus error code. If you use the explain error tool on 538181, ...2, etc. you will see what I mean. In addition each function tries to be responsible to make sure that the responses are well-formed. For example if a function code is invalid or if the response doesn't match the request, it will throw another error (538172, function data mismatch, 538170, function code mismatch).

I have a customer asking if the NI slave supports Modbus Function Code 22: Mask Write Register

In looking through the Slave function blocks I see a Masked Write Holding Registers,  but in my thinking that would be for me to use for the data going out to the master.

If my customer's master polls the NI slave with a function code 22 - will it work?

Function 22/0x16 is supported on both sides. The Mask Write Holding Register VI will send function code 22 from the master side or perform equivalent behavior on the slave side (on the slave it directly modifies the data). However, you are correct, it makes more sense from the master where you can modify a single bit within a register. Without the latency of the network it doesn't make so much sense.

Thanks,

Daniel

0 Kudos
Message 28 of 527
(7,229 Views)

Hey Tarsel,

I've attached a sample master function with some additional notes to help you (hopefully) understand where to plug in the appropriate code. Please note that the sample attached is the easiest way to add a function

(a) just to the master

(b) without creating a child class, which is another option

(c) without modifying the published library directly, which also works

Doing this also made me realize some limitations to the flexibility of the objects, but you don't need to worry about that.

Steps:

1) Download the files attached. You should be able to feed any modbus master class into the "Read X" VI. This is the top level request function, equivalent to calling "read coils".

2) Look at the description of the function you wish to implement, here: http://www.modbus.org/docs/Modbus_Application_Protocol_V1_1b3.pdf

3) In "Read X Request", you'll want to add the code to form your packet appropriately. For function 8, that looks like this:

req.png

Therefore, you'll have two parameters on your "Read Diagnostics Request" function:

-a sub-function, which should be a U16 that you split into two bytes using the "split number" function (an example is shown in the provided code).

-An array of U16s, which should also be split. In that case you'll want to use the "split number" and then "interleave" functions, to make sure data is in the right order. The PDU function is expecting a byte array.

4) Note that you don't have to do anything to send the request--this is handled by the library.

5) In "Read X Response", you'll want to unpack your packet appropriately. For function 8, this looks like this:

repsp.png

Therefore, you'll want to pull out two parameters as function outputs:

-a sub-function, which should be a set of two U8s which you join into a U16 using the "join number" function.

-an array of U16s, which should be joined as well. However, you'll want to decimate the remainder of the dataset first before using the join function (an example is shown in the provided code).

And thats the end...

Haha, just kidding. Normally that is the end. Read coils, for example, just returns the raw data. Thats why I referenced this as being a particularly complex function code. My recommendation would be to perform the implementation above and then create a set of wrapper functions for each "sub-function" you want to use. The easiest example is sub-function 0x00, which is basically a loopback test. I would implement this as shown below, where the central function would be the "Read Diagnostics" function you implemented above.

diagnostic0.png

However, looking at the rest of the diagnostics most of them look pretty straight forward. I still recommend this approach of a wrapper for each diagnostic because it makes it easier to use, but I'll leave the specifics of the implementation to you.

Hopefully this helps you out and isn't too difficult. Obviously feel free to post back if you've got questions.

Thanks,

Daniel

Realized I left the pw on there and it wasn't saved for 2011, both of which would make this useful. Fixed.

0 Kudos
Message 29 of 527
(7,229 Views)

I need to monitor exceptions returned by the slave: i.e. illegal function, illegal address, illegal data and failure (MODBUS Application Protocol Specification V1.1b3 Section 7.0). Do you generate an error or warning for these that I need to intercept and reset? If so, what are the error codes?

Just to clarify, the piece I was referring to above can be found in "Read X Response" in the posted zip file, in this case:

error.png

That is because an exception is defined as a modbus function return greater than 0x80:

Function Code Field: In a normal response, the server echoes the function code of the

original request in the function code field of the response. All function codes have a most–

significant bit (MSB) of 0 (their values are all below 80 hexadecimal). In an exception

response, the server sets the MSB of the function code to 1. This makes the function code

value in an exception response exactly 80 hexadecimal higher than the value would be for a

normal response

The data field is then used in that function to find the modbus exception, as described here:

Data Field: In a normal response, the server may return data or statistics in the data field

(any information that was requested in the request). In an exception response, the server

returns an exception code in the data field. This defines the server condition that caused the

exception

I believe that error generation VI is locked, so you can reference the code here:

error2.png

Ideally we would also monitor exceptions at the master - (i.e. slave packets which are error free but contain the wrong response - this only happens when there is an error in the slave protocol).

As I mentioned before, these are thrown as 538172. This is an example of those checks:

othererror.png

0 Kudos
Message 30 of 527
(7,229 Views)