adccommunitymod (AutomationDirect) asked a question.

Simple Modbus RTU

Created Date: February 27,2008

Created By: testone

**** This post has been imported from our legacy forum. Information in this post may be outdated and links contained in the post may no longer work.****

I am writing a simple VB.NET program to write 8866 to V3000 and AA44 to V3001. I have checked my CRC code and read the modbus pdf files but I keep getting Illegal Function (01) back from the plc. I am using a DL250(-1) and port 2, 19200,n,8,1 Sent to PLC (hex): 01,10,A2,41,00,02,04,88,66,AA,44,62,18 Received from PLC: 01,90,01,8D,C0 Thanks.


  • adccommunitymod (AutomationDirect)

    Created Date: February 27,2008

    Created by: bcarlton

    Isn't MODBUS function code 1 "Read Coils "? I believe you want function code 16 (10hex) "Write Multiple Registers "

    Edit - I see now that you are trying function code 16 but what is the "01 " at the start. That is what the receiving unit sees as the function code.

    Edit#2 - Ah - the "01 " must be the device address. All I can mention is, is it properly fomatted?

    Edit#3 - I read the response as a "function not supported " for a function 16 request.

    Edit#4 - Your address seems to be encoding "41537 " but I believe you only need to encode "1537 " which would be "06 ", "01 "

    Expand Post
  • adccommunitymod (AutomationDirect)

    Created Date: February 28,2008

    Created by: jackson

    bcarlton hit the nail on the head. You are writing to the wrong address.

    The correct modbus string to do what you want is:

    01,10,06,00,00,02,04,88,66,aa,44,6d,23

    When I write that string, I see the correct values in V3000 and V3001 and I get a good response from the PLC.

  • adccommunitymod (AutomationDirect)

    Created Date: February 28,2008

    Created by: jackson

    If you are only reading and writing V registers, the easiest way to convert a V memory to a modbus protocol string is just convert octal to hex.

    If you are getting into the other areas (X, Y, C, etc...) it's a different story.

    If you are using the Modbus conversion spreadsheet from the tech support area of the website, this is intended to do a conversion to Modicon style addressing, which is what most HMI's and SCADAs use.

    You can still use that but you will need to subtract the base address (Coils = 000001, Input Bits = 10001, Holding Registers = 40001 and Input Registers = 30001) from the converted address and then convert to hex.

    Expand Post
  • adccommunitymod (AutomationDirect)

    Created Date: February 28,2008

    Created by: testone

    Thank you. I will try this.

    I searched for "modbus " in this forum and I read somewhere to convert you take O3000 to decimal (1536) and add 40001. I must have misread that.

  • adccommunitymod (AutomationDirect)

    Created Date: February 28,2008

    Created by: MacS

    The 40001 range address is what most Modbus master software is looking for when you specify a Modbus Holding Register address to read or write.

    If you are writing your own Modbus driver you need the the protocol level address which is zero based and the function code determines the data type.

  • adccommunitymod (AutomationDirect)

    Created Date: February 28,2008

    Created by: testone

    That worked. I also had an issue with vb.net where it was not transmitting anything over 7f hex. I fixed that and now I am communicating.

    How fast can I pound the data into the plc? I am sending a string every 200ms and I see gaps where the plc did not respond. They seem random so I don't think its tied to a crc error or anything. I changed baud to 9600 as that was more reliable. Thanks.

    Expand Post
  • adccommunitymod (AutomationDirect)

    Created Date: February 28,2008

    Created by: jackson

    What is your scan time on the PLC?

    Typically, 200ms would be a very lax poll rate on Modbus.

    Assuming the PLC does not have a very long scan time, it should be able to handle much faster polls than that.

    The one thing to remember when doing Modbus with the DirectLogic PLCs... In Modbus, there is not supposed to be any gap between characters in a message over 1.5 character times. Many devices are lax with this specification. Direct Logic PLCs are not. If you have some packets going out that have a gap between the characters, you will most likely not get a response from the PLC.

    Expand Post
  • adccommunitymod (AutomationDirect)

    Created Date: February 28,2008

    Created by: testone

    Scan time is 3ms. Very small program right now. I would assume vb.net is sometimes beyond the 1.5 byte time. Thanks

  • adccommunitymod (AutomationDirect)

    Created Date: February 27,2008

    Created by: testone

    I am writing a simple VB.NET program to write 8866 to V3000 and AA44 to V3001. I have checked my CRC code and read the modbus pdf files but I keep getting Illegal Function (01) back from the plc. I am using a DL250(-1) and port 2, 19200,n,8,1

    Sent to PLC (hex):

    01,10,A2,41,00,02,04,88,66,AA,44,62,18

    Received from PLC:

    01,90,01,8D,C0

    Thanks.

    Expand Post