Importing and sending messages from CSV

Comprehensive CAN monitor for Windows® and its add-ins: Plotter, CANdb Import, Instruments Panel, and J1939
Post Reply
agcomptec
Posts: 1
Joined: Fri 28. Sep 2012, 18:29

Importing and sending messages from CSV

Post by agcomptec » Fri 28. Sep 2012, 18:32

Hi, I have some recorded messages stored in a CSV file. I would like to use VBScript to import, parse, and send these messages. I'm basically looking for a method to import a line of text from a text file using VBScript in the Explorer-5 environment. The rest I can do. Thanks.

User avatar
PEAK-Support
Sales & Support
Sales & Support
Posts: 1646
Joined: Fri 10. Sep 2010, 19:34

Re: Importing and sending messages from CSV

Post by PEAK-Support » Fri 28. Sep 2012, 19:50

Opening Files, read lines etc. is raw VBS and have nothing to do with the PE5 Extensions.
Here is a simple Maro that load a Text File Line by Line and write the Data of each line to the transmit List. (PE4 Macro - but easy to port to PE5)

Code: Select all

' Dieser Makro laedt CAN-Botschaften aus einer Textdatei in die Sendeliste,
' wobei in der Textdatei die Botschaften in folgender Form gespeichert sind:
' CAN-ID(Hex,3 Zeichen) DLC Daten(Hex), Z.B. 100 5 1A 5F C4 3B FF

Sub LadeNachrichten()
  Const ForReading = 1
  Dim fso
  Set fso = CreateObject("Scripting.FileSystemObject")
  Dim FileName
  FileName = "C:\Temp\Test.log"
  
  ' Abfrage des Dateinamens
  FileName = InputBox("Dateiname:",, FileName)
  If Not fso.FileExists(FileName) Then
	MsgBox "Datei existiert nicht!"
	Exit Sub
  End If
  
  ' Datei oeffnen  
  Dim tf
  Set tf = fso.OpenTextFile(FileName, ForReading)
  
  ' Alle Zeilen der Datei lesen
  Dim Line, Msg, n
  While Not tf.AtEndOfStream
	Set Msg = TransmitMessages.Add
	Msg.ID = CInt("&H" & tf.Read(3))  ' 3 Zeichen CAN-ID in Hex
	tf.Skip(1)
	Msg.DLC = CInt(tf.Read(1))  ' 1 Zeichen DLC
	tf.Skip(1)
	For n = 0 To Msg.DLC-1
	  Msg.Data(n) = CInt("&H" & tf.Read(2))  ' Jeweils 2 Zeichen Hex-Daten
	  tf.Skip(1)
	Next
	tf.ReadLine  ' Gehe zur nõchsten Zeile
  Wend
  
  tf.Close  ' Datei schliessen
End Sub
--------------------------------
PEAK-System Technik
Technical Support Team
support[at]peak-system.com
-------------------------------

Post Reply