Dustin And Ron!!! you are the best......
Many thanks for both you're efforts I have it POKING lol..
But I have a few questions about it...
Not going to post them yet AS I want to see (now with the proper format) if I can get the same results to just trigger a BIT instead of an integer. I have 3 buttons working as of now.....
So my hat is off to both of you as usual!!!!!
Thanks So much, Both of you
Matt
Matt,
Glad to help, and glad to hear that you've got it working. You shouldn't have any problems "POKING" a bit either using the same method. However, if you are going to set a bit high then you can't just do DDEPoke rslinx, "B3:0/0", 1. You have to use a cell value that CONTAINS a one. I've learned that through experience. Seems stupid that you can't just directly code a "1" or "0" for a bit reference, but VBA is an object-oriented language...
OkiePC said:
Or better yet, make it a field on the spreadsheet, so the user can edit the DDE/OPC Topic name at runtime.
Good idea, Paul.
I'll definitely be using that one next time I've got to do any DDE work.
It doesn't have the error checking like yours that would be useful if the DDE topic fails I promise to steal that little snippet for mine, thanks.
Hey feel free, brother. That piece of code is just copied from either a KB article or an excel forum, can't remember which, but I will see if I can dig up the link. I was just trying to illustrate for the OP the basic concepts involved in writing data into a PLC register using DDE/OPC on RSLinx. I would add that if writing into a PLC register from an Excel cell, adding some code to make sure the cell value is numeric, and fits within the bounds of signed 16-bit architecture is probably a good idea. Such as:
Code:
If IsNumeric(Range("A1")) Then
If Range("A1") >= -32768 And Range("A1") <= 32767 Then
DDEPoke rslinx, "N7:0", Range("A1")
Else
MsgBox "Error Cell Value must be >= -32768 and <= 32767", vbExclamation, "Error"
End If
Else
MsgBox "Error attempting to write non-numeric value to PLC Integer Register", vbExclamation, "Error"
End If
But it has working examples of DDE Poke, and you can see the VBA code I used.
Very nice work, Paul. I will definitely be keeping that guy in my toolbag. I really like how you totalized all the bit columns into an integer value for the write. Didn't know about the "ISBLANK" function, nice way to do an MVM in excel.
Might take a lot of work, but one thing I would suggest is to have some error checking on the "PLC Base Address" field. You'd want to make sure that the value is not only in valid PLC/SLC addressing format, but that it is an existing data table in the target PLC. Also you'd want to ensure that DataFile + DataLength <= the highest address in the data file.
I have no idea if all that information can be extracted from RSLinx into VBA, and then again it may be overkill, but it would be handy to have in there...