Author Topic: Omron Ethernet Fins String Value Read Write  (Read 3852 times)

aquilmustafa

  • Full Member
  • ***
  • Posts: 121
    • View Profile
Omron Ethernet Fins String Value Read Write
« 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.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5269
    • View Profile
    • AdvancedHMI
Re: Omron Ethernet Fins String Value Read Write
« Reply #1 on: November 30, 2016, 08:53:21 PM »
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)


Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5269
    • View Profile
    • AdvancedHMI
Re: Omron Ethernet Fins String Value Read Write
« Reply #2 on: November 30, 2016, 08:55:59 PM »
or maybe this:

        Dim vals() As String = OmronEthernetFINSCom1.Read("D0", 10)
        Dim StringResult As String = MfgControl.AdvancedHMI.Drivers.Common.CalculationsAndConversions.WordsToString(vals)

aquilmustafa

  • Full Member
  • ***
  • Posts: 121
    • View Profile
Re: Omron Ethernet Fins String Value Read Write
« Reply #3 on: November 30, 2016, 11:37:34 PM »
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.

aquilmustafa

  • Full Member
  • ***
  • Posts: 121
    • View Profile
Re: Omron Ethernet Fins String Value Read Write
« Reply #4 on: December 01, 2016, 04:12:28 AM »
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.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5269
    • View Profile
    • AdvancedHMI
Re: Omron Ethernet Fins String Value Read Write
« Reply #5 on: December 01, 2016, 10:52:45 AM »
Code: [Select]
   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

aquilmustafa

  • Full Member
  • ***
  • Posts: 121
    • View Profile
Re: Omron Ethernet Fins String Value Read Write
« Reply #6 on: December 02, 2016, 07:59:38 AM »
Code: [Select]
   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.



Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5269
    • View Profile
    • AdvancedHMI
Re: Omron Ethernet Fins String Value Read Write
« Reply #7 on: December 03, 2016, 02:08:00 PM »
I ran this exact code and it worked as expected for me:
Code: [Select]
    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.

aquilmustafa

  • Full Member
  • ***
  • Posts: 121
    • View Profile
Re: Omron Ethernet Fins String Value Read Write
« Reply #8 on: January 13, 2017, 04:12:11 AM »
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.