Author Topic: ASCII ARRAY WITH CLX CONTROLLER  (Read 3802 times)

aquilmustafa

  • Full Member
  • ***
  • Posts: 121
    • View Profile
ASCII ARRAY WITH CLX CONTROLLER
« on: June 04, 2016, 05:48:25 AM »
Hey,

I've been trying to read and write the RFID data from CLx controller and have been successful in reading them from PLC. In PLC we have created a ASCII Array into which RFID  data is read. That data is now stored in the DB. Now when the PLC asks for RFID data with suffix to be written in PLC into the same ASCII Array. I've been using this command to do so.

 strx = AtStation.Text
                    If strx <> "" Or strx <> "0" Then
                        For i = 1 To strx.Length
                            str_arr(i) = Mid(strx, i, 1)
                        Next
                        EthernetIPforCLXCom1.Write("RFID_SEARCH_RESULT.DATA[0]", str_arr.Length - 1, str_arr)
                    End If
                End If

But EthernetIPforCLXCom1.Write throws an error

{"Conversion from string ""D"" to type 'Double' is not valid."}

Please help..

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: ASCII ARRAY WITH CLX CONTROLLER
« Reply #1 on: June 04, 2016, 07:39:39 AM »
There is no ASCII atomic data type in a ControlLogix. A string is made up of an array of SINT. Before trying to write your character, you need to convert it to a byte.

Dim b() As Byte
b = System.Text.Encoding.ASCII.GetBytes(strx)
EthernetIPforCLXCom1.Write("RFID_SEARCH_RESULT.DATA[0]",b)


Are you writing to a custom length string in the CLX?

aquilmustafa

  • Full Member
  • ***
  • Posts: 121
    • View Profile
Re: ASCII ARRAY WITH CLX CONTROLLER
« Reply #2 on: June 04, 2016, 07:57:28 AM »
Yes I'm writing to a custom length of an array of 20 Sint of data type ASCII

While trying your code it throws below given error

Severity   Code   Description   Project   File   Line   Suppression State
Error   BC30518   Overload resolution failed because no accessible 'Write' can be called with these arguments:
    'Public Function Write(startAddress As String, dataToWrite As Integer) As Integer': Value of type 'Byte()' cannot be converted to 'Integer'.
    'Public Function Write(startAddress As String, dataToWrite As Single) As Integer': Value of type 'Byte()' cannot be converted to 'Single'.
    'Public Function Write(startAddress As String, dataToWrite As Single()) As Integer': Value of type 'Byte()' cannot be converted to 'Single()' because 'Byte' is not derived from 'Single'.
    'Public Function Write(startAddress As String, dataToWrite As Integer()) As Integer': Value of type 'Byte()' cannot be converted to 'Integer()' because 'Byte' is not derived from 'Integer'.
    'Public Function Write(startAddress As String, dataToWrite As String) As String': Value of type 'Byte()' cannot be converted to 'String'.   AdvancedHMI   H:\CLIENTS\ORBITAL\FINAL MAIN SCADA 19May2016\AdvancedHMIBetaV399f\AdvancedHMI\CRADLS.vb   8344   Active
« Last Edit: June 04, 2016, 08:04:19 AM by aquilmustafa »

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: ASCII ARRAY WITH CLX CONTROLLER
« Reply #3 on: June 04, 2016, 08:23:01 AM »
EthernetIPforCLXCom1.Write("RFID_SEARCH_RESULT.DATA[0]",b.length,b)

aquilmustafa

  • Full Member
  • ***
  • Posts: 121
    • View Profile
Re: ASCII ARRAY WITH CLX CONTROLLER
« Reply #4 on: June 04, 2016, 08:55:06 AM »
Hey Archie,

Still same error is thrown

Severity   Code   Description   Project   File   Line   Suppression State
Error   BC30518   Overload resolution failed because no accessible 'Write' can be called with these arguments:
    'Public Function Write(startAddress As String, numberOfElements As Integer, dataToWrite As Single()) As Integer': Value of type 'Byte()' cannot be converted to 'Single()' because 'Byte' is not derived from 'Single'.
    'Public Function Write(startAddress As String, numberOfElements As Integer, dataToWrite As Integer()) As Integer': Value of type 'Byte()' cannot be converted to 'Integer()' because 'Byte' is not derived from 'Integer'.
    'Public Function Write(startAddress As String, numberOfElements As Integer, dataToWrite As String()) As Integer': Value of type 'Byte()' cannot be converted to 'String()' because 'Byte' is not derived from 'String'.   AdvancedHMI   H:\CLIENTS\ORBITAL\FINAL MAIN SCADA 19May2016\AdvancedHMIBetaV399f\AdvancedHMI\CRADLS.vb   8362   Active

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: ASCII ARRAY WITH CLX CONTROLLER
« Reply #5 on: June 04, 2016, 09:02:26 AM »
I will have to set up and try this later. One meths that should work is to create a string array and write each byte from the byte array into it, then use the string array in the Write.

aquilmustafa

  • Full Member
  • ***
  • Posts: 121
    • View Profile
Re: ASCII ARRAY WITH CLX CONTROLLER
« Reply #6 on: June 04, 2016, 08:47:04 PM »
Hey Archie,

Even that is not working on my side. Any other options in your magic box:)

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: ASCII ARRAY WITH CLX CONTROLLER
« Reply #7 on: June 05, 2016, 08:46:37 AM »
I was able to test my code and this is what I came up with:

OPTION 1:
Code: [Select]
        '* Extract the string into an array of bytes
        Dim b() As Byte = System.Text.Encoding.ASCII.GetBytes("ABC")

        '* Convert the byte values into strings
        Dim s(b.Length - 1) As String
        For i = 0 To b.Length - 1
            s(i) = b(i).ToString
        Next

        '* Write to the PLC
        EthernetIPforCLXCom1.Write("StringTag.DATA[0]", s.Length, s)

OPTION 2:
If you wanted to clean up your code, this can be encapsulated into the driver like this:
- In Solution Explorer, expand down the AdvancedHMIDrivers project
- Expand down the AllenBradley folder
- Right click EthernetIPforCLXCom.vb and select View Code
- Scroll all the way to the bottom and insert the following code just above "End Class"
Code: [Select]
    Public Overloads Sub Write(ByVal startAddress As String, ByVal dataToWrite() As Byte)
        '* Convert the byte values into strings
        Dim s(dataToWrite.Length - 1) As String
        For i As Integer = 0 To dataToWrite.Length - 1
            s(i) = dataToWrite(i).ToString
        Next

        '* Write to the PLC
        Write(startAddress, s.Length, s)
    End Sub

- Now back to your code, it can now be simplified like this:
Code: [Select]
        Dim b() As Byte = System.Text.Encoding.ASCII.GetBytes(strX)
        EthernetIPforCLXCom1.Write("RFID_SEARCH_RESULT.DATA[0]", b)

aquilmustafa

  • Full Member
  • ***
  • Posts: 121
    • View Profile
Re: ASCII ARRAY WITH CLX CONTROLLER
« Reply #8 on: June 07, 2016, 01:26:18 PM »
Hey Archie,

Thanks a lot for the solution. But I'll be able to check this solution only after the next week..