From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Need a little modbus TCP help

Solved!
Go to solution

Hi guys,

 

I have 4 questions regarding modbus TCP.

 

First the short one: I need to reset the watchdog when I stop the VI and want to send data again, the help from Beckhoff says this:

ModbusTCP Interface

If the watchdog timer on your slave has elapsed it can be reset by writing twice to register 0x1121. The following must be written to the register: 0xBECF 0xAFFE. This can be done either with function 6 or with function 16.

 

How do I write BECF, as the field in labview is U16.

 

Second, maybe a dumb question, but what does 0xBECF mean? what is the 0x stand for? is the rest Hex?

 

Third, I have examined the modbus library and it type casts the data before sending it through TCP. What is this for and what does it do?

 

 

Last, I'm using the modbus library to control a Beckhoff BK9050. Ive tried the MB Ethernet Master  example, and it works -kinda-

The Digital outputs and inputs work, but trying to write an analog out results ALWAYS in an error. I just entered a number in the field for the registers.

 

I dont know very much about it yet, but this is what the documentation says about writing multiple registers (function 16):

Preset multiple register (Function 16):

 

 

 

 

Preset multiple register (Function 16)

The Preset Multiple Register function can be used to write a number of analog outputs. The first two analog output words are written in this example. The analog outputs start at an offset of 0x0800. Here the offset always describes a word. Offset 0x0003 writes to the fourth word in the output process image. The length indicates the number of words, and the Byte count is formed from the combination of all the bytes that are to be written.

Example: 4 words – correspond to a byte count of 8

The data bytes contain the values for the analog outputs. In this example, two words are to be written. The first word is to receive the value 0x7FFF, and the second word is to receive the value 0x3FFF.

Query

Byte Name Example
Function code 16
Start address high 8
Start address low 0
Length high 0
Length low 2
Byte Count 4
Data 1 byte 1 127
Data 1 byte 2 255
Data 2 byte 1 63
Data 2 byte 2 255

Response

The coupler replies with the start address and the length of the transmitted words.

Byte Name Example
Function code 16
Start address high 8
Start address low 0
Length high 0
Length low 2
0 Kudos
Message 1 of 46
(9,808 Views)

0x is a typical prefix indicating the following data is in Hex.  BECF are all hex characters.

 

If you drop a U16 constant on the block diagram, set the display format for hex, and type in BECF you can wire that into the cluster for the Modbus data.

 

Ultimately, all of the data to be transmitted is typecast to a string since either the TCP/IP functions (or VISA functions for serial Modbus) require a string input.

 

For help with writing to an analog out register, you are going to need to tell us more info as to what register you are writing to and what data.  Also, how do you know it is not working?  Are you getting an error message?

Message 2 of 46
(9,792 Views)

Thanks for the answers, really helpful!

 

The error I get is through the VI, whether I am trying to write a single register or multiple registers.

I have 4 analog outputs connected, of which 3 are connected to an actual device. So what I have tried is write to the first register, I have entered starting address as 0 or 1 (that would be the first analog out on the fieldbus right?) and for the register I have just entered a number -say 500-. Even if its zero the VI gives one the built in error pop-ups that something is wrong and the VI stops.

 

The ouput Im trying to write is just an analog 16 bit output, it controls a pump. The module gives a 0-10V output voltage depending on the 16 bit number I put in.

 

So what I figured is that the beckhoff isnt receiving the data the way it expects it to be, hence I have included their table for writing a register.

Any clues?

 

 

0 Kudos
Message 3 of 46
(9,781 Views)

What does the pop up error say?  Does it have an error number.  (Kind of important information when troubleshooting.Smiley Wink)

 

Are you sure you want a starting address of zero?  What is the register number you are trying to access according to the manual?  A starting address of 0 corresponds to register 40001.

Message 4 of 46
(9,777 Views)

uhhh I think that is the problem... STUPID really. I knew that they start with 4000... Will try and report.

 

Can you perhaps tell me what an U16 is -unsigned word-

How does this relate to a 16 bit number?

0 Kudos
Message 5 of 46
(9,771 Views)

btw, Im getting Error 6002 Modbus exception code 2

 

Sometimes I also get 6004 when writing digital outputs

 

0 Kudos
Message 6 of 46
(9,768 Views)

A 16 bit number is two 8 bit bytes,  one word.  It can either be signed or unsigned.  A signed 16 bit number (I16) goes from -32768 to 32767  ,  An unsigned 16 bit number (U16) goes from 0 to 65535.

 

An error code of 6002 means a modbus exception 2 which is an illegal address.  See this document http://www.modbus.org/docs/Modbus_Application_Protocol_V1_1b.pdf page 49.  A 6004 is exception 4 which is a "slave device failure".

 

What register are you trying to write to?  If you are writing to a register such as 40010, then your starting address will be 9.

 

Are you sure it is a register you can write to (a holding register starting with a 4), or is it a register you can only read from, (an input register which starts with a 3)?

Message 7 of 46
(9,761 Views)

Yes, they are write registers. But I think if I enter 40001 as starting address things will be alright!

 

Thank you for the claryfying answers + kudos all the way!

 

Last, I'd like to know what determines whether I should use signed or unsigned word?

And why is it called a word and not a 16bit number, it confuses me 😄

 

I know the single and double precision floats, so last I'd like to know what fixed point, long and quad are for. I have never used them.

 

0 Kudos
Message 8 of 46
(9,755 Views)

Start by just reading the registers.  Less things can go wrong.  Once you know you can read from a register, then try writing to it.

 

You do not want to enter the 40000 part as the starting address.  If you truly want register 40001, then the starting address you enter into LabVIEW is 0.

 

Have you tried entering hex 0800 as the starting address since that is one of the values the example you posted above listed?  (Which is 2048 decimal)

 

A word is a common computer term related to a group of two bytes of data.  A long integer is a 32 bit integer, also known as a double word.  A quad, or a quad word, is 4 words, or 8-byte integer.  Whether these are signed or unsigned all depends on whether they need to represent negative values or not.

 

 

 

 

Message 9 of 46
(9,745 Views)

Well thank you again!

 

I can now write without errors BUT it doesnt do anything. I entered as the starting address the ofset of 2048 and it can write without problem, when I read the holding registers

it returns the exact same values as I have just written.

 

Normally the analog out should control a pump, but nothing happens. Any clue?

 

 

 

 

0 Kudos
Message 10 of 46
(9,712 Views)