OpenNetCF (Desktop Communications.RAPI) question

  • Thread starter Thread starter Dave Corun
  • Start date Start date
D

Dave Corun

First off, you guys absolutely RULE for creating this set of libraries for
the rest of us to use!

My question is in regards to CopyFileFromDevice()

I'm basically copying the log.xml file from the device over to my desktop.

i.CopyFileFromDevice("\program files\sd_dispatch\Log.xml", "C:\log.xml",
True)

All I ever get is "Cannot Access Remote File"

The log file exists on the device, but it never gets moved over.

I tried creating an empty file there, but same error when it gets to
CopyFileFromDevice().

dim strFile as string = "C:\log.xml"
Dim f As System.IO.File
If f.Exists(strFile) = True Then f.Delete(strFile)
Dim sr As System.IO.StreamWriter = f.CreateText(strFile)
sr.Close()
f = Nothing
sr = Nothing

I do have another question as well, how would I tell if a file exists on the
device? Can I just use system.io.file to hit the device? I want to make
sure I handle any errors relating to the missing files on the device
correctly. This log file is one of 3 files that need to get transferred via
RAPI.

Thanks!!!

// Dave

(I didn't mean to make it a response to that Sai's post, but it's showing up
that way for me! Sorry for the double-post!)
 
Nope, "remote" always means "not on the host where the code is running".
With RAPI that will always be the device.

--
Chris Tacke, eMVP
Advisory Board Member
www.OpenNETCF.org
---
Windows CE Product Manager
Applied Data Systems
www.applieddata.net


Dave Corun said:
Oh, hah, when I think of remote, I think "desktop" b/c the function does the
oposite of the other.

Thanks! I'll play w/ it now!

// Dave



If you look at the documentation, you've got your parameters reversed:

http://www.opennetcf.org/docs/Commu...p.Communication.RAPI.CopyFileFromDevice1.html

[Visual Basic]Overloads Public Sub CopyFileFromDevice( _ ByVal
LocalFileName As String, _ ByVal RemoteFileName As String _)
--
Chris Tacke, eMVP
Advisory Board Member
www.OpenNETCF.org
---
Windows CE Product Manager
Applied Data Systems
www.applieddata.net


Dave Corun said:
First off, you guys absolutely RULE for creating this set of libraries for
the rest of us to use!

My question is in regards to CopyFileFromDevice()

I'm basically copying the log.xml file from the device over to my desktop.

i.CopyFileFromDevice("\program files\sd_dispatch\Log.xml", "C:\log.xml",
True)

All I ever get is "Cannot Access Remote File"

The log file exists on the device, but it never gets moved over.

I tried creating an empty file there, but same error when it gets to
CopyFileFromDevice().

dim strFile as string = "C:\log.xml"
Dim f As System.IO.File
If f.Exists(strFile) = True Then f.Delete(strFile)
Dim sr As System.IO.StreamWriter = f.CreateText(strFile)
sr.Close()
f = Nothing
sr = Nothing

I do have another question as well, how would I tell if a file exists on the
device? Can I just use system.io.file to hit the device? I want to make
sure I handle any errors relating to the missing files on the device
correctly. This log file is one of 3 files that need to get transferred via
RAPI.

Thanks!!!

// Dave

(I didn't mean to make it a response to that Sai's post, but it's
showing
up
that way for me! Sorry for the double-post!)
 
It was an early bug that I thought was fixed in 1.1 or 1.2.

--
Chris Tacke, eMVP
Advisory Board Member
www.OpenNETCF.org
---
Windows CE Product Manager
Applied Data Systems
www.applieddata.net


Dave Corun said:
I got past that issue, but now I'm having the problem where
CopyFileToDevice() only copies 4k of the file.

I read this post on the forums:
http://www.opennetcf.org/forums/topic.asp?TOPIC_ID=122


The release I have from the web site has the problems stated in this topic.
Is there another release planned, or am I missing something? The file I'm
trying to copy to the device is 157k right now, but I'll probably go up to
around 170k.

Thanks!!

// Dave




Nope, "remote" always means "not on the host where the code is running".
With RAPI that will always be the device.

--
Chris Tacke, eMVP
Advisory Board Member
www.OpenNETCF.org
---
Windows CE Product Manager
Applied Data Systems
www.applieddata.net


Dave Corun said:
Oh, hah, when I think of remote, I think "desktop" b/c the function does the
oposite of the other.

Thanks! I'll play w/ it now!

// Dave



If you look at the documentation, you've got your parameters reversed:
http://www.opennetcf.org/docs/Commu...p.Communication.RAPI.CopyFileFromDevice1.html
[Visual Basic]Overloads Public Sub CopyFileFromDevice( _ ByVal
LocalFileName As String, _ ByVal RemoteFileName As String _)
--
Chris Tacke, eMVP
Advisory Board Member
www.OpenNETCF.org
---
Windows CE Product Manager
Applied Data Systems
www.applieddata.net


Dave Corun said:
First off, you guys absolutely RULE for creating this set of libraries for
the rest of us to use!

My question is in regards to CopyFileFromDevice()

I'm basically copying the log.xml file from the device over to my desktop.

i.CopyFileFromDevice("\program files\sd_dispatch\Log.xml", "C:\log.xml",
True)

All I ever get is "Cannot Access Remote File"

The log file exists on the device, but it never gets moved over.

I tried creating an empty file there, but same error when it gets to
CopyFileFromDevice().

dim strFile as string = "C:\log.xml"
Dim f As System.IO.File
If f.Exists(strFile) = True Then f.Delete(strFile)
Dim sr As System.IO.StreamWriter = f.CreateText(strFile)
sr.Close()
f = Nothing
sr = Nothing

I do have another question as well, how would I tell if a file exists
on
the
device? Can I just use system.io.file to hit the device? I want to make
sure I handle any errors relating to the missing files on the device
correctly. This log file is one of 3 files that need to get
transferred
via
RAPI.

Thanks!!!

// Dave

(I didn't mean to make it a response to that Sai's post, but it's
showing
up
that way for me! Sorry for the double-post!)
 
Hmm... The code I have I downloaded is 1.2 from June 6th.

It matches the post though?

Help!

Thanks!

// Dave


It was an early bug that I thought was fixed in 1.1 or 1.2.

--
Chris Tacke, eMVP
Advisory Board Member
www.OpenNETCF.org
---
Windows CE Product Manager
Applied Data Systems
www.applieddata.net


Dave Corun said:
I got past that issue, but now I'm having the problem where
CopyFileToDevice() only copies 4k of the file.

I read this post on the forums:
http://www.opennetcf.org/forums/topic.asp?TOPIC_ID=122


The release I have from the web site has the problems stated in this topic.
Is there another release planned, or am I missing something? The file I'm
trying to copy to the device is 157k right now, but I'll probably go up to
around 170k.

Thanks!!

// Dave




Nope, "remote" always means "not on the host where the code is running".
With RAPI that will always be the device.

--
Chris Tacke, eMVP
Advisory Board Member
www.OpenNETCF.org
---
Windows CE Product Manager
Applied Data Systems
www.applieddata.net


Dave Corun said:
Oh, hah, when I think of remote, I think "desktop" b/c the function does the
oposite of the other.

Thanks! I'll play w/ it now!

// Dave



If you look at the documentation, you've got your parameters reversed:
http://www.opennetcf.org/docs/Commu...p.Communication.RAPI.CopyFileFromDevice1.html
[Visual Basic]Overloads Public Sub CopyFileFromDevice( _ ByVal
LocalFileName As String, _ ByVal RemoteFileName As String _)
--
Chris Tacke, eMVP
Advisory Board Member
www.OpenNETCF.org
---
Windows CE Product Manager
Applied Data Systems
www.applieddata.net


Dave Corun said:
First off, you guys absolutely RULE for creating this set of libraries for
the rest of us to use!

My question is in regards to CopyFileFromDevice()

I'm basically copying the log.xml file from the device over to my desktop.

i.CopyFileFromDevice("\program files\sd_dispatch\Log.xml", "C:\log.xml",
True)

All I ever get is "Cannot Access Remote File"

The log file exists on the device, but it never gets moved over.

I tried creating an empty file there, but same error when it gets to
CopyFileFromDevice().

dim strFile as string = "C:\log.xml"
Dim f As System.IO.File
If f.Exists(strFile) = True Then f.Delete(strFile)
Dim sr As System.IO.StreamWriter = f.CreateText(strFile)
sr.Close()
f = Nothing
sr = Nothing

I do have another question as well, how would I tell if a file exists
on
the
device? Can I just use system.io.file to hit the device? I want to make
sure I handle any errors relating to the missing files on the device
correctly. This log file is one of 3 files that need to get
transferred
via
RAPI.

Thanks!!!

// Dave

(I didn't mean to make it a response to that Sai's post, but it's
showing
up
that way for me! Sorry for the double-post!)
 
I'll have to look at the source. As I recall it was a simple bug so you
might be able to fix it yourself.

--
Chris Tacke, eMVP
Advisory Board Member
www.OpenNETCF.org
---
Windows CE Product Manager
Applied Data Systems
www.applieddata.net

Dave Corun said:
Hmm... The code I have I downloaded is 1.2 from June 6th.

It matches the post though?

Help!

Thanks!

// Dave


It was an early bug that I thought was fixed in 1.1 or 1.2.

--
Chris Tacke, eMVP
Advisory Board Member
www.OpenNETCF.org
---
Windows CE Product Manager
Applied Data Systems
www.applieddata.net


Dave Corun said:
I got past that issue, but now I'm having the problem where
CopyFileToDevice() only copies 4k of the file.

I read this post on the forums:
http://www.opennetcf.org/forums/topic.asp?TOPIC_ID=122


The release I have from the web site has the problems stated in this topic.
Is there another release planned, or am I missing something? The file I'm
trying to copy to the device is 157k right now, but I'll probably go up to
around 170k.

Thanks!!

// Dave




Nope, "remote" always means "not on the host where the code is running".
With RAPI that will always be the device.

--
Chris Tacke, eMVP
Advisory Board Member
www.OpenNETCF.org
---
Windows CE Product Manager
Applied Data Systems
www.applieddata.net


does
the
http://www.opennetcf.org/docs/Commu...p.Communication.RAPI.CopyFileFromDevice1.html
[Visual Basic]Overloads Public Sub CopyFileFromDevice( _ ByVal
LocalFileName As String, _ ByVal RemoteFileName As String _)
--
Chris Tacke, eMVP
Advisory Board Member
www.OpenNETCF.org
---
Windows CE Product Manager
Applied Data Systems
www.applieddata.net


First off, you guys absolutely RULE for creating this set of
libraries
for
the rest of us to use!

My question is in regards to CopyFileFromDevice()

I'm basically copying the log.xml file from the device over to my desktop.

i.CopyFileFromDevice("\program files\sd_dispatch\Log.xml", "C:\log.xml",
True)

All I ever get is "Cannot Access Remote File"

The log file exists on the device, but it never gets moved over.

I tried creating an empty file there, but same error when it gets to
CopyFileFromDevice().

dim strFile as string = "C:\log.xml"
Dim f As System.IO.File
If f.Exists(strFile) = True Then f.Delete(strFile)
Dim sr As System.IO.StreamWriter = f.CreateText(strFile)
sr.Close()
f = Nothing
sr = Nothing

I do have another question as well, how would I tell if a file
exists
 
I don't speak C#, so I'm a bit confused by the function and where it could
be broken. I see that the buffer is set @ 4k here:

byte[] buffer = new byte[0x1000]; // 4k transfer buffer

But I don't see how that could be the problem, its just the buffer that
should continually get cleared. I did rebuild from the source code and
tried using the new dll, but that didn't work either.

Any help you can give me would be excellent! I'm trying to finish up this
app and move onto more exciting things. hehe.

Thanks!!

// Dave


I'll have to look at the source. As I recall it was a simple bug so you
might be able to fix it yourself.

--
Chris Tacke, eMVP
Advisory Board Member
www.OpenNETCF.org
---
Windows CE Product Manager
Applied Data Systems
www.applieddata.net

Dave Corun said:
Hmm... The code I have I downloaded is 1.2 from June 6th.

It matches the post though?

Help!

Thanks!

// Dave


It was an early bug that I thought was fixed in 1.1 or 1.2.

--
Chris Tacke, eMVP
Advisory Board Member
www.OpenNETCF.org
---
Windows CE Product Manager
Applied Data Systems
www.applieddata.net


Dave Corun said:
I got past that issue, but now I'm having the problem where
CopyFileToDevice() only copies 4k of the file.

I read this post on the forums:
http://www.opennetcf.org/forums/topic.asp?TOPIC_ID=122


The release I have from the web site has the problems stated in this topic.
Is there another release planned, or am I missing something? The file I'm
trying to copy to the device is 157k right now, but I'll probably go up to
around 170k.

Thanks!!

// Dave




Nope, "remote" always means "not on the host where the code is running".
With RAPI that will always be the device.

--
Chris Tacke, eMVP
Advisory Board Member
www.OpenNETCF.org
---
Windows CE Product Manager
Applied Data Systems
www.applieddata.net


does
the
http://www.opennetcf.org/docs/Commu...p.Communication.RAPI.CopyFileFromDevice1.html
[Visual Basic]Overloads Public Sub CopyFileFromDevice( _ ByVal
LocalFileName As String, _ ByVal RemoteFileName As String _)
--
Chris Tacke, eMVP
Advisory Board Member
www.OpenNETCF.org
---
Windows CE Product Manager
Applied Data Systems
www.applieddata.net


First off, you guys absolutely RULE for creating this set of
libraries
for
the rest of us to use!

My question is in regards to CopyFileFromDevice()

I'm basically copying the log.xml file from the device over to my desktop.

i.CopyFileFromDevice("\program files\sd_dispatch\Log.xml", "C:\log.xml",
True)

All I ever get is "Cannot Access Remote File"

The log file exists on the device, but it never gets moved over.

I tried creating an empty file there, but same error when it gets to
CopyFileFromDevice().

dim strFile as string = "C:\log.xml"
Dim f As System.IO.File
If f.Exists(strFile) = True Then f.Delete(strFile)
Dim sr As System.IO.StreamWriter = f.CreateText(strFile)
sr.Close()
f = Nothing
sr = Nothing

I do have another question as well, how would I tell if a file
exists
 
Does the function look like this? Most importantly not the line in the Try() that does the second localFile.Read. The second parameter must be zero *not* filepos (which was the earlier bug).

-Chris



public void CopyFileToDevice(string LocalFileName, string RemoteFileName, bool Overwrite)
{
if(!Connected)
{
throw new RAPIException("No connected device.");
}

FileStream localFile;
IntPtr remoteFile = IntPtr.Zero;
int bytesread = 0;
int byteswritten = 0;
int filepos = 0;
int create = Overwrite ? CREATE_ALWAYS : CREATE_NEW;
byte[] buffer = new byte[0x1000]; // 4k transfer buffer

// create the remote file
remoteFile = CeCreateFile(RemoteFileName, GENERIC_WRITE, 0, 0, create, FILE_ATTRIBUTE_NORMAL, 0);

// check for success
if ((int)remoteFile == INVALID_HANDLE_VALUE)
{
throw new RAPIException("Could not create remote file");
}

// open the local file
localFile = new FileStream(LocalFileName, FileMode.Open);

// read 4k of data
bytesread = localFile.Read(buffer, filepos, buffer.Length);
while(bytesread > 0)
{
// move remote file pointer # of bytes read
filepos += bytesread;

// write our buffer to the remote file
if(! Convert.ToBoolean(CeWriteFile(remoteFile, buffer, bytesread, ref byteswritten, 0)))
{ // check for success
CeCloseHandle(remoteFile);
throw new RAPIException("Could not write to remote file");
}
try
{
// refill the local buffer
bytesread = localFile.Read(buffer, 0, buffer.Length);
}
catch(Exception)
{
bytesread = 0;
}
}

// close the remote file
CeCloseHandle(remoteFile);

// close the local file
localFile.Close();
}
 
Awesome man! Totally works now! I just grabbed the most recent release
from the site.

Thanks!

One last question, I'm checking the sample now to see if it handles this,
but is there a way I can tell if a file exists on the device?

I know for Windows Forms apps you can instantiate a system.io.file and use
..Exists(), but what about w/ RAPI?

Thanks!

// Dave


Does the function look like this? Most importantly not the line in the
Try() that does the second localFile.Read. The second parameter must be
zero *not* filepos (which was the earlier bug).

-Chris
 
Back
Top