'
' File System Object Demo
'
Option Explicit
'
' File Open constants
'
Const fsoError = -1
Const fsoOpenRead = 0
Const fsoOpenWrite = 1
Const fsoOpenReadWrite = 2
'
' File Seek Constants
'
Const fsoSEEK_SET = 0
Const fsoSEEK_CUR = 1
Const fsoSEEK_END = 2
Sub Main()
Dim
InFile
Dim
FileSize
Dim
ThisByte
Dim
TmpStr
Dim
Outfile
Dim
FileName
Dim
Cnt
'
'
Open File
'
Const FileFilter = "All Eprom Files (*.bin, *.crd)|*.bin;*.crd;|Bin
Files (*.bin)|*.bin|Crd Files (*.crd)|*.crd"
FileName = Fs.FileOpenDialog(FileFilter, "Please select a valid bin
file", "Penta3.bin")
If
FileName <> "" Then
'
'
Check if the file exists
'
If Fs.FileExists(FileName) = 0 Then
Sc.MsgBox("The file does not exist")
Else
InFile = Fs.FileOpen(FileName, fsoOpenRead)
End If
End
if
'
'
Seek to end of file to get size
'
FileSize = Fs.FileSeek(InFile, 0, fsoSEEK_END)
Sc.Print "The file size is " & FileSize & vbCr &
vbCr
For Cnt
= 0 to FileSize/86 - 1
Sc.Reset()
call
Fs.FileSeek(InFile, Cnt*86, fsoSEEK_SET)
TmpStr = ""
Wcmd()
For
ThisByte = 0 to 85
TmpStr = TmpStr & HexString(Fs.FileGetc(InFile), 2) & "
"
Next
Sc.Write(TmpStr)
Sc.Delay(400)
Sc.Read(2)
Next
call
Fs.FileSeek(InFile, 0, fsoSEEK_SET)
Fs.FileClose(InFile)
End Sub
'================================================================
Function HexString(ThisNumber, Length)
Dim
RetVal
Dim
CurLen
'
'
Convert a integer to a hex string and
'
pad it with the desired number of zeros
'
RetVal = Hex(ThisNumber)
CurLen = Len(RetVal)
If
CurLen < Length Then
RetVal = String(Length - CurLen, "0") & RetVal
End
If
HexString = RetVal
End Function
'================================================================
Function Wcmd()
Sc.Write("C3 77 00 00 56")
Wcmd
= Sc.Read(1)
End Function