News:

  • August 26, 2026, 02:37:05 AM

Login with username, password and session length

Author Topic: Modbus TCP Ascii Protocol  (Read 28031 times)

ATU

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 2126
  • YKPAIHA
    • ATU, Inc.
Modbus TCP Ascii Protocol
« on: August 07, 2018, 12:18:53 PM »
On the BRX, how would you handle Modbus TCP Ascii Protocol?  Its a older device with some type of Ethernet Converter that I am stuck with, but the Ethernet Modbus protocol is in Ascii.

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6172
  • Yes Pinky, Do-more will control the world!
Re: Modbus TCP Ascii Protocol
« Reply #1 on: August 07, 2018, 12:27:28 PM »
Didn't know they put ascii on TCP. We don't support it.

Creating a generalized handler would be more work, but if you know exactly what you are reading/writing, it isn't too hard to roll your own with TCPOPEN/STREAMIN/STREAMOUT/CHECKSUM.
"It has recently come to our attention that users spend 95% of their time using 5% of the available features. That might be relevant." -BobO

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3843
    • Host Engineering
Re: Modbus TCP Ascii Protocol
« Reply #2 on: August 07, 2018, 12:31:09 PM »
Do-more does not support the original Modbus/ASCII (Serial or on Ethernet). You are going to have to write your own logic and treat it like a "custom protocol".  You would only need to implement the function codes you need, generating the Master and processing the Slave's response.

You would use OPENTCP to create the connection, but then also have to handle any situations where the remote side might disconnect you.  Then use STREAMOUT/STREAMIN to transmit/receive the ASCII "packets".

Which function code(s) will you need to implement?

ATU

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 2126
  • YKPAIHA
    • ATU, Inc.
Re: Modbus TCP Ascii Protocol
« Reply #3 on: August 07, 2018, 12:55:41 PM »
Only need the holding register read, code 3?  Do you have any documentation good links for the TCP protocol?

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6172
  • Yes Pinky, Do-more will control the world!
Re: Modbus TCP Ascii Protocol
« Reply #4 on: August 07, 2018, 01:09:28 PM »
"It has recently come to our attention that users spend 95% of their time using 5% of the available features. That might be relevant." -BobO

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6172
  • Yes Pinky, Do-more will control the world!
Re: Modbus TCP Ascii Protocol
« Reply #5 on: August 07, 2018, 01:13:49 PM »
Modbus/TCP basically just drops the serial address byte and CRC from the RTU packet and adds a 7 byte header. I'm happy to answer questions, although I have never implemented the ascii variety.
"It has recently come to our attention that users spend 95% of their time using 5% of the available features. That might be relevant." -BobO

ATU

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 2126
  • YKPAIHA
    • ATU, Inc.
Re: Modbus TCP Ascii Protocol
« Reply #6 on: August 07, 2018, 01:45:13 PM »
The only place ascii mode is mentioned is in the Legacy spec. So I swap the RTU packet information in the TCP Protocol with the Ascii formated packet?

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6172
  • Yes Pinky, Do-more will control the world!
Re: Modbus TCP Ascii Protocol
« Reply #7 on: August 07, 2018, 01:55:19 PM »
Maybe, but you may be looking at Modbus/RTU (Ascii) over TCP, not Modbus/TCP.
"It has recently come to our attention that users spend 95% of their time using 5% of the available features. That might be relevant." -BobO

ATU

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 2126
  • YKPAIHA
    • ATU, Inc.
Re: Modbus TCP Ascii Protocol
« Reply #8 on: August 07, 2018, 02:20:58 PM »
MODBUS Messaging on TCP/IP Implementation Guide V1.0b?

There is also MODBUS APPLICATION PROTOCOL SPECIFICATION
V1.1b3

No mention of Modbus Ascii anywhere. I had to pull up the legacy spec
Modicon
Modbus Protocol
Reference Guide
PI–MBUS–300 Rev. J

To find any mention of it.

I have my client digging up the documentation for the device to see if you can choose between Ascii and RTU.  
Even 20 years ago on most equipment you had a choice. I am hoping there is some dipswitch somewhere to flick.

ATU

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 2126
  • YKPAIHA
    • ATU, Inc.
Re: Modbus TCP Ascii Protocol
« Reply #9 on: August 07, 2018, 02:40:26 PM »
Maybe, but you may be looking at Modbus/RTU (Ascii) over TCP, not Modbus/TCP.

So even if there is a choice, the protocol may be different from the BRX Modbus?

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6172
  • Yes Pinky, Do-more will control the world!
Re: Modbus TCP Ascii Protocol
« Reply #10 on: August 07, 2018, 04:50:02 PM »
So even if there is a choice, the protocol may be different from the BRX Modbus?

BRX Modbus/TCP is according to the spec I directed you to. There are a number of NotReallyModbusTCP implementations out there, including the Modbus/RTU over TCP I mentioned. I'm sure they are all close to the spec, but in comms, 'close' usually means 'doesn't work'.
"It has recently come to our attention that users spend 95% of their time using 5% of the available features. That might be relevant." -BobO

ATU

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 2126
  • YKPAIHA
    • ATU, Inc.
Re: Modbus TCP Ascii Protocol
« Reply #11 on: August 10, 2018, 02:28:38 PM »
OK, sending out and receiving data.

Sending out
:010303EC000C74<CR><LF>

Receiving
:01830478<CR><LF>

I found that 04 is an internal error in the slave?
My question is the LRC value. I used CHecksum and then the STRPRINT function using FmtInt(D10,hex,2,zeropad) "$0D$0A" where D10 is the LRC value. Is the LRC value supposed to be converted to ASCII?


« Last Edit: August 10, 2018, 03:44:42 PM by ATU »

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6172
  • Yes Pinky, Do-more will control the world!
Re: Modbus TCP Ascii Protocol
« Reply #12 on: August 10, 2018, 03:45:57 PM »
Exception code 4 is Slave Device Failure.

Not sure what it means in this context.
"It has recently come to our attention that users spend 95% of their time using 5% of the available features. That might be relevant." -BobO

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6172
  • Yes Pinky, Do-more will control the world!
Re: Modbus TCP Ascii Protocol
« Reply #13 on: August 10, 2018, 03:48:23 PM »
My question is the LRC value. I used CHecksum and then the STRPRINT function using FmtInt(D10,hex,2,zeropad) "$0D$0A" where D10 is the LRC value. Is the LRC value supposed to be converted to ASCII?

It appears so from my brief web search.
"It has recently come to our attention that users spend 95% of their time using 5% of the available features. That might be relevant." -BobO

ATU

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 2126
  • YKPAIHA
    • ATU, Inc.
Re: Modbus TCP Ascii Protocol
« Reply #14 on: August 10, 2018, 04:05:29 PM »
I looked up on the  Simply Modbus website on how to calculate the LRC. It was different than what the CHECKSUM instruction gave me. I hard coded that number in the request string and it works! I get the data. Not sure why it didn't.

This is the request string that works

:010303EC000B02

When I used Checksum on that string (prior to adding the Checksum), it calculated a 75 using an Offset of 1 so it doesn't include the ':'
« Last Edit: August 10, 2018, 04:17:22 PM by ATU »