Read String out of CLX with Excel

ak0004

Member
Join Date
Mar 2010
Location
NRW
Posts
10
Hi folks

I am trying to read out a couple of strings with this Code

Code:
Sub weigher()

rslinx = DDEInitiate("RSLINX", "Mermaid_04")
For i = 0 To 100


'Get the value form the DDE link
weigherdata = DDERequest(rslinx, "Program:ComSock02_TCPClient.History[" & i & "].String_Data.DATA,L1,C1")


'If there is an error, display a message box
If TypeName(Data) = "Error" Then
If MsgBox("Error reading tag ComSock02_TCPClient.History[" & i & "]String_Data.DATA" & _
"Continue with Read?", vbYesNo + vbExclamation, _
"Error") = vbNo Then Exit For
Else



'No error, place data in cell
Cells(2 + i, 1) = weigherdata
End If
Next i

    
    'Terminate the DDE connection
    DDETerminate rslinx
    
End Sub
I am getting only "74" back into excel...?!?!? But when i look into the CLX there is an complete string an no "74"

any idea where i did the misstake?
 
74 is ASCII code 'G', is there any 'G' in the string?
Then you know what you need to convert from ' weigherdata'
 
The way that Rockwell's Logix platform stores strings is with a DINT that holds the length of the string and an array of SINTs that contain the characters of the string. In your case String_Data.LEN will contain the length of the string and String_Data.Data will be an array each element which will contain one string character. Your excel code is reading only the first element of the array and displaying its decimal representation. I did some quick experimenting with excel and got it to display a string by dropping the .Data from the end of the string tag, so I would try that.
 
The way that Rockwell's Logix platform stores strings is with a DINT that holds the length of the string and an array of SINTs that contain the characters of the string. In your case String_Data.LEN will contain the length of the string and String_Data.Data will be an array each element which will contain one string character. Your excel code is reading only the first element of the array and displaying its decimal representation. I did some quick experimenting with excel and got it to display a string by dropping the .Data from the end of the string tag, so I would try that.

Hi Ben, Thanks for this hint! You are right, the .DATA is not necessary.
But I found another misstake, which was not caused by Excel.
In the .LEN there was in every Array element an 0. Because i copied only the .DATA in the programm :eek:

So I changed this to the complete String and then it works.

Thanks vor your Help.

For all who want to use the Code, here the final working.

Code:
Sub weigher()

rslinx = DDEInitiate("RSLINX", "Mermaid_04") 'after "," this is the DDE Topic
For i = 0 To 99



'>>>Waagenstring<<<

weigherdata = DDERequest(rslinx, "Program:ComSock02_TCPClient.StringHistory[" & i & "]")
'If there is an error, display a message box
If TypeName(Data) = "Error" Then
If MsgBox("Error reading tag ComSock02_TCPClient.History[" & i & "]String_Data.DATA" & _
"Continue with Read?", vbYesNo + vbExclamation, _
"Error") = vbNo Then Exit For
Else
'No error, place data in Row A
Cells(2 + i, 1) = weigherdata
End If

Next i

'Terminate the DDE connection
DDETerminate rslinx 
    
End Sub
 
Write String to Logix 5000 (ControlLogix, CompactLogix) using DDE and VBA

AK004,

Thanks for the final code. Was very helpful for me.

For future reference for others. Here is code I used to write a string value. Make sure not to use .Value in your reference to the Excel cell holding your string...in this case Cells(20,1). If you use Cells(20,1).Value to read the string in the cell, the DDEPoke doesn't work. Excel will read the string properly...ie MsgBox(Cells(20,1).Value) displays the text in the cell, but the DDE doesn't work. That was a little tip I learned on another post in the forum.

Also not to confuse people, TEST_STRING_ARR is an array of strings in the Controllogix. Since the strings themselves are arrays of INTs it can get confusing, but for this code you just refer to the string tag itself, no need to drill down to the .LEN or .DATA[] pieces of the string...Rockwell site has a bunch of KB's about strings mentioning those parts of the datatype, but they're not needed for this to work.

Code:
Private Sub CommandButton2_Click()
Dim lngDDE_Chan As Long

lngDDE_Chan = DDEInitiate("RSLINX", "SPECTRA_DEV_1") 'after "," this is the DDE Topic

DDEPoke lngDDE_Chan, "TEST_STRING_ARR[0]", Cells(20, 1)
'Terminate the DDE connection
DDETerminate rslinx
End Sub
 
Minor code upate

Oops
My terminate command had wrong channel reference. Still worked (not sure why, maybe with only one channel open it defaults to the correct value), but not good programming practice!

Should look like this.

Code:
Private Sub CommandButton2_Click()
Dim lngDDE_Chan As Long

lngDDE_Chan = DDEInitiate("RSLINX", "SPECTRA_DEV_1") 'after "," this is the DDE Topic

DDEPoke lngDDE_Chan, "TEST_STRING_ARR[0]", Cells(20, 1)

'Terminate the DDE connection
DDETerminate lngDDE_Chan

End Sub
 

Similar Topics

Hello, So i managed to read the string coming from control logix and put a string display in PanelView 800. Now I am struggling to do the other...
Replies
1
Views
153
Good day. The problem is the following, I am using the Machine shop parker program to program an HMI that communicates with a logix5573 PLC. I can...
Replies
0
Views
1,267
Good day. The problem is the following, I am using the Machine shop parker program to program an HMI that communicates with a logix5573 PLC. I can...
Replies
1
Views
1,401
Hi, I'm pretty new to FactoryTalk and PLC's in general. In View SE, is it possible to read a string contained in a UDT and use it in another tag...
Replies
1
Views
1,240
Back
Top Bottom