Skip to main content

ReadScopeCsv




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



Public Sub ReadScopeCsv(td As TriggerData)
    On Error GoTo ErrHandler
    ' TODO: Add your code here
    ' final code
    
    'create the logging file
    Dim TimeStamp1 As String
    TimeStamp1 = Format(Now(), "_ddmmyyyyhhnnss")
    
    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("E:\csv\LogBEMF" + TimeStamp1 + ".csv", ForWriting, True)
    
    ' 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.BEMF.D3260"
    Set dpWrCmpl = client.RequestDataPoint(tag, 1000, 0)
    Dim testcompletecode As Double
    
    Dim FolderName As String
    FolderName = g.OPC.Read("Mitsubishi.MXOPC.6\fx5u.MotSet.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
    
    
    outputFile.WriteLine FolderName1
    Set inputFile = objFSO.OpenTextFile("E:\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 dp1 As GENCLIENTWRAPPERLib.datapoint
    tag = "Mitsubishi.MXOPC.6\fx5u.BEMF.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.BEMF.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.BEMF.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.BEMF.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.BEMF.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.BEMF.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.BEMF.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.BEMF.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.BEMF.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.BEMF.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.BEMF.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.BEMF.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.BEMF.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.BEMF.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.BEMF.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.BEMF.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.BEMF.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.BEMF.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.BEMF.D3246.11"
    'Set dpWrCmpl = client.RequestDataPoint(tag, 1000, 0)
    'dpWrCmpl.SyncWrite 1
    'dpWrCmpl.SyncWrite True
    
    'g.OPC.Write "Mitsubishi.MXOPC.6\fx5u.BEMF.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.Write "Error Encountered"
    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

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 "App...