Skip to main content

Scada Notes

Q1. How do we have local variables on the PC ( not PLC ) that are accessible by all the different Iconics Applications ?
A1. Configure Items in Unified Data Manager so that the item is accessible by the GraphWorX  as well as ScriptWorX
Example : UDMConfig --> Registers (New Bool1, Writeable)

____________________________________________________________________________

Q2. How do we log PLC Item data to a .csv file

Trigger Tag is created in UDMConfig --> Registers (New Bool1, Writeable)
Configure Tag as reg:Bool1

Trigger is configured in the UDMConfig --> Event trigger --> Data Trigger (New) -> Data Trigger Options
Name : Bool1ChgTrig ( Trigger Name )
Condition : Execute when Tag changes to TRUE
Data Tag : reg:Bool1

In ScriptWorX2010 create a Thread, then create a script below it
Ensure that the script is stopped -  "RED TRAFFIC LIGHT" must be ON in ScriptWorX

Script : NewScript
Trigger Name : trg_data:Bool1ChgTrig
Click the "Apply" Button to create the new Script
Click "Edit VBA Code" to open the VB Editor and add / edit code in the "NewScript" that is associated with the Trigger

Save the code in the VB Editor



Right Click the Thread and click on "Make VBA Project dll"

Ensure that the Project, Thread and Script have "Enabled" checked in their respective configuration editors
Ensure that the script is turned ON-  "GREEN TRAFFIC LIGHT" must be ON in ScriptWorX


Option Explicit
Dim g As SWXRuntimeLib.Global
Dim objFSO As Scripting.FileSystemObject
Dim objLogFile As Scripting.TextStream
Public Sub NewScript(td As TriggerData)
    On Error GoTo ErrHandler
    ' TODO: Add your code here
   '------------------
    Const ForWriting = 2
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objLogFile = objFSO.CreateTextFile("C:\csv\" + "nff2" + ".csv", ForWriting, True)
    'comment text ~~a~~
    objLogFile.Write "~~a~~,"
    'comment text ramp
    objLogFile.Write "Ramp,"
    'comment text ~~c~~
    objLogFile.Write "~~c~~,"
    objLogFile.Writeline

    Dim opcval1 As Integer
    Dim opcval2 As Boolean
    Dim opcval3 As Double
   
    opcval1 = g.OPC.Read("Mitsubishi.MXOPC.6\fx5u.Group001.D2000")
    opcval2 = g.OPC.Read("Mitsubishi.MXOPC.6\fx5u.Group001.Tag001")
    opcval3 = g.OPC.Read("Mitsubishi.MXOPC.6\fx5u.Group001.D2002")
   
    objLogFile.Write opcval1
    objLogFile.Write ","
    objLogFile.Write opcval2
    objLogFile.Write ","
    objLogFile.Write opcval3
    objLogFile.Write ","
 
       '------------------

     g.ConsoleMsg MSG_INFO_VERBOSE, "Script", "Script Triggered"
    g.ConsoleMsg MSG_INFO_VERBOSE, "Mitsubishi.MXOPC.6\Module3.Common.Log_DATA", opcval1
    g.ConsoleMsg MSG_INFO_VERBOSE, "Mitsubishi.MXOPC.6\Module3.Common.Log_DATA1", opcval2
    Dim dbcon As New ADODB.Connection
    Dim dbrst As New ADODB.Recordset
   
    dbcon.ConnectionString = "Provider=SQLOLEDB;Data Source=MEI-PC-12-6052\SQLEXPRESS;Integrated Security=SSPI;Initial Catalog=TestDB;"
    dbcon.Open
   
    dbcon.Execute ("INSERT INTO dbo.Table_1(DateTime,Data1,Data2)VALUES(getdate()," & opcval1 & "," & opcval2 & ")")
    dbcon.Close
    Set dbcon = Nothing
   
    Exit Sub
ErrHandler:
    g.ConsoleMsg MSG_SEVERE_ERROR, "Script", "'NewScript' failed"
End Sub

Q3. How to Parse a .csv file
A3.
1. Using the Split() Function.
2. Data is made available to GraphWorX using the ScriptWorX2010 "GlobalVariables"

Option Explicit
Dim g As SWXRuntimeLib.Global
Dim objFSO As Scripting.FileSystemObject
Dim objLogFile As Scripting.TextStream

' Called once when a new designer/thread is started
Private Sub GlobalInstance_OnConnection(ByVal SwxGlobal As SWXRuntimeLib.Global, ByVal MTDllInst As Object, Custom() As Variant)
    On Error GoTo ErrHandler
    Set g = SwxGlobal
    ' TODO: Add your thread initialization code here
    g.Variables.Write "MyGlobalVariable1", "x", g.Thread.Identif
    g.Variables.Write "MyGlobalVariable2", "y", g.Thread.Identif
    g.Variables.Write "MyGlobalVariable3", "z", g.Thread.Identif
    g.Variables.Write "MyGlobalVariable4", "hey", g.Thread.Identif
    Exit Sub

ErrHandler:
    g.ConsoleMsg MSG_SEVERE_ERROR, "Designer", "'NewDesigner' OnConnection failed"
End Sub


Public Sub ReadCsvScript(td As TriggerData)
    On Error GoTo ErrHandler
    ' TODO: Add your code here
    Dim arr() As String
    Dim outputString As String
    Dim outputFile As Scripting.TextStream
    Dim inputFile As Scripting.TextStream
    Const ForWriting = 2
    Const ForReading = 1
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set outputFile = objFSO.CreateTextFile("C:\csv\" + "csvwrite.csv" + ".csv", ForWriting, True)
    Set inputFile = objFSO.OpenTextFile("C:\csv\" + "csvread.csv", ForReading)
    Do While inputFile.AtEndOfStream <> True
        arr = Split(inputFile.ReadLine, ",")
        outputString = Join(arr, ",")
        outputFile.WriteLine outputString
     
        '------------------------------------------
        ' need info if UDM tags are accesible in ScriptWorX2010
        'waiting for a miracle from Mitsubishi India
        'FirstReadValue = arr(1)
        'SecondReadValue = arr(2)
        'ThirdReadValue = arr(3)
        '------------------------------------------
     
        g.Variables.Write "MyGlobalVariable1", arr(0), g.Thread.Identif
        g.Variables.Write "MyGlobalVariable2", arr(1), g.Thread.Identif
        g.Variables.Write "MyGlobalVariable3", arr(2), g.Thread.Identif
        g.Variables.Write "MyGlobalVariable4", "hi", g.Thread.Identif
     

    Loop
outputFile.Close
inputFile.Close


    Exit Sub
ErrHandler:
    g.ConsoleMsg MSG_SEVERE_ERROR, "Script", "'ReadCsvScript' failed"
End Sub

Access the ScriptWorX2010 Global Variables in GraphWorX32 as  swx:Variable("MyGlobalVariable1")




Note that the text values should not have commas
supportstaff = ts.ReadLine

c = Split(supportstaff, ",")
Firstnm = c(0)
Lastnm = c(1)
logonnm = c(2)

Note the use of both the Split() and the Join() functions

Set outputFile = fso.OpenTextFile(FileName1, ForWriting, True)
Set inputFile = fso.OpenTextFile(FileName2, ForReading)
Do While inputFile.AtEndOfStream <> True
    arr = Split(inputFile.ReadLine, ",")
    arr(3) = "E"
    outputString = Join(arr, ",")
    outputFile.WriteLine outputString
Loop
Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.OpenTextFile("C:\Scripts\Test.txt", ForReading)
Do Until objFile.AtEndOfStream strLine = objFile.ReadLine arrFields = Split(strLine, ",")
If InStr(arrFields(1), "Everyone") Then strContents = strContents & arrFields(5) & vbCrlf End If Loop
objFile.Close
Set objFile = objFSO.CreateTextFile("C:\Scripts\Everyone.txt") objFile.Write strContents
objFile.Close

Q4. Where is the sample code ?
A4 : C:\Program Files (x86)\Mitsubishi Electric\MC Works\Examples



Q5. Code to write to PLC
A5.  g.OPC.Write "Mitsubishi.MXOPC.6\fx5u.Group001.D3030", 998.998

---------------------------------------------------------------------------------------------------------
Check latest code in next listing below

Script Name : ScriptWorX2010->Projects->ReadScopeCsv->Thread1->ReadScopeCsv
Trigger Name : trg_data:ReadScopeCsv
Trigger Configuration : UDMConfig -> Event Trigger -> Data Trigger -> ReadScopeCsv
                                       Execute Condition : When Data Tag Changes to True
                                       Data Tag : Mitsubishi.MXOPC.6\fx5u.Group001.ReadCsv

Final Code :

Public Sub ReadScopeCsv(td As TriggerData)
    On Error GoTo ErrHandler
    ' TODO: Add your code here
    ' final code
    Dim FolderName As String
    FolderName = g.OPC.Read("Mitsubishi.MXOPC.6\fx5u.Group001.D4502")
    Dim FolderName1 As String
    FolderName1 = Trim(FolderName)
 
    'ENSURE THAT FOLDER NAME CORRESPONDING TO WINDING SR NO IS CREATED AND CONTAINS THE FILE MeasLog.csv
    'ENSURE THAT THE SAME WINDING SR NO IS ENTERED IN THE HMI FIELD D4502
 
 
    Dim outputString As String
    Dim outputFile As Scripting.TextStream
    Dim inputFile As Scripting.TextStream
    Const ForWriting = 2
    Const ForReading = 1
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set outputFile = objFSO.CreateTextFile("C:\csv\" + "Logger.csv", ForWriting, True)
    outputFile.WriteLine FolderName + FolderName1
    Set inputFile = objFSO.OpenTextFile("C:\csv\" + FolderName1 + "\MeasLog.csv", ForReading)
 
    Dim temp As String
    temp = inputFile.ReadLine' read the 1st line and discard
    outputFile.WriteLine temp


    'Dim temp1() As String
    'temp1 = Split(inputFile.ReadLine, ",")
    'outputString = Join(temp1, ",")
    'outputFile.WriteLine outputString

    Dim Reading1() As String
    Dim BEmfRd1Ch1Rms As Double, BEmfRd1Ch2Rms As Double, BEmfRd1Ch3Rms As Double
    Dim Reading2() As String
    Dim BEmfRd2Ch1Rms As Double, BEmfRd2Ch2Rms As Double, BEmfRd2Ch3Rms As Double
    Dim Reading3() As String
    Dim BEmfRd3Ch1Rms As Double, BEmfRd3Ch2Rms As Double, BEmfRd3Ch3Rms As Double
    Dim Reading4() As String
    Dim BEmfRd4Ch1Rms As Double, BEmfRd4Ch2Rms As Double, BEmfRd4Ch3Rms As Double
    Dim Reading5() As String
    Dim BEmfRd5Ch1Rms As Double, BEmfRd5Ch2Rms As Double, BEmfRd5Ch3Rms As Double
    Dim Reading6() As String
    Dim BEmfRd6Ch1Rms As Double, BEmfRd6Ch2Rms As Double, BEmfRd6Ch3Rms As Double
 
    Dim value As Variant, qual As Variant
    Dim ts As Variant, tsms As Variant
    Set client = CreateObject("GenClientWrapper.Client")
    'tag3 = " ICONICS.Simulator.1\SimulatePLC.OUTPUTS.FLOAT1"

    Dim tag As String
    Dim dp1 As GENCLIENTWRAPPERLib.datapoint
    tag = "Mitsubishi.MXOPC.6\fx5u.Group001.D3030"
    Set dp1 = client.RequestDataPoint(tag, 1000, 0)
    'While dp1.State <> GC_POINT_OK_UPDATED
    ' Do nothing until point is ready
    'Wend
    'Get tag information
    'dp1.GetValueEtc value, qual, ts, tsms
 
 
    Dim dp2 As GENCLIENTWRAPPERLib.datapoint
    tag = "Mitsubishi.MXOPC.6\fx5u.Group001.D3032"
    Set dp2 = client.RequestDataPoint(tag, 1000, 0)
    'While dp2.State <> GC_POINT_OK_UPDATED
    ' Do nothing until point is ready
    'Wend
    'Get tag information
    'dp2.GetValueEtc value, qual, ts, tsms

    Dim dp3 As GENCLIENTWRAPPERLib.datapoint
    tag = "Mitsubishi.MXOPC.6\fx5u.Group001.D3034"
    Set dp3 = client.RequestDataPoint(tag, 1000, 0)
    'While dp3.State <> GC_POINT_OK_UPDATED
    ' Do nothing until point is ready
    'Wend
    'Get tag information
    'dp3.GetValueEtc value, qual, ts, tsms
 
    Dim dp4 As GENCLIENTWRAPPERLib.datapoint
    tag = "Mitsubishi.MXOPC.6\fx5u.Group001.D3068"
    Set dp4 = client.RequestDataPoint(tag, 1000, 0)
    'While dp4.State <> GC_POINT_OK_UPDATED
    ' Do nothing until point is ready
    'Wend
    'Get tag information
    'dp4.GetValueEtc value, qual, ts, tsms
 
    Dim dp5 As GENCLIENTWRAPPERLib.datapoint
    tag = "Mitsubishi.MXOPC.6\fx5u.Group001.D3070"
    Set dp5 = client.RequestDataPoint(tag, 1000, 0)
    'While dp5.State <> GC_POINT_OK_UPDATED
    ' Do nothing until point is ready
    'Wend
    'Get tag information
    'dp5.GetValueEtc value, qual, ts, tsms
 
    Dim dp6 As GENCLIENTWRAPPERLib.datapoint
    tag = "Mitsubishi.MXOPC.6\fx5u.Group001.D3072"
    Set dp6 = client.RequestDataPoint(tag, 1000, 0)
    'While dp6.State <> GC_POINT_OK_UPDATED
    ' Do nothing until point is ready
    'Wend
    'Get tag information
    'dp6.GetValueEtc value, qual, ts, tsms
 
    Dim dp7 As GENCLIENTWRAPPERLib.datapoint
    tag = "Mitsubishi.MXOPC.6\fx5u.Group001.D3106"
    Set dp7 = client.RequestDataPoint(tag, 1000, 0)
    'While dp7.State <> GC_POINT_OK_UPDATED
    ' Do nothing until point is ready
    'Wend
    'Get tag information
    'dp7.GetValueEtc value, qual, ts, tsms
 
    Dim dp8 As GENCLIENTWRAPPERLib.datapoint
    tag = "Mitsubishi.MXOPC.6\fx5u.Group001.D3108"
    Set dp8 = client.RequestDataPoint(tag, 1000, 0)
    'While dp8.State <> GC_POINT_OK_UPDATED
    ' Do nothing until point is ready
    'Wend
    'Get tag information
    'dp8.GetValueEtc value, qual, ts, tsms
 
    Dim dp9 As GENCLIENTWRAPPERLib.datapoint
    tag = "Mitsubishi.MXOPC.6\fx5u.Group001.D3110"
    Set dp9 = client.RequestDataPoint(tag, 1000, 0)
    'While dp9.State <> GC_POINT_OK_UPDATED
    ' Do nothing until point is ready
    'Wend
    'Get tag information
    'dp9.GetValueEtc value, qual, ts, tsms
 
    Dim dp10 As GENCLIENTWRAPPERLib.datapoint
    tag = "Mitsubishi.MXOPC.6\fx5u.Group001.D3144"
    Set dp10 = client.RequestDataPoint(tag, 1000, 0)
    'While dp10.State <> GC_POINT_OK_UPDATED
    ' Do nothing until point is ready
    'Wend
    'Get tag information
    'dp10.GetValueEtc value, qual, ts, tsms
 
    Dim dp11 As GENCLIENTWRAPPERLib.datapoint
    tag = "Mitsubishi.MXOPC.6\fx5u.Group001.D3146"
    Set dp11 = client.RequestDataPoint(tag, 1000, 0)
    'While dp11.State <> GC_POINT_OK_UPDATED
    ' Do nothing until point is ready
    'Wend
    'Get tag information
    'dp11.GetValueEtc value, qual, ts, tsms
 
    Dim dp12 As GENCLIENTWRAPPERLib.datapoint
    tag = "Mitsubishi.MXOPC.6\fx5u.Group001.D3148"
    Set dp12 = client.RequestDataPoint(tag, 1000, 0)
    'While dp12.State <> GC_POINT_OK_UPDATED
    ' Do nothing until point is ready
    'Wend
    'Get tag information
    'dp12.GetValueEtc value, qual, ts, tsms
 
    Dim dp13 As GENCLIENTWRAPPERLib.datapoint
    tag = "Mitsubishi.MXOPC.6\fx5u.Group001.D3182"
    Set dp13 = client.RequestDataPoint(tag, 1000, 0)
    'While dp13.State <> GC_POINT_OK_UPDATED
    ' Do nothing until point is ready
    'Wend
    'Get tag information
    'dp13.GetValueEtc value, qual, ts, tsms
 
    Dim dp14 As GENCLIENTWRAPPERLib.datapoint
    tag = "Mitsubishi.MXOPC.6\fx5u.Group001.D3184"
    Set dp14 = client.RequestDataPoint(tag, 1000, 0)
    'While dp14.State <> GC_POINT_OK_UPDATED
    ' Do nothing until point is ready
    'Wend
    'Get tag information
    'dp14.GetValueEtc value, qual, ts, tsms
 
    Dim dp15 As GENCLIENTWRAPPERLib.datapoint
    tag = "Mitsubishi.MXOPC.6\fx5u.Group001.D3186"
    Set dp15 = client.RequestDataPoint(tag, 1000, 0)
    'While dp15.State <> GC_POINT_OK_UPDATED
    ' Do nothing until point is ready
    'Wend
    'Get tag information
    'dp15.GetValueEtc value, qual, ts, tsms
 
    Dim dp16 As GENCLIENTWRAPPERLib.datapoint
    tag = "Mitsubishi.MXOPC.6\fx5u.Group001.D3220"
    Set dp16 = client.RequestDataPoint(tag, 1000, 0)
    'While dp16.State <> GC_POINT_OK_UPDATED
    ' Do nothing until point is ready
    'Wend
    'Get tag information
    'dp16.GetValueEtc value, qual, ts, tsms
 
    Dim dp17 As GENCLIENTWRAPPERLib.datapoint
    tag = "Mitsubishi.MXOPC.6\fx5u.Group001.D3222"
    Set dp17 = client.RequestDataPoint(tag, 1000, 0)
    'While dp17.State <> GC_POINT_OK_UPDATED
    ' Do nothing until point is ready
    'Wend
    'Get tag information
    'dp17.GetValueEtc value, qual, ts, tsms
 
    Dim dp18 As GENCLIENTWRAPPERLib.datapoint
    tag = "Mitsubishi.MXOPC.6\fx5u.Group001.D3224"
    Set dp18 = client.RequestDataPoint(tag, 1000, 0)
    'While dp18.State <> GC_POINT_OK_UPDATED
    ' Do nothing until point is ready
    'Wend
    'Get tag information
    'dp18.GetValueEtc value, qual, ts, tsms
 
 
    Reading1 = Split(inputFile.ReadLine, ",")
    outputString = Join(Reading1, ",")
    outputFile.WriteLine outputString
         
    BEmfRd1Ch1Rms = CDbl(Reading1(1))
    BEmfRd1Ch2Rms = CDbl(Reading1(2))
    BEmfRd1Ch3Rms = CDbl(Reading1(3))
         
    dp1.SyncWrite BEmfRd1Ch1Rms
    dp2.SyncWrite BEmfRd1Ch2Rms
    dp3.SyncWrite BEmfRd1Ch3Rms

 
    Reading2 = Split(inputFile.ReadLine, ",")
    outputString = Join(Reading2, ",")
    outputFile.WriteLine outputString
         
    BEmfRd2Ch1Rms = CDbl(Reading2(1))
    BEmfRd2Ch2Rms = CDbl(Reading2(2))
    BEmfRd2Ch3Rms = CDbl(Reading2(3))

         
    dp4.SyncWrite BEmfRd2Ch1Rms
    dp5.SyncWrite BEmfRd2Ch2Rms
    dp6.SyncWrite BEmfRd2Ch3Rms

 
    Reading3 = Split(inputFile.ReadLine, ",")
    outputString = Join(Reading3, ",")
    outputFile.WriteLine outputString
         
    BEmfRd3Ch1Rms = CDbl(Reading3(1))
    BEmfRd3Ch2Rms = CDbl(Reading3(2))
    BEmfRd3Ch3Rms = CDbl(Reading3(3))

         
    dp7.SyncWrite BEmfRd3Ch1Rms
    dp8.SyncWrite BEmfRd3Ch2Rms
    dp9.SyncWrite BEmfRd3Ch3Rms

 
    Reading4 = Split(inputFile.ReadLine, ",")
    outputString = Join(Reading4, ",")
    outputFile.WriteLine outputString
         
    BEmfRd4Ch1Rms = CDbl(Reading4(1))
    BEmfRd4Ch2Rms = CDbl(Reading4(2))
    BEmfRd4Ch3Rms = CDbl(Reading4(3))

         
    dp10.SyncWrite BEmfRd4Ch1Rms
    dp11.SyncWrite BEmfRd4Ch2Rms
    dp12.SyncWrite BEmfRd4Ch3Rms

 
    Reading5 = Split(inputFile.ReadLine, ",")
    outputString = Join(Reading5, ",")
    outputFile.WriteLine outputString
         
    BEmfRd5Ch1Rms = CDbl(Reading5(1))
    BEmfRd5Ch2Rms = CDbl(Reading5(2))
    BEmfRd5Ch3Rms = CDbl(Reading5(3))

         
    dp13.SyncWrite BEmfRd5Ch1Rms
    dp14.SyncWrite BEmfRd5Ch2Rms
    dp15.SyncWrite BEmfRd5Ch3Rms

 
    Reading6 = Split(inputFile.ReadLine, ",")
    outputString = Join(Reading6, ",")
    outputFile.WriteLine outputString
         
    BEmfRd6Ch1Rms = CDbl(Reading6(1))
    BEmfRd6Ch2Rms = CDbl(Reading6(2))
    BEmfRd6Ch3Rms = CDbl(Reading6(3))

         
    dp16.SyncWrite BEmfRd6Ch1Rms
    dp17.SyncWrite BEmfRd6Ch2Rms
    dp18.SyncWrite BEmfRd6Ch3Rms


    'does not work as we have no reference for the Bool Data Type
    'Dim dpWrCmpl As GENCLIENTWRAPPERLib.datapoint
    'tag = "Mitsubishi.MXOPC.6\fx5u.Group001.D3246.11"
    'Set dpWrCmpl = client.RequestDataPoint(tag, 1000, 0)
    'dpWrCmpl.SyncWrite 1
    'dpWrCmpl.SyncWrite True
 
    'g.OPC.Write "Mitsubishi.MXOPC.6\fx5u.Group001.D3246.11", True   'doesn't work
 
    Dim dpWrCmpl As GENCLIENTWRAPPERLib.datapoint
    tag = "Mitsubishi.MXOPC.6\fx5u.Group001.D3260"
    Set dpWrCmpl = client.RequestDataPoint(tag, 1000, 0)
    Dim testcompletecode As Double
    testcompletecode = 1973.5
    dpWrCmpl.SyncWrite testcompletecode
 
    outputFile.Close
    inputFile.Close

    Exit Sub
ErrHandler:
    g.ConsoleMsg MSG_SEVERE_ERROR, "Script", "'ReadScopeCsv' failed"
    outputFile.Close
    inputFile.Close
End Sub


----------------------------------------------------------------------------------------------
Script modified to handle missing file. 19-Mar-2018
Script Name : ScriptWorX2010->Projects->ReadScopeCsv->Thread1->ReadScopeCsv
Trigger Name : trg_data:ReadScopeCsv
Trigger Configuration : UDMConfig -> Event Trigger -> Data Trigger -> ReadScopeCsv
                                       Execute Condition : When Data Tag Changes to True
                                       Data Tag : Mitsubishi.MXOPC.6\fx5u.Group001.ReadCsv



Public Sub ReadScopeCsv(td As TriggerData)
    On Error GoTo ErrHandler
    ' TODO: Add your code here
    ' final code
    ' PLC Register to store status of the operation

   
    Dim tag As String
    Dim value As Variant, qual As Variant
    Dim ts As Variant, tsms As Variant
    Set client = CreateObject("GenClientWrapper.Client")
    'tag3 = " ICONICS.Simulator.1\SimulatePLC.OUTPUTS.FLOAT1"
    Dim dpWrCmpl As GENCLIENTWRAPPERLib.datapoint
    tag = "Mitsubishi.MXOPC.6\fx5u.Group001.D3260"
    Set dpWrCmpl = client.RequestDataPoint(tag, 1000, 0)
    Dim testcompletecode As Double
   
    Dim FolderName As String
    FolderName = g.OPC.Read("Mitsubishi.MXOPC.6\fx5u.Group001.D4502")
    Dim FolderName1 As String
    FolderName1 = Trim(FolderName)
   
    'ENSURE THAT FOLDER NAME CORRESPONDING TO WINDING SR NO IS CREATED AND CONTAINS THE FILE MeasLog.csv
    'ENSURE THAT THE SAME WINDING SR NO IS ENTERED IN THE HMI FIELD D4502
   
   
    Dim outputString As String
    Dim outputFile As Scripting.TextStream
    Dim inputFile As Scripting.TextStream
    Const ForWriting = 2
    Const ForReading = 1
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set outputFile = objFSO.CreateTextFile("C:\csv\" + "Logger.csv", ForWriting, True)
    outputFile.WriteLine FolderName + FolderName1
    Set inputFile = objFSO.OpenTextFile("C:\csv\" + FolderName1 + "\MeasLog.csv", ForReading)
   
    outputFile.WriteLine "HELLO"
    Dim temp As String
    temp = inputFile.ReadLine + "HELLO" ' read the 1st line and discard
    outputFile.WriteLine temp


    'Dim temp1() As String
    'temp1 = Split(inputFile.ReadLine, ",")
    'outputString = Join(temp1, ",")
    'outputFile.WriteLine outputString

    Dim Reading1() As String
    Dim BEmfRd1Ch1Rms As Double, BEmfRd1Ch2Rms As Double, BEmfRd1Ch3Rms As Double
    Dim Reading2() As String
    Dim BEmfRd2Ch1Rms As Double, BEmfRd2Ch2Rms As Double, BEmfRd2Ch3Rms As Double
    Dim Reading3() As String
    Dim BEmfRd3Ch1Rms As Double, BEmfRd3Ch2Rms As Double, BEmfRd3Ch3Rms As Double
    Dim Reading4() As String
    Dim BEmfRd4Ch1Rms As Double, BEmfRd4Ch2Rms As Double, BEmfRd4Ch3Rms As Double
    Dim Reading5() As String
    Dim BEmfRd5Ch1Rms As Double, BEmfRd5Ch2Rms As Double, BEmfRd5Ch3Rms As Double
    Dim Reading6() As String
    Dim BEmfRd6Ch1Rms As Double, BEmfRd6Ch2Rms As Double, BEmfRd6Ch3Rms As Double
   


    Dim dp1 As GENCLIENTWRAPPERLib.datapoint
    tag = "Mitsubishi.MXOPC.6\fx5u.Group001.D3030"
    Set dp1 = client.RequestDataPoint(tag, 1000, 0)
    'While dp1.State <> GC_POINT_OK_UPDATED
    ' Do nothing until point is ready
    'Wend
    'Get tag information
    'dp1.GetValueEtc value, qual, ts, tsms
   
 
    Dim dp2 As GENCLIENTWRAPPERLib.datapoint
    tag = "Mitsubishi.MXOPC.6\fx5u.Group001.D3032"
    Set dp2 = client.RequestDataPoint(tag, 1000, 0)
    'While dp2.State <> GC_POINT_OK_UPDATED
    ' Do nothing until point is ready
    'Wend
    'Get tag information
    'dp2.GetValueEtc value, qual, ts, tsms

    Dim dp3 As GENCLIENTWRAPPERLib.datapoint
    tag = "Mitsubishi.MXOPC.6\fx5u.Group001.D3034"
    Set dp3 = client.RequestDataPoint(tag, 1000, 0)
    'While dp3.State <> GC_POINT_OK_UPDATED
    ' Do nothing until point is ready
    'Wend
    'Get tag information
    'dp3.GetValueEtc value, qual, ts, tsms
   
    Dim dp4 As GENCLIENTWRAPPERLib.datapoint
    tag = "Mitsubishi.MXOPC.6\fx5u.Group001.D3068"
    Set dp4 = client.RequestDataPoint(tag, 1000, 0)
    'While dp4.State <> GC_POINT_OK_UPDATED
    ' Do nothing until point is ready
    'Wend
    'Get tag information
    'dp4.GetValueEtc value, qual, ts, tsms
   
    Dim dp5 As GENCLIENTWRAPPERLib.datapoint
    tag = "Mitsubishi.MXOPC.6\fx5u.Group001.D3070"
    Set dp5 = client.RequestDataPoint(tag, 1000, 0)
    'While dp5.State <> GC_POINT_OK_UPDATED
    ' Do nothing until point is ready
    'Wend
    'Get tag information
    'dp5.GetValueEtc value, qual, ts, tsms
   
    Dim dp6 As GENCLIENTWRAPPERLib.datapoint
    tag = "Mitsubishi.MXOPC.6\fx5u.Group001.D3072"
    Set dp6 = client.RequestDataPoint(tag, 1000, 0)
    'While dp6.State <> GC_POINT_OK_UPDATED
    ' Do nothing until point is ready
    'Wend
    'Get tag information
    'dp6.GetValueEtc value, qual, ts, tsms
   
    Dim dp7 As GENCLIENTWRAPPERLib.datapoint
    tag = "Mitsubishi.MXOPC.6\fx5u.Group001.D3106"
    Set dp7 = client.RequestDataPoint(tag, 1000, 0)
    'While dp7.State <> GC_POINT_OK_UPDATED
    ' Do nothing until point is ready
    'Wend
    'Get tag information
    'dp7.GetValueEtc value, qual, ts, tsms
   
    Dim dp8 As GENCLIENTWRAPPERLib.datapoint
    tag = "Mitsubishi.MXOPC.6\fx5u.Group001.D3108"
    Set dp8 = client.RequestDataPoint(tag, 1000, 0)
    'While dp8.State <> GC_POINT_OK_UPDATED
    ' Do nothing until point is ready
    'Wend
    'Get tag information
    'dp8.GetValueEtc value, qual, ts, tsms
   
    Dim dp9 As GENCLIENTWRAPPERLib.datapoint
    tag = "Mitsubishi.MXOPC.6\fx5u.Group001.D3110"
    Set dp9 = client.RequestDataPoint(tag, 1000, 0)
    'While dp9.State <> GC_POINT_OK_UPDATED
    ' Do nothing until point is ready
    'Wend
    'Get tag information
    'dp9.GetValueEtc value, qual, ts, tsms
   
    Dim dp10 As GENCLIENTWRAPPERLib.datapoint
    tag = "Mitsubishi.MXOPC.6\fx5u.Group001.D3144"
    Set dp10 = client.RequestDataPoint(tag, 1000, 0)
    'While dp10.State <> GC_POINT_OK_UPDATED
    ' Do nothing until point is ready
    'Wend
    'Get tag information
    'dp10.GetValueEtc value, qual, ts, tsms
   
    Dim dp11 As GENCLIENTWRAPPERLib.datapoint
    tag = "Mitsubishi.MXOPC.6\fx5u.Group001.D3146"
    Set dp11 = client.RequestDataPoint(tag, 1000, 0)
    'While dp11.State <> GC_POINT_OK_UPDATED
    ' Do nothing until point is ready
    'Wend
    'Get tag information
    'dp11.GetValueEtc value, qual, ts, tsms
   
    Dim dp12 As GENCLIENTWRAPPERLib.datapoint
    tag = "Mitsubishi.MXOPC.6\fx5u.Group001.D3148"
    Set dp12 = client.RequestDataPoint(tag, 1000, 0)
    'While dp12.State <> GC_POINT_OK_UPDATED
    ' Do nothing until point is ready
    'Wend
    'Get tag information
    'dp12.GetValueEtc value, qual, ts, tsms
   
    Dim dp13 As GENCLIENTWRAPPERLib.datapoint
    tag = "Mitsubishi.MXOPC.6\fx5u.Group001.D3182"
    Set dp13 = client.RequestDataPoint(tag, 1000, 0)
    'While dp13.State <> GC_POINT_OK_UPDATED
    ' Do nothing until point is ready
    'Wend
    'Get tag information
    'dp13.GetValueEtc value, qual, ts, tsms
   
    Dim dp14 As GENCLIENTWRAPPERLib.datapoint
    tag = "Mitsubishi.MXOPC.6\fx5u.Group001.D3184"
    Set dp14 = client.RequestDataPoint(tag, 1000, 0)
    'While dp14.State <> GC_POINT_OK_UPDATED
    ' Do nothing until point is ready
    'Wend
    'Get tag information
    'dp14.GetValueEtc value, qual, ts, tsms
   
    Dim dp15 As GENCLIENTWRAPPERLib.datapoint
    tag = "Mitsubishi.MXOPC.6\fx5u.Group001.D3186"
    Set dp15 = client.RequestDataPoint(tag, 1000, 0)
    'While dp15.State <> GC_POINT_OK_UPDATED
    ' Do nothing until point is ready
    'Wend
    'Get tag information
    'dp15.GetValueEtc value, qual, ts, tsms
   
    Dim dp16 As GENCLIENTWRAPPERLib.datapoint
    tag = "Mitsubishi.MXOPC.6\fx5u.Group001.D3220"
    Set dp16 = client.RequestDataPoint(tag, 1000, 0)
    'While dp16.State <> GC_POINT_OK_UPDATED
    ' Do nothing until point is ready
    'Wend
    'Get tag information
    'dp16.GetValueEtc value, qual, ts, tsms
   
    Dim dp17 As GENCLIENTWRAPPERLib.datapoint
    tag = "Mitsubishi.MXOPC.6\fx5u.Group001.D3222"
    Set dp17 = client.RequestDataPoint(tag, 1000, 0)
    'While dp17.State <> GC_POINT_OK_UPDATED
    ' Do nothing until point is ready
    'Wend
    'Get tag information
    'dp17.GetValueEtc value, qual, ts, tsms
   
    Dim dp18 As GENCLIENTWRAPPERLib.datapoint
    tag = "Mitsubishi.MXOPC.6\fx5u.Group001.D3224"
    Set dp18 = client.RequestDataPoint(tag, 1000, 0)
    'While dp18.State <> GC_POINT_OK_UPDATED
    ' Do nothing until point is ready
    'Wend
    'Get tag information
    'dp18.GetValueEtc value, qual, ts, tsms
   
   
    Reading1 = Split(inputFile.ReadLine, ",")
    outputString = Join(Reading1, ",")
    outputFile.WriteLine outputString
           
    BEmfRd1Ch1Rms = CDbl(Reading1(1))
    BEmfRd1Ch2Rms = CDbl(Reading1(2))
    BEmfRd1Ch3Rms = CDbl(Reading1(3))
         
    dp1.SyncWrite BEmfRd1Ch1Rms
    dp2.SyncWrite BEmfRd1Ch2Rms
    dp3.SyncWrite BEmfRd1Ch3Rms

   
    Reading2 = Split(inputFile.ReadLine, ",")
    outputString = Join(Reading2, ",")
    outputFile.WriteLine outputString
           
    BEmfRd2Ch1Rms = CDbl(Reading2(1))
    BEmfRd2Ch2Rms = CDbl(Reading2(2))
    BEmfRd2Ch3Rms = CDbl(Reading2(3))

         
    dp4.SyncWrite BEmfRd2Ch1Rms
    dp5.SyncWrite BEmfRd2Ch2Rms
    dp6.SyncWrite BEmfRd2Ch3Rms

   
    Reading3 = Split(inputFile.ReadLine, ",")
    outputString = Join(Reading3, ",")
    outputFile.WriteLine outputString
           
    BEmfRd3Ch1Rms = CDbl(Reading3(1))
    BEmfRd3Ch2Rms = CDbl(Reading3(2))
    BEmfRd3Ch3Rms = CDbl(Reading3(3))

         
    dp7.SyncWrite BEmfRd3Ch1Rms
    dp8.SyncWrite BEmfRd3Ch2Rms
    dp9.SyncWrite BEmfRd3Ch3Rms

   
    Reading4 = Split(inputFile.ReadLine, ",")
    outputString = Join(Reading4, ",")
    outputFile.WriteLine outputString
           
    BEmfRd4Ch1Rms = CDbl(Reading4(1))
    BEmfRd4Ch2Rms = CDbl(Reading4(2))
    BEmfRd4Ch3Rms = CDbl(Reading4(3))

         
    dp10.SyncWrite BEmfRd4Ch1Rms
    dp11.SyncWrite BEmfRd4Ch2Rms
    dp12.SyncWrite BEmfRd4Ch3Rms

   
    Reading5 = Split(inputFile.ReadLine, ",")
    outputString = Join(Reading5, ",")
    outputFile.WriteLine outputString
           
    BEmfRd5Ch1Rms = CDbl(Reading5(1))
    BEmfRd5Ch2Rms = CDbl(Reading5(2))
    BEmfRd5Ch3Rms = CDbl(Reading5(3))

         
    dp13.SyncWrite BEmfRd5Ch1Rms
    dp14.SyncWrite BEmfRd5Ch2Rms
    dp15.SyncWrite BEmfRd5Ch3Rms

   
    Reading6 = Split(inputFile.ReadLine, ",")
    outputString = Join(Reading6, ",")
    outputFile.WriteLine outputString
           
    BEmfRd6Ch1Rms = CDbl(Reading6(1))
    BEmfRd6Ch2Rms = CDbl(Reading6(2))
    BEmfRd6Ch3Rms = CDbl(Reading6(3))

         
    dp16.SyncWrite BEmfRd6Ch1Rms
    dp17.SyncWrite BEmfRd6Ch2Rms
    dp18.SyncWrite BEmfRd6Ch3Rms


    'does not work as we have no reference for the Bool Data Type
    'Dim dpWrCmpl As GENCLIENTWRAPPERLib.datapoint
    'tag = "Mitsubishi.MXOPC.6\fx5u.Group001.D3246.11"
    'Set dpWrCmpl = client.RequestDataPoint(tag, 1000, 0)
    'dpWrCmpl.SyncWrite 1
    'dpWrCmpl.SyncWrite True
   
    'g.OPC.Write "Mitsubishi.MXOPC.6\fx5u.Group001.D3246.11", True   'doesn't work


    testcompletecode = 1973.5
    dpWrCmpl.SyncWrite testcompletecode
   
    outputFile.Close
    inputFile.Close

    Exit Sub
ErrHandler:
    'g.ConsoleMsg MSG_SEVERE_ERROR, "Script", "'ReadScopeCsv' failed"
    testcompletecode = 2073.5
    dpWrCmpl.SyncWrite testcompletecode
    outputFile.Close
    inputFile.Close
End Sub

Comments

Popular posts from this blog

GXWorks3 GXDeveloper3 Notes

Set Device comment using Navigation Tree View -> Device-> Common Device Comment Q1. Blinking erratic display of values when choosing Controller Type : FX A1. Communication issue between the GS2110 HMI and the FX5U PLC over ethernet was resolved by the following settings : System Tree View -> Controller Setting ->CH1-> Controller Type : Melsec iQ-F , I/F : Ethernet Multi Unit type : FX5CPU, IP Address : 192.168.1.17, Port : 5562, Communication TCP Q2. When communication between the FX5U PLC and the GS2110 HMI was established the GXWorks3 Programming software was unable to go online with the PLC - gives communication error A2. The PLC connection set to "Direct" and not "Via Hub" Q3  Unable to establish simultaneous communication to FX5U PLC with SCADA (MX OPC Server ) and HMI ( GS2110 ) Need to add Melsoft  device to correspond to the HMI as shown below Q4. Functions and Function Blocks Functions :  1. Do not get i...

FX5U PLC Module Settings

FX5U-4AD-PT-ADP FX5U-8AD