AdvancedHMI Software
General Category => Open Discussion => Topic started by: aquilmustafa on November 30, 2016, 08:11:18 PM
-
Hey Archie,
I've been Omron Ethernet Fins Driver from v3.99r to write String to array of (D200.....44) of data type string defined in Omron PLC. I've written code to do so. The code is as follows:
Public Function StrToHex(ByRef Data As String) As String
Dim sVal As String
Dim sHex As String = ""
While Data.Length > 0
sVal = Conversion.Hex(Strings.Asc(Data.Substring(0, 1).ToString()))
Data = Data.Substring(1, Data.Length - 1)
sHex = sHex & sVal
End While
Return sHex
End Function
The problem with this code is it only writes to 1 character to array of strings and leaves all the other characters.
Could you please guide me as to where i'm going wrong.
-
Is this what you want to do:
Dim x() As Integer = MfgControl.AdvancedHMI.Drivers.Common.CalculationsAndConversions.StringToWords("ABC")
Dim XasString(x.Length - 1) As String
For i = 0 To x.Length - 1
XasString(i) = CStr(x(i))
Next
OmronEthernetFINSCom1.Write("D0", XasString)
-
or maybe this:
Dim vals() As String = OmronEthernetFINSCom1.Read("D0", 10)
Dim StringResult As String = MfgControl.AdvancedHMI.Drivers.Common.CalculationsAndConversions.WordsToString(vals)
-
Hi Archie,
Thanks a ton for the fast reply.
Hope you have some solution for ComError and DataReturn property of Omron Ethernet fins protocol. They actually don't work at all since i'm used to Ethernet Clx protocol's response time.
Thanks a ton for this awesome project.
-
Hey Archie,
Just got to try the write String command you send. Was unable to transfer even a single character to the PLC.
Any other tricks up your sleeves that would help me resolve this problem.
-
Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles Button1.Click
Dim s As Integer = Convert.ToInt32("A"c)
Dim x() As Integer = StringToWords("ABC")
Dim XasString(x.Length - 1) As String
For i = 0 To x.Length - 1
XasString(i) = CStr(x(i))
Next
OmronEthernetFINSCom1.Write("D10", XasString)
End Sub
Public Shared Function StringToWords(ByVal source As String) As Int32()
If source Is Nothing Then
Return Nothing
' Throw New ArgumentNullException("input")
End If
Dim ArraySize As Integer = Convert.ToInt32(Math.Ceiling(source.Length / 2)) - 1
Dim ConvertedData(ArraySize) As Int32
Dim i As Integer
While i <= ArraySize
ConvertedData(i) = Convert.ToInt32(Convert.ToChar(source.Substring(i * 2, 1))) * 256
'* Check if past last character of odd length string
If (i * 2) + 1 < source.Length Then ConvertedData(i) += Convert.ToInt32(Convert.ToChar(source.Substring((i * 2) + 1, 1)))
i += 1
End While
Return ConvertedData
End Function
-
Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles Button1.Click
Dim s As Integer = Convert.ToInt32("A"c)
Dim x() As Integer = StringToWords("ABC")
Dim XasString(x.Length - 1) As String
For i = 0 To x.Length - 1
XasString(i) = CStr(x(i))
Next
OmronEthernetFINSCom1.Write("D10", XasString)
End Sub
Public Shared Function StringToWords(ByVal source As String) As Int32()
If source Is Nothing Then
Return Nothing
' Throw New ArgumentNullException("input")
End If
Dim ArraySize As Integer = Convert.ToInt32(Math.Ceiling(source.Length / 2)) - 1
Dim ConvertedData(ArraySize) As Int32
Dim i As Integer
While i <= ArraySize
ConvertedData(i) = Convert.ToInt32(Convert.ToChar(source.Substring(i * 2, 1))) * 256
'* Check if past last character of odd length string
If (i * 2) + 1 < source.Length Then ConvertedData(i) += Convert.ToInt32(Convert.ToChar(source.Substring((i * 2) + 1, 1)))
i += 1
End While
Return ConvertedData
End Function
Hey Archie,
I've tested this code but this too does not send any data through to PLC. The value in string array is completely empty. Please suggest if you have any other tricks up your sleeves.
-
I ran this exact code and it worked as expected for me:
Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles Button1.Click
Dim x() As Integer = StringToWords("ZYXWVU")
Dim XasString(x.Length - 1) As String
For i = 0 To x.Length - 1
XasString(i) = CStr(x(i))
Next
OmronEthernetFINSCom1.Write("D10", XasString)
End Sub
Public Shared Function StringToWords(ByVal source As String) As Int32()
If source Is Nothing Then
Return Nothing
' Throw New ArgumentNullException("input")
End If
Dim ArraySize As Integer = Convert.ToInt32(Math.Ceiling(source.Length / 2)) - 1
Dim ConvertedData(ArraySize) As Int32
Dim i As Integer
While i <= ArraySize
ConvertedData(i) = Convert.ToInt32(Convert.ToChar(source.Substring(i * 2, 1))) * 256
'* Check if past last character of odd length string
If (i * 2) + 1 < source.Length Then ConvertedData(i) += Convert.ToInt32(Convert.ToChar(source.Substring((i * 2) + 1, 1)))
i += 1
End While
Return ConvertedData
End Function
Attached are pictures of the data monitor before and after clicking the button.
-
Hey Archie,
While trying to write string it throws error in HostLinkBaseCom.vb at line 191 which throws error as " Invalid Hexadecimal Value" on my side.
Could you please guide me what is it that I am doing wrong.