DDE Write a Null String

fitness_ted

Member
Join Date
Jan 2015
Location
gym
Posts
3
I'm a fairly experienced DDE user, and use Excel spreadsheets to manage recipe variables on my machines.


I have no problems reading an empty string from an empty string array in the processor, but I'm not sure how to write an empty string without DDE throwing an error - for instance, I'd like to be able to blank an entire recipe structure, without having to use a placeholder string like "Spare" or "Not Used".


Anybody have any insights? Processor is a 5069.
 
Right. If the data referenced in Cells() is null, an error occurs. If there's "" in the cell, that is written literally and appears as "" in the string tag.


Is there a way to use the DDEPoke command without a cell reference?


Code:
DDEPoke rslinx, "Recipe[" & i & "].Description", Cells(2, 5 + i)
 
In the ControlLogix world, clearing out a string is best accomplished by plc code. Using a COP instruction to clear a complex UDT works well. I know you want to avoid this, but it may still be the best way.

It has to do with the way strings are implemented in the processor. A string tag has a .DATA member that is a SINT array which holds the ASCII codes for the characters and a .LEN member that is the string length in characters.

Some methods of clearing a string simply set the .LEN to 0 and this works sometimes, but since it leaves the character data behind, you sometimes see trash in the tag. It depends on how it's displayed.

A more thorough way is to set the entire .DATA array to 0 and set .LEN to 0.

I do this by using a tag of the same type (usually a UDT) that is set to the values I want to initialize my working tags. I then use a COP instruction to initialize the working tag. You can trigger a bit from Excel that executes the COP if you like.

I think part of your problem is that you are doing this from Excel. Excel doesn't let you type just anything in a cell, it likes to be smart and guess what you really want and put that in instead. I'm guessing your blank cell is looking like a single null (ASCII 0).

It also may be that you are expecting RSLinx to be smarter than it is. You might try writing to "Recipe[" & i & "].Description.DATA" instead. Writing to the base tag may not produce the expected result. Writing to the .LEN should produce an "empty" result with character data left in the array, that may suit your needs.
 
Last edited:
Writing 0 to both the .LEN and .DATA works, thank you.
Code:
If Cells(x,x) = "" Then
DDEPoke rslinx, "Recipe[" & i & "].Description.LEN", Cells(x,x)
DDEPoke rslinx, "Recipe[" & i & "].Description.DATA", Cells(x,x)
The above lines work, but can it be accomplished without a cell reference? None of the below lines do anything - yet they don't produce errors.
Code:
DDEPoke rslinx, "Recipe[" & i & "].Description.LEN", 0
DDEPoke rslinx, "Recipe[" & i & "].Description.LEN", "0"
DDEPoke rslinx, "Recipe[" & i & "].Description.LEN", ""
 
Writing null does not seem possible

TLDR: I tried everything I could think of without success.



I think maybe the most meaningful way to erase a recipe from excel is to create a BOOL tag in the plc, use excel to set it to 1, then have the plc monitor the tag. The PLC would reset the tag and clear the recipe using an FLL instruction for the UDT/Array.



I tried the following and it does NOT write blank data, but it also does not throw an error, which sucks:


  • DDEPoke rslinx, Tag, 0
  • DDEPoke rslinx, Tag, vbNullString
  • DDEPoke rslinx, Tag, ""
  • DDEPoke rslinx, Tag, "0"
  • DDEPoke rslinx, Tag, cell.value
  • DDEPoke rslinx, Tag, vbNull
  • DDEPoke rslinx, Tag, Array(0)
  • DDEPoke rslinx, Tag, Array("")
I tried the following, and it wrote a blank string, but it immediately crashes excel afterwards.

  • DDEPoke rslinx, Tag & ",L1,C1", cell


I assigned a dummy cell, wrote the value 0 to it, and used it as a reference for the DDEPoke. This kind of works, but then all of the string tags end up with "0". You could write to the subtag .LEN, but you would need to know what datatype it is. It's clunky any way you slice it.


I've also used an if statement in VBA to see if the cell is blank, and it if is blank, then I write 0 to .LEN, but this is risky and assumes that a blank implies a string tag.
 

Similar Topics

I am sure there are people out there who use Excel to transfer data to and from a ControlLogix using DDE via custom VBA code. For those of you...
Replies
2
Views
5,020
Hi All Can anyone show me a code snippet in v.b. using DDE that can read tags from rslinx? Thanks
Replies
1
Views
3,740
Is there any way that I can write data from Microsoft Excel into a AB PLC processor via a RXLINX DDE server if so what is the code instuction that...
Replies
5
Views
11,464
I need to support some old data collection that is running on Excel, but I need to get it running on LibreOffice. The following statement works...
Replies
0
Views
98
Hey Friends. I am currently trying to write approximately 700 tags from FtView13 to an Logix Emulate 5000. I am using rslinx DDE/OPC to create an...
Replies
0
Views
409
Back
Top Bottom