steveohara / j2mod

Enhanced Modbus library implemented in the Java programming language
Apache License 2.0
265 stars 111 forks source link

Does Modbus ASCII handle the longer max message length? #77

Closed NogginBops closed 6 years ago

NogginBops commented 6 years ago

Serial modbus with ASCII framing has a larger max message length than RTU. It dosen't look like this is handled in the code.

From the specification:

Each data byte needs two characters for encoding. Thus, to ensure compatibility at MODBUS application level between
ASCII mode and RTU mode, the maximum data size for ASCII data field (2x252) is the double the maximum data size for RTU data
field (252). Consequently, the maximum size of a MODBUS ASCII frame is 513 characters.
steveohara commented 6 years ago

Looks can be deceiving :)

Pairs of characters are converted into bytes as they are read from the request stream - ModbusSerialTransport.readAsciiByte

The buffers represent the number if bytes not characters read/written using the ASCII protocol.