Announcement

Collapse
No announcement yet.

how to read a csv file

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    how to read a csv file

    SOLVED!!


    Does anyone know how to let homeseer read a csv file from C:/ ?

    regards
    Last edited by Malosa; August 31, 2016, 11:11 AM. Reason: SOlved
    Preferred -> Jon's Plugins, Pushover, Phlocation, Easy-trigger,
    Rfxcom, Blade Plugins, Pushbullet, homekit, Malosa Scripts




    HS3Pro 4.1.14.0 on windows 10 enterprise X64 on hp quadcore laptop 8 GB.

    #2
    There are quite a few examples of this here if you search, there are also plenty of options available for .net reading a CSV file (you have the option to read as data or if it is a very simple file you can just split a single line on the comma).

    Comment


      #3
      Hi Adam

      thanks , i found one

      but i need your help , i build one and it works , but here is the thing.
      When i get a new value in the csv file i want that it shows only the new value not the past value , how to do that ?
      because when it updates it shows ony the first entry and also change the (lastchange) so it multi trigger an event...

      ( i use a ini file to configure from thats why i put this here Dim FileName As string = path )

      its for my anpr

      this is the csv , but the last entry i don;t need , but it works like this

      Code:
      23/08/2017,02:44,"PT-FK-41","PT-FK-41.jpg"


      Code:
      Dim str As String
      		Dim FileName As string = path
      		Dim SplitStr() As String
      		
      		
      		str = My.Computer.FileSystem.ReadAllText(FileName)
      		
      		
      		SplitStr = Split(str, ",")
      		hs.writelog("0", SplitStr(0)) 'Date
      		Ref = hs.GetDeviceRef("ANPR-Date")
              hs.SetDeviceString(ref, SplitStr(0), True) 
      		
      		hs.writelog("1", SplitStr(1)) 'Time
      		Ref = hs.GetDeviceRef("ANPR-Time")
              hs.SetDeviceString(ref, SplitStr(1), True)
      		
      		hs.writelog("2", SplitStr(2)) 'Plates
      		Ref = hs.GetDeviceRef("ANPR-Plates")
              hs.SetDeviceString(ref, SplitStr(2), True)


      Originally posted by mrhappy View Post
      There are quite a few examples of this here if you search, there are also plenty of options available for .net reading a CSV file (you have the option to read as data or if it is a very simple file you can just split a single line on the comma).
      Preferred -> Jon's Plugins, Pushover, Phlocation, Easy-trigger,
      Rfxcom, Blade Plugins, Pushbullet, homekit, Malosa Scripts




      HS3Pro 4.1.14.0 on windows 10 enterprise X64 on hp quadcore laptop 8 GB.

      Comment


        #4
        Either test whether the string is different in a nested if...then loop or try something like this (not sure if it will work);

        hs.SetDeviceString(ref, SplitStr(2), IIf(hs.devicestring(ref) = SplitStr(2), False, True))

        Comment


          #5
          Hi Adam , thanks for the reply

          with that string nothing changes ,

          Here is the code again then without everythig added, i just keep it simple.

          Code:
                Sub Main(ByVal Parms As Object) 
          	        Dim str As String
          		Dim FileName As string = path
          		Dim SplitStr() As String
          		
          		
          		str = My.Computer.FileSystem.ReadAllText ("C:/test.csv")
          		
          		
          		SplitStr = Split(str, ",")
          		hs.writelog("0", SplitStr(0)) 'Date
          		hs.writelog("1", SplitStr(1)) 'Time
          		hs.writelog("2", SplitStr(2)) 'Plates
          		End Sub
          Output in log is this
          Code:
          Aug-28 13:38:06	 	2	"PT-FK-41"
          Aug-28 13:38:06	 	1	20:44
          Aug-28 13:38:06	 	0	23/08/2016
          Inifile is this

          Code:
          23/08/2016,20:44,"PT-FK-41","PT-FK-41.jpg"
          23/08/2017,02:44,"PT-FK-41","PT-FK-42.jpg"
          The second row is the last entry , i just want it to read te last new row.

          regards




          Originally posted by mrhappy View Post
          Either test whether the string is different in a nested if...then loop or try something like this (not sure if it will work);

          hs.SetDeviceString(ref, SplitStr(2), IIf(hs.devicestring(ref) = SplitStr(2), False, True))
          Preferred -> Jon's Plugins, Pushover, Phlocation, Easy-trigger,
          Rfxcom, Blade Plugins, Pushbullet, homekit, Malosa Scripts




          HS3Pro 4.1.14.0 on windows 10 enterprise X64 on hp quadcore laptop 8 GB.

          Comment


            #6
            There may be better ways of doing this but I have in the past split on the new line (Chr(0) I think), then for each new line I would then split each line on the comma. Depending on the amount of data depends on whether or not this is a great method because as I say there are options in .net to read this in as data and instead query it like you would a database.

            Comment


              #7
              hi Adam

              i made this one but ,it shows the first line , then the second line
              what do i need to change that it only shows the last line of the file , because if i expand this script and let it write to a virtual device , t will constantly change till he reached the end of the file..

              this script is in .VB it was in .txt i converted it.


              Code:
              Sub Main(ByVal Parms As Object)
              Dim fso, file, filename, data, r, cmd, path, arrSplitData
                
              Path = "C:\test.csv"
              fso = CreateObject("Scripting.FileSystemObject")
              file = fso.OpenTextFile(Path, 1, True)
              do while file.AtEndOfStream <> True
              r = file.ReadLine
              arrSplitData = split(r,",")
              
              hs.writelog("0", arrSplitData(0))
              hs.writelog("0", arrSplitData(1))
              hs.writelog("0", arrSplitData(2))
              Loop
              file.Close
              end sub



              Originally posted by mrhappy View Post
              There may be better ways of doing this but I have in the past split on the new line (Chr(0) I think), then for each new line I would then split each line on the comma. Depending on the amount of data depends on whether or not this is a great method because as I say there are options in .net to read this in as data and instead query it like you would a database.
              Preferred -> Jon's Plugins, Pushover, Phlocation, Easy-trigger,
              Rfxcom, Blade Plugins, Pushbullet, homekit, Malosa Scripts




              HS3Pro 4.1.14.0 on windows 10 enterprise X64 on hp quadcore laptop 8 GB.

              Comment


                #8
                i got it ,

                this must be under file.close and it works

                Code:
                hs.writelog("0", arrSplitData(0))
                hs.writelog("0", arrSplitData(1))
                hs.writelog("0", arrSplitData(2))
                but there is one problem left , if the last entry doesnt change how can i let it not change the last change at the device? when the script has run
                Last edited by Malosa; August 29, 2016, 12:56 AM.
                Preferred -> Jon's Plugins, Pushover, Phlocation, Easy-trigger,
                Rfxcom, Blade Plugins, Pushbullet, homekit, Malosa Scripts




                HS3Pro 4.1.14.0 on windows 10 enterprise X64 on hp quadcore laptop 8 GB.

                Comment

                Working...
                X