Hello, I was wondering if I could get a bit of help. I don't do much programming and I think that's why I'm having problems. My goal is this:
I need to monitor a PLC, when a data change is detected I need to read 5 values from the PLC and the write them to a CSV file. I need to append the time, and the ST20:19, ST20:0 values to the file each minute and when a value changes. When the run is completed, the file will be closed and it should wait for the next run.
The way I have it now, a new file is created every minute, and the PLC seems to be being polled each second.
Here is my code:
Private Sub DataSubscriber2_DataChanged(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles DataSubscriber2.DataChanged
Dim strFilename As String = Format(Now, "yyyyMMddhhmm") & ".csv"
Dim strDateStamp As String = Format(Now, "MM/dd/yyyy")
Dim strTimeStamp As String = Format(Now, "hh:mm tt")
Dim path As String = String.Concat("C:\temp\", strFilename)
Dim w As New IO.StreamWriter(path, True)
w.Write(strDateStamp)
w.Write(",")
If e.PlcAddress = "ST20:1" Then
w.Write(e.Values(0))
w.Write(",")
End If
If e.PlcAddress = "ST20:2" Then
w.Write(e.Values(0))
w.Write(",")
End If
If e.PlcAddress = "ST20:18" Then
w.Write(e.Values(0))
w.Write(",")
End If
If Timer1.Interval = 60000 Then
If e.PlcAddress = "ST20:19" Then
w.Write(e.Values(0))
w.Write(",")
Else
w.Write(" ")
End If
If e.PlcAddress = "ST20:0" Then
w.Write(strTimeStamp & ",")
w.Write(e.Values(0))
End If
w.WriteLine(vbNewLine)
End If
w.Close()
End Sub
Here is an example of the output (First CSV file):
04/01/2016, 03:09 PM,00:00:00 104.7C 0.2PSI
04/01/2016,CYCLE NAME: LIQUIDS 2,
04/01/2016,CYCLE TEMP: 121.0C,
04/01/2016,CYCLE TIME: 12 MIN,
04/01/2016,CYCLE ABORTED,
followed by (next CSV file):
04/01/2016, 03:10 PM,00:00:00 71.2C 0.6PSI
04/01/2016, ,
04/01/2016, 03:10 PM,00:00:00 71.4C 0.6PSI
04/01/2016, 03:10 PM,00:00:00 71.7C 0.6PSI
04/01/2016,CONDITIONING,
04/01/2016, 03:10 PM,00:00:00 71.9C 2.1PSI
04/01/2016, 03:10 PM,00:00:00 73.4C 4.5PSI
04/01/2016, 03:10 PM,00:00:00 79.7C 4.8PSI
04/01/2016, 03:10 PM,00:00:00 88.2C 4.8PSI
04/01/2016, 03:10 PM,00:00:00 93.8C 4.7PSI
04/01/2016, 03:10 PM,00:00:00 97.2C 4.6PSI
04/01/2016, 03:10 PM,00:00:00 99.5C 4.5PSI
04/01/2016, 03:10 PM,00:00:00 101.0C 4.2PSI
04/01/2016, 03:10 PM,00:00:00 101.9C 4.2PSI
04/01/2016, 03:10 PM,00:00:00 102.7C 4.1PSI
04/01/2016, 03:10 PM,00:00:00 103.3C 4.2PSI
04/01/2016, 03:10 PM,00:00:00 103.8C 4.2PSI
04/01/2016, 03:10 PM,00:00:00 104.2C 4.2PSI
04/01/2016, 03:10 PM,00:00:00 104.4C 4.1PSI
04/01/2016, 03:10 PM,00:00:00 104.6C 4.1PSI
I really only want the date, ST20:1, ST20:2 and ST2018: on the head of the first pass and to loop through ST:2019 and ST20:0, in one CSV file.
Then close and get ready for the next run.
Thank You,
Alan