VB Smart Devivce Programming

  • Thread starter Thread starter Martin
  • Start date Start date
M

Martin

Hi all,

I just started a project in VB2005 for Smart Devices. For this I need to
read a text file. Does anyone have a code snippet of how this is done? I
mapped a directory to emulate the storage card and copied the file in there.
In the file manager of the device emulator I can see the file there. But I
have no idea how to access the file (directory name, etc.)

Hope anyone can help
Regards,
Martin
 
Hi,

Here is a code snip. It uses the OpenFileDialog control. Note, I am using
it to read data in "chunks" from a file and then to send those "chunks" out
the serial port. However, you can do equivalent things (such as simply
displaying the file), rather than sending it.

OpenFileDialog1.ShowDialog()

Dim Filename As String = OpenFileDialog1.FileName

If Filename <> "" Then

Dim fs As New System.IO.FileStream(Filename, IO.FileMode.Open,
IO.FileAccess.Read)

'declaring a FileStream to open the file with access mode of reading

logReader = New System.IO.BinaryReader(fs)

'creating a new StreamReader and passing the filestream object fs as
argument

logReader.BaseStream.Seek(0, IO.SeekOrigin.Begin)

Dim FileLength = logReader.BaseStream.Length

Dim BytesRemaining As Integer = FileLength

With SerialPort

Do Until BytesRemaining < SerialPort.WriteBufferSize

Try

Dim buffer(.WriteBufferSize - 1) As Byte

buffer = logReader.ReadBytes(.WriteBufferSize)

..Write(buffer, 0, .WriteBufferSize)

BytesRemaining -= .WriteBufferSize

Catch ex As Exception

Exit Do

End Try

Loop

'etc

For this reason, I use a BinaryReader. You might choose to use a TextReader
instead. If you examine the Filename result from the OpenFileDialog, you
can see how paths are handled for Storage Cards.

Dick
--
Richard Grier, MVP
Hard & Software
Author of Visual Basic Programmer's Guide to Serial Communications, Fourth
Edition,
ISBN 1-890422-28-2 (391 pages, includes CD-ROM). July 2004, Revised March
2006.
See www.hardandsoftware.net for details and contact information.
 
Back
Top