VBA Wite to PLC Troubles

Gadelric

Member
Join Date
Nov 2018
Location
Midwest
Posts
137
Team,

I am a plc guy that has been tasked with making an automated report with excel. I have been successful with everything (with lots of searching on this forum) except writing a value back to the PLC.

The sample code structure given in RSlinx OEM help is as follows:
Sub Word_Write()

RSIchan = DDEInitiate("RSLinx", "testsol")

DDEPoke RSIchan, "N7:30", Range("[RSLINXXL.XLS]DDE_Sheet!D7")

DDETerminate (RSIchan)

End Sub

I removed the comments to reduce space.

My first issue is ddeInitiate. When I process this line, I get an error that RSLinx.exe is missing or inaccessible.

I don't need to start RSLinx OEM as it is already running.

What I want to do is to move a value from active sheet [I1] into
"=RSLINX|F2905_Snap!'Program:MainProgram.Index_Pointer'"

This link works, as I am using this value to tell my application how many rows to populate.

Index Pointer is a DINT data type.

I am probably over thinking this and causing my own troubles. Any advice will be appreciated.

Gad
 
Team,

I am a plc guy that has been tasked with making an automated report with excel. I have been successful with everything (with lots of searching on this forum) except writing a value back to the PLC.

The sample code structure given in RSlinx OEM help is as follows:
Sub Word_Write()

RSIchan = DDEInitiate("RSLinx", "testsol")

DDEPoke RSIchan, "N7:30", Range("[RSLINXXL.XLS]DDE_Sheet!D7")

DDETerminate (RSIchan)

End Sub

I removed the comments to reduce space.

My first issue is ddeInitiate. When I process this line, I get an error that RSLinx.exe is missing or inaccessible.

I don't need to start RSLinx OEM as it is already running.

What I want to do is to move a value from active sheet [I1] into
"=RSLINX|F2905_Snap!'Program:MainProgram.Index_Pointer'"

This link works, as I am using this value to tell my application how many rows to populate.

Index Pointer is a DINT data type.

I am probably over thinking this and causing my own troubles. Any advice will be appreciated.

Gad


Your code looks kinda like I remember.

I had no luck with "RSLINX". I had to put the full path to my RSLinx, like 'C:\Windows\Program\RSlinx.exe' ... that's not right, just an example.

If your initiate does not work, nothing else will.

There are lab demos that you can download. I got a copy from RAOTM (Rockwell Automation On the Move). I can't locate them right now ... but I think you can find them in the Rockwell knowledgebase as well. The demos go through the process step by step for hands-on labs. I know this because that's the only place I've made this work. In My Humble Opinion DDE is far to ... unreliable .. flaky .. for production use. I have the grey hair to support that statement!

If you have a historian, it would be better to use a reporting package to fetch the information from your historian and print it pretty in the report.

I suggest doing it another way because I have had nothing but headaches whenever I have used DDE, and OPC Version 1. Stuff breaks whenever any one piece of software is upgraded - including windows, xl, rslinx, anti-virus .. etc. DDE drivers are notorious for zero security. They are likely more reliable as back doors than they are as data sources.

I have spent a *LOT* of money getting rid of DDE and OPC Version 1 from our systems. Excel may be a convenient way to do a report, but it is not a reliable way to do a report. Just because you CAN do something does not mean that you SHOULD do something. ;)
 
If you have RSLinx OEM or higher (paid version) and you have the DDE working well enough to read data, then the RSLinx license is okay, there is probably something not quite right with the write logic. The example in the RSLinx help file is extremely basic, and has no error trapping and it looks like that is what your code is based on. It has been a few years (like 10) since I did this, but I think I followed an example at MrPLC:

http://forums.mrplc.com/index.php?/files/file/543-excel-to-plc-thru-rslinx-demo/

If I have the right link, that file contains a much more robust script to handle the writes and should be of some value to you as an example to follow. I don't use Excel any more so I didn't even try to download that workbook to see if it will open in LibreOffice, it probably will, but I am quite sure it won't run without M***cel.

Anyway, if that isn't the right file, there are a few others over at MrPLC.com if you search for RSLinx and Excel.
 
With a paid version of RSLinx, as OkiePC mentioned, you can do OPC writes to a PLC. Create a TagGroup, add some tags to it. The knowledgebase has some rudimentary sample code, you can probably find some in this forum as well. I’ve used it both in the HMI and from Excel
 
RSIchan = DDEInitiate("RSLinx", "testsol")

DDEPoke RSIchan, "N7:30", Range("[RSLINXXL.XLS]DDE_Sheet!D7")

DDETerminate (RSIchan)

If RSLinx is running, open it, go to DDE/OPC >> Topic Configuration.

Click on your testsol topic in the left-hand pane. Does the target PLC get shown with a light gray highlight?

If not, your problem is that your topic isn't configured properly. Same if there isn't a "testsol" topic.
 
Thank you everyone for you assistance in this matter. I was able to get this to work and my excel project is now complete.
 

Similar Topics

I'm creating an HMI that has a recipe with 288 data point. It has 3 pieces of data for 96 segments. I need help with VBA code to copy all 288...
Replies
0
Views
123
Hi everyone Is it possible to change a button image in FactoryTalk View SE (v13.00) using VBA?
Replies
0
Views
69
Hi all. Currently I'm working on a VBa script for FTView. I would like to understand a bit better about some commands. 1) What are the...
Replies
3
Views
559
Hi all. I'm running a VBA code on my FTView which is actually working, but everytime I open the display that calls the VBA code, it throws the...
Replies
28
Views
1,659
I am wondering if anyone has created an alarm within a global object via VBA? Yes, I will explain. I have a global object. It references an...
Replies
1
Views
254
Back
Top Bottom