Help - Search - Members - Calendar
Full Version: Vb Script And Excel Multitask
Forums.MrPLC.com > PLCs and Supporting Devices > Allen Bradley
Chris Elston
Got a question.

I have a project that has five manual stations. Each station has a load cell. I wanted to take readings from each load cell through DDE and dump that into Excel.

I've written very little of VB and VB Script so my knowledge of how Visual Basic behaves is limited.

Each of my stations can trigger at different times, operator driven. Can I write my "trigger" code in Excel (VB Script) in five different sub routines, and will VB Script (VB Code) multitask the triggers?

So no matter what trigger is fired from any of the stations, will each of the five sub routines run independently in VB?

Even if I call Trigger2 and call Trigger3 at the SAME TIME, will both sub routines run simultaneously?

Something like this:

CODE
Sub Trigger1()

   RSIchan = DDEInitiate("RSLinx", "STATION1")      'opens DDE link
   
   data = DDERequest(RSIchan, "F11:0")     ‘assign “DATA” to F11:0
   Windows("logger.xls").Activate                    'looks for sheet logger
    Sheets("LOG").Select                              'Make Sure Log sheet is Active
   Cells(1, 1).Value = data                         'read word 0

   DDETerminate (RSIchan)                          'close DDE link

Sub Trigger2()

   RSIchan = DDEInitiate("RSLinx", "STATION2")      'opens DDE link
   
   data = DDERequest(RSIchan, "F11:1")     ‘assign “DATA” to F11:1
   Windows("logger.xls").Activate                    'looks for sheet logger
    Sheets("LOG").Select                              'Make Sure Log sheet is Active
   Cells(1, 2).Value = data                         'read word 1

   DDETerminate (RSIchan)                          'close DDE link

Sub Trigger3()

   RSIchan = DDEInitiate("RSLinx", "STATION3")      'opens DDE link
   
   data = DDERequest(RSIchan, "F11:2")     ‘assign “DATA” to F11:2
   Windows("logger.xls").Activate                    'looks for sheet logger
    Sheets("LOG").Select                              'Make Sure Log sheet is Active
   Cells(1,32).Value = data                         'read word 2

   DDETerminate (RSIchan)                          'close DDE link

monkey
Chris,

I haven't done what your talking about, but I would have to guess no on the multitasking of VB and certainly RSLinx is communicating serially (one bit at a time) to your PLC so it can't happen simultaneously regardless of what VB does. I would imagine though that the delay between the trigger and the actual data retrieval would be very small. If you need to have an exact instantaneous value I would recommend "latching" the value (and possibly a timestamp if needed) in the PLC when the trigger event occurs. Then it really doesn't matter when you get the info to excel as long as it is before the next trigger

Best of luck,

monkey
Chris Elston
monkey,

You've got a good point on the serial comms.

I guess I really don't need the data at the same exact time. I was more concerned with missing a trigger from one of the operators if one stations was triggered to read the load cell vaule, then the next station was also triggered shortly behind. Would the second station, or the station that was triggered later miss the trigger because the first subroutine is already running?

That was mostly my concern.
monkey
Chris,

How is the trigger physically connected to the PC? Is the trigger a pulse? If so you can make the pulse length longer then the time it takes to run the subroutine (5X) so it won't be missed.Can you send the trigger signal to the PLC and have the PLC decide when to send to the PC? Maybe you could have a "hot" DDE link (one that is open all the time) which would be constantly reading the data that is in the PLC.


Chris Elston
monkey,

Yeah your close. Generally what I do is setup up a workbook that has a hot DDE link. When that cell value changes, I call a Sub routine to execute and read words from the PLC.

Of course, the PLC is triggered by the operator by an opto button, but as far as triggering Excel, I'll have a workbook with a hot link setup and when that value changes, then I tell the sub routine to read the load cell. I figure at this point, I will have maybe five different workbooks, each with hot dde links, when each of those respectly change, they will call their own sub routines to execute and read from their own load cells. At least that is what I am hoping will happen.... lookaround.gif
Chris Elston
Here is the code what I do:
(Probablly pretty dumb, but I am still pretty new to VB and VB Script)

I've not been able to figure out how to make VB look for a "1" or "0" change of state on this worksheet using DDE Hot Link, so rather I look for ANY change of state or the "OnData" event to drive the triggers.


CODE

Sub Auto()
   
   Worksheets("INDATA1").OnData = "Trigger1"
   
   ' A bit change from the PLC Hot Linked on INDATA1
   ' will automaticly Run Macro (trigger1).

End Sub
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2010 Invision Power Services, Inc.