I was able to test my code and this is what I came up with:
OPTION 1:
'* 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"
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:
Dim b() As Byte = System.Text.Encoding.ASCII.GetBytes(strX)
EthernetIPforCLXCom1.Write("RFID_SEARCH_RESULT.DATA[0]", b)