|
-
Sep 12th, 2007, 08:26 AM
#1
Thread Starter
PowerPoster
[RESOLVED] Copy file to scanner
I am starting this as a new thread.
Here is what I am doing.
On PC, I create a flat file (Z:\Location.txt)
I want to copy flat file to scanner
On scanner application, I will add a button that displays a grid with the location data loaded.
Should not be too difficult.
My 1st stumbling block is what to do if the file already exists on the scanner (which it will). Here is my code for loading the file.
filename = "Z:\LOCATION.TXT"
'locate the file, and see if it already exists on the device
lngFileHandle = CeFindFirstFile(filename, typFindFileData)
'if we get -1 then the file wasn't found so we can go ahead and create it
'otherwise we dont want to overwrite in this demo, so we will cancel the operation.
'If lngFileHandle <> INVALID_HANDLE Then
' MsgBox filename & " already exists. Operation Cancelled."
' CeFindClose lngFileHandle
' CopyFileToPocketPC = False
'End If
==> The previous bit of code, from a sample, did not want to overwrite the file. I do.
'create the file on the device, and return the handle to the file
'--filename = Form1.txtPPCFile.Text
lngDestinationHandle = CeCreateFile(filename, GENERIC_WRITE, FILE_SHARE_READ, vbNullString, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0)
'if something went wrong in CeCreateFile we will get -1, and therefore need to abort
If lngDestinationHandle = INVALID_HANDLE Then
MsgBox "CeCreateFile Error " & CeGetLastError & " occurred.", vbCritical & vbOKOnly
CopyFileToPocketPC = False
Exit Function
End If
==> because I did not delete the existing file, I get a 'Create File' error here (error #3).
===================================================
If your question has been answered, mark the thread as [RESOLVED]
-
Sep 12th, 2007, 08:32 AM
#2
Frenzied Member
Re: Copy file to scanner
"Z:\LOCATION.TXT" won't exist on the device - it will by default, I think, be in "My Documents\Location.txt".
Pete
-
Sep 12th, 2007, 08:56 AM
#3
Thread Starter
PowerPoster
===================================================
If your question has been answered, mark the thread as [RESOLVED]
-
Sep 12th, 2007, 09:08 AM
#4
Thread Starter
PowerPoster
Re: Copy file to scanner
I changed it to this:
'-- filename
filename = "My Documents/LocationFile"
originalfile = "Z:\DAD\LOCATION.TXT"
'locate the file, and see if it already exists on the device
lngFileHandle = CeFindFirstFile(filename, typFindFileData)
'create the file on the device, and return the handle to the file
'--filename = Form1.txtPPCFile.Text
lngDestinationHandle = CeCreateFile(filename, GENERIC_WRITE, FILE_SHARE_READ, vbNullString, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0)
'if something went wrong in CeCreateFile we will get -1, and therefore need to abort
If lngDestinationHandle = INVALID_HANDLE Then
MsgBox "CeCreateFile Error " & CeGetLastError & " occurred.", vbCritical & vbOKOnly
CopyFileToPocketPC = False
Exit Function
End If
'Call function to read file on the desktop into the byte buffer
If ReadFileAsBinary(originalfile, lngFileSize, bytBuffer()) = True Then
'Write contents of Binary buffer to CE file.
'Return value of 0 = failure, non zero = success
intRetVal = CeWriteFile(lngDestinationHandle, bytBuffer(0), lngFileSize, lngNumBytesWritten, 0)
I get a Create File error 32. This code resides on the PC, by the way. I just want to get the file to the scanner right now.
===================================================
If your question has been answered, mark the thread as [RESOLVED]
-
Sep 12th, 2007, 09:11 AM
#5
Thread Starter
PowerPoster
Re: Copy file to scanner
I don't know what error 32 is. Could it be because the file exists and I am trying to create it? If so, how would I delete it first?
===================================================
If your question has been answered, mark the thread as [RESOLVED]
-
Sep 12th, 2007, 09:17 AM
#6
Frenzied Member
Re: Copy file to scanner
filename = "My Documents/LocationFile"
should it not be
filename = "\My Documents\Location.txt"
??
-
Sep 12th, 2007, 09:20 AM
#7
Thread Starter
PowerPoster
Re: Copy file to scanner
I the routine that copies FROM the scanner I have:
filename = "My Documents/ScannerFile"
That seems to work.
===================================================
If your question has been answered, mark the thread as [RESOLVED]
-
Sep 12th, 2007, 09:23 AM
#8
Thread Starter
PowerPoster
Re: Copy file to scanner
Have a look at this:
'locate the file, and see if it already exists on the device
lngFileHandle = CeFindFirstFile(filename, typFindFileData)
'must delete the old file if it exists
If lngDestinationHandle <> INVALID_HANDLE Then
'-- delete file here
Exit Function
End If
How do I tell the scanner to delete the existing file? I think this will fix my current problem.
===================================================
If your question has been answered, mark the thread as [RESOLVED]
-
Sep 12th, 2007, 09:40 AM
#9
Frenzied Member
Re: Copy file to scanner
Hi,
rapi contains a 'CeDeleteFile'.
Public Declare Function CeDeleteFile Lib "rapi.dll" ( _
DeviceFileName As String) As Integer
I think
OpentNetCF has an opensource DesktopCommunication Library that wraps all the rapi calls
-
Sep 12th, 2007, 09:42 AM
#10
Thread Starter
PowerPoster
Re: Copy file to scanner
I was reading that the CREATE_ALWAYS shoudl do thje same thing.
lngDestinationHandle = CeCreateFile(filename, GENERIC_WRITE, FILE_SHARE_READ, vbNullString, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0)
However, I will try the above first
===================================================
If your question has been answered, mark the thread as [RESOLVED]
-
Sep 12th, 2007, 10:12 AM
#11
Thread Starter
PowerPoster
Re: Copy file to scanner
I'm making progress. I commented out this code:
'if something went wrong in CeCreateFile we will get -1, and therefore need to abort
If lngDestinationHandle = INVALID_HANDLE Then
MsgBox "CeCreateFile Error " & CeGetLastError & " occurred.", vbCritical & vbOKOnly
CopyFileToPocketPC = False
Exit Function
End If
because I read that it will get an error even the process succeeds because the file previously existed.
Now I am getting an error reading the original file. It looks likes thes:
1243,'','1','2','03',4536
1350,'3100510','3','3','41',2580
1455,'5500200','2','3','35',3876
1825,'3100010','3','3','41',3655
2000,'','3','3','09',-800
2048,'4242020','2','0','16',30000
2345,'','2','3','17',5525
2352,'','2','3','11',-33000
2365,'','3','3','43',6000
The code to read the file is:
Private Function ReadFileAsBinary(strSrcFilename As String, lngFileSize As Long, bytBuffer() As Byte) As Boolean
On Error GoTo ErrHandler
Dim intFileHandle As Integer
Dim intSeekPos As Integer
lngFileSize = FileLen(strSrcFilename)
intFileHandle = FreeFile
Open strSrcFilename For Binary As intFileHandle
For intSeekPos = 1 To lngFileSize
Get #intFileHandle, intSeekPos, bytBuffer(intSeekPos - 1)
Next intSeekPos
Close intFileHandle
ReadFileAsBinary = True
Exit Function
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ErrHandler:
MsgBox "Error reading file " & strSrcFilename, vbCritical & vbOKOnly
ReadFileAsBinary = False
End Function
It makes it through the For Loop for a bit before it pukes with a read error.
===================================================
If your question has been answered, mark the thread as [RESOLVED]
-
Sep 12th, 2007, 10:25 AM
#12
Thread Starter
PowerPoster
Re: Copy file to scanner
Got it fixed. I had to change the buffer size from
Dim bytBuffer(16384) As Byte
to
Dim bytBuffer(106384) As Byte
Evidently the read blew up when the buffer filled up.
===================================================
If your question has been answered, mark the thread as [RESOLVED]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|