Yes You are Right About this point Archie. I did not take care enough to this point as it is not affect the run in normal condition so as I suggested yesterday I found that adding a new version of ModbusPDUFrame Dedicated for RTU and Leave the Old one for TCP as is will be one possibility and the code should be like this
Namespace MfgControl.AdvancedHMI.Drivers.Modbus
Public Class ModbusPDUFrame
'***************** The old Method Dedicated For TCP And whatever other callers need AS Is no thing changed
Public Sub New(ByVal packet As Byte(), ByVal length As Integer, ByVal offset As Integer)
Me.FullPacket = New List(Of Byte)
If (offset < 0) Then
offset = 0
End If
Me.m_FunctionCode = packet((0 + offset))
If ((Me.m_FunctionCode >= &H80) AndAlso (packet.Length > 1)) Then
Me.m_ExceptionCode = packet((1 + offset))
Else
Me.m_ExceptionCode = 0
End If
Me.m_EncapsulatedData = New List(Of Byte)
If ((length + offset) > packet.Length) Then
length = (packet.Length - offset)
End If
Dim num2 As Integer = (length - 1)
Dim i As Integer = (2 + offset)
Do While (i <= num2)
Me.m_EncapsulatedData.Add(packet(i))
i += 1
Loop
End Sub
'***************************************************************
'***************** The New Added One Dedicated For RTU tailored on the RTU Requirements
Public Sub New(ByVal packet As Byte(), ByVal lengthOfThePacket As Integer, ByVal offset As Integer, ByVal It_Is_RTU As Integer)
Me.FullPacket = New List(Of Byte)
If (offset < 0) Then
offset = 0
End If
Me.m_FunctionCode = packet(1)
If ((Me.m_FunctionCode >= &H80) AndAlso (packet.Length > 1)) Then
Me.m_ExceptionCode = packet(2)
Else
Me.m_ExceptionCode = 0
End If
Me.m_EncapsulatedData = New List(Of Byte)
If ((lengthOfThePacket) > packet.Length) Then
lengthOfThePacket = (packet.Length)
End If
Dim newPacketLength As Integer = (lengthOfThePacket - 1)
Dim i As Integer = 2
Do While (i <= newPacketLength)
Me.m_EncapsulatedData.Add(packet(i))
i += 1
Loop
End Sub
'Stop **********************************************************************************
Namespace MfgControl.AdvancedHMI.Drivers.ModbusRTU
Public Class ModbusRTUFrame
Public Sub New(ByVal packet As Byte(), ByVal length As Integer, ByVal RTU As Integer)
Me.FullPacket = New List(Of Byte)
Me.m_StationAddress = packet(0)
'***********************************
Dim Offset As Integer = 1
Dim Is_It_RTU As Integer = 1
'***********************************
Me.m_PDU = New ModbusPDUFrame(packet, packet.Length, Offset, Is_It_RTU)
End Sub
Namespace ModbusRTU
Public Class ModbusRTUCom
Dim IT_IS_RTU As Integer = 1
Dim RTU As New ModbusRTUFrame(New List(Of Byte)(e.RawData).ToArray, e.RawData.Count, IT_IS_RTU)
Now It is work Great
Thank you so much dear