19
« on: March 25, 2020, 05:30:41 PM »
I was checked that lines of code but its the same as you paste, nothing to do about converting etc.... But i check some FINSBaseCom.vb on latest AHMI and find some differences start at line 551 and below. Thats the code in my older version of AHMI'* Memory Area Read (FINS 1,2)
'* Reference : Section 5-3-3
Public Overrides Function BeginWrite(ByVal address As MfgControl.AdvancedHMI.Drivers.Omron.OmronPlcAddress, ByVal dataToWrite() As String) As Integer
If address Is Nothing Then Throw New ArgumentNullException("WriteData Address parameter cannot be null.")
'* No data was sent, so exit
If dataToWrite.Length <= 0 Then Return 0
Dim CurrentTNS As Byte
'* Save this
CurrentTNS = CByte(GetNextTransactionID(255))
Dim Header As New MfgControl.AdvancedHMI.Drivers.Omron.FINSHeaderFrame(MfgControl.AdvancedHMI.Drivers.Omron.GatewayCountOption.Three, TargetAddress, SourceAddress, CByte(CurrentTNS))
'* Save this TNS to check if data received was requested by this instance
'ActiveTNSs.Add(CurrentTNS)
'* Mark as a write and Save
address.IsWrite = True
Requests(CurrentTNS) = address
'* Attach the instruction data
Dim dataPacket As New List(Of Byte)
dataPacket.Add(address.MemoryAreaCode)
dataPacket.Add(CByte((address.ElementNumber >> 8) And 255))
dataPacket.Add(CByte((address.ElementNumber) And 255))
'* 24-SEP-15 A 0xff was going in the bit position if no bit specified. This is so returned data doesn't think a bit was requested
Dim BitNumberByte As Integer = Requests(CurrentTNS).BitNumber
If Requests(CurrentTNS).BitNumber < 0 Or Requests(CurrentTNS).BitNumber > 64 Then
BitNumberByte = 0
End If
dataPacket.Add(CByte(BitNumberByte))
dataPacket.Add(CByte((address.NumberOfElements >> 8) And 255))
dataPacket.Add(CByte((address.NumberOfElements) And 255))
If address.BitsPerElement = 16 Then
Dim x(1) As Byte
For i As Integer = 0 To dataToWrite.Length - 1
If m_TreatDataAsHex Then
Dim data As Integer
Try
data = Convert.ToUInt16(dataToWrite(i), 16)
Catch ex As Exception
Throw New MfgControl.AdvancedHMI.Drivers.Common.PLCDriverException("Invalid hexadecimal value " & dataToWrite(i))
End Try
x(0) = CByte(data And 255)
x(1) = CByte(data >> 8)
Else
x = BitConverter.GetBytes(CUShort(dataToWrite(i)))
If address.IsBCD Then
'* Convert to BCD
x(1) = CByte(CUShort(Math.Floor(CDbl(dataToWrite(i)) / 100)))
x(0) = MfgControl.AdvancedHMI.Drivers.Common.CalculationsAndConversions.HexToByte(Convert.ToString(CUShort(dataToWrite(i)) - (x(1) * 100)))
x(1) = MfgControl.AdvancedHMI.Drivers.Common.CalculationsAndConversions.HexToByte(Convert.ToString(x(1)))
End If
End If
'* Bitconverter uses LittleEndian
'* Omron uses BigEndian, so reverse
dataPacket.Add(x(1))
dataPacket.Add(x(0))
Next
Else
'* Bit level
For i As Integer = 0 To dataToWrite.Length - 1
If Convert.ToInt32(dataToWrite(i)) > 0 Then
dataPacket.Add(1)
Else
dataPacket.Add(0)
End If
Next
End If[code]