dcooper33
Lifetime Supporting Member + Moderator
Could you explain how you did this? Can you use Advanced HMI instead of a licensed version of Rslinx such as OEM?
You bet.
Archie and dmroeder were kind enough to help me set this up for the first time.
I have RSLinx OEM, but I actually needed to open Excel in the background, log PLC data, and save the spreadsheet, all from a single button-click without further user interaction.
This can be done without RSLinx (or Logix) altogether, all you need is an established connection to the PLC you want to pull data from.
The following code can be used as the sub to handle a vb button click. It will open an existing spreadsheet, pull the values in N7:0-99 (SLC or Micrologix processor in the example), and load them in a column in the spreadsheet.
You can modify this easily to apply to any data table and length of read. To use for another PLC, just substitute the appropriate driver in place of "EthernetIPforSLCMicroComm1".
(Before AdvancedHMI can interact with Excel, you have to add a reference to the project. From AdvancedHMI:
Project --> Add Reference.
Click on COM tab and scroll down to Microsoft Excel xx.x Object Library and click OK)
Code:
Private Sub Log_PLC_Data_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Log_PLC_Data_Button.Click
Dim PLC_Data_xlapp As Microsoft.Office.Interop.Excel.Application
Dim PLC_Data_wb As Microsoft.Office.Interop.Excel.Workbook
Dim PLC_Data_ws As Microsoft.Office.Interop.Excel.Worksheet
Dim PLC_Data_XL_Open As Boolean = False
If System.IO.File.Exists("C:\My Spreadsheet Folder\My PLC Log.xlsx") Then
PLC_Data_xlapp = New Microsoft.Office.Interop.Excel.Application
PLC_Data_wb = PLC_Data_xlapp.Workbooks.Open("C:\My Spreadsheet Folder\My PLC Log.xlsx")
PLC_Data_ws = PLC_Data_wb.Worksheets(1)
PLC_Data_XL_Open = True
Else
MsgBox("The spreadsheet you are wanting to load does not exist at ""C:\My Spreadsheet Folder\My PLC Log.xlsx"". Make sure spreadsheet is in correct location")
PLC_Data_XL_Open = False
End If
If PLC_Data_XL_Open = True Then
Dim data as Integer
For i As Integer = 0 To 99 'Read the values in N7:0-99 and load into Column in Excel
data = EthernetIPforPLCSLCMicroComm1.ReadAny("N7:" & i)
PLC_Data_ws.Cells(4 + i, 2).Value = data
Next
PLC_Data_ws.Range("A2").Value = Now
PLC_Data_wb.SaveAs("C:\My Spreadsheet Folder\My PLC Log.xlsx")
PLC_Data_wb.Close() 'Close the workbook
PLC_Data_xlapp.Quit() 'Close Excel
PLC_Data_ws = Nothing 'Release the worksheet from memory
PLC_Data_wb = Nothing 'Release the workbook from memory
PLC_Data_xlapp = Nothing 'Release Excel from memory
PLC_Data_XL_Open = False
End If
End Sub