Reading Files from a USB camera

Hi All,

I have an application that detects when digital cameras are connected and
copies file from them.  Currently it works with plug in play cameras that
use USB storage and I am now working on a Still Image version.  I have the
Still Image handler code working and I can detect what USB port the camera
is on, but I am unable to read from that port.  Basically what I want to do
is use windows.CreateFile passing the USB port in the format of //./Usbscan
and then query and read from this location.  Below is a sample application
that uses CreateFile and then attempts to get pipe information from the file
handle using DeviceIOControl.  The CreateFile call works without issue, but
I am getting an error, 87 - Parameter incorrect, on the DeviceIOControl
call.  I have tried all combination of params I can think of to no avail.
Hopefully someone out there has done something similar...  Here is the code:


unit Demo;


interface


uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;


{ start USBSCAN.h translation }
const


  FILE_DEVICE_USB_SCAN = $8000;
  IOCTL_INDEX = $0800;
  METHOD_BUFFERED = 0;
  FILE_ANY_ACCESS = 0;
  MAX_NUM_PIPES = 8;


  IOCTL_GET_PIPE_CONFIGURATION =
    (FILE_DEVICE_USB_SCAN SHL 16)  OR
    (FILE_ANY_ACCESS SHL 14) OR
    ((IOCTL_INDEX + 10) SHL 2) or METHOD_BUFFERED;
    //CTL_CODE(FILE_DEVICE_USB_SCAN, IOCTL_INDEX +
10,METHOD_BUFFERED,FILE_ANY_ACCESS);


type
  _RAW_PIPE_TYPE = (
    USBSCAN_PIPE_CONTROL,
    USBSCAN_PIPE_ISOCHRONOUS,
    USBSCAN_PIPE_BULK,
    USBSCAN_PIPE_INTERRUPT  );


  _USBSCAN_PIPE_INFORMATION = record
    MaximumPacketSize: Word;
    EndpointAddress: UCHAR;
    Interval: UCHAR;
    PipeType: _RAW_PIPE_TYPE;
  end {_USBSCAN_PIPE_INFORMATION};
  USBSCAN_PIPE_INFORMATION = _USBSCAN_PIPE_INFORMATION;
  PUSBSCAN_PIPE_INFORMATION = ^_USBSCAN_PIPE_INFORMATION;


  _USBSCAN_PIPE_CONFIGURATION = record
    NumberOfPipes: ULONG;
    PipeInfo: Array[0..MAX_NUM_PIPES-1] of USBSCAN_PIPE_INFORMATION;
  end {_USBSCAN_PIPE_CONFIGURATION};
  USBSCAN_PIPE_CONFIGURATION = _USBSCAN_PIPE_CONFIGURATION;
  PUSBSCAN_PIPE_CONFIGURATION = ^_USBSCAN_PIPE_CONFIGURATION;


{ end USBSCAN.h translation }


type
  TForm1 = class(TForm)
    Button1: TButton;
    Memo1: TMemo;
    Edit1: TEdit;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;


var
  Form1: TForm1;


implementation


{$R *.DFM}


procedure TForm1.Button1Click(Sender: TObject);
var
     hres: HRESULT;
     srcHandle: THandle;
     usbScanPipeInfo : USBSCAN_PIPE_CONFIGURATION;
     overlapped : TOverlapped;
     bytesReturned: DWORD;
     b : boolean;
     pt : _RAW_PIPE_TYPE;
begin
  memo1.lines.clear();
  memo1.lines.Add(format('USBSCAN_PIPE_CONFIGURATION
size:%s',[inttostr(sizeof(USBSCAN_PIPE_CONFIGURATION))]));
  memo1.lines.Add(format('USBSCAN_PIPE_INFORMATION
size:%s',[inttostr(sizeof(USBSCAN_PIPE_INFORMATION))]));


  // Initialize Overlapped structure
  FillChar(overlapped, SizeOf(overlapped), #0);
  overlapped.hEvent := CreateEvent(nil, True, False, nil);


  srcHandle := CreateFile(
                    PChar(edit1.text),   // format = //./Usbscanx
                    GENERIC_READ,
                    FILE_SHARE_READ,
                    nil,
                    OPEN_EXISTING,
                    FILE_ATTRIBUTE_NORMAL {OR FILE_FLAG_OVERLAPPED},
                    0
                   );


  memo1.lines.Add(format('CreateFile LastError
size:%s',[inttostr(getlasterror ())]));


  b := DeviceIoControl(
         srcHandle,
         DWORD(IOCTL_GET_PIPE_CONFIGURATION),
         nil,
         0,
         @usbScanPipeInfo,
         sizeof(USBSCAN_PIPE_CONFIGURATION),
         bytesReturned,
         //@overlapped    // if FLAG FILE_FLAG_OVERLAPPED set in CreateFile
         nil
        );


  memo1.lines.Add(format('DeviceIoControl LastError
size:%s',[inttostr(getlasterror ())]));


  CloseHandle(srcHandle);


  SetEvent(overlapped.hEvent);
  CloseHandle(overlapped.hEvent);


end;


end.
0
Laszlo
8/20/2008 5:22:15 PM
embarcadero.delphi.nativeapi 1236 articles. 1 followers. Follow

0 Replies
1193 Views

Similar Articles

[PageSpeed] 37
Get it on Google Play
Get it on Apple App Store

Reply:

Similar Artilces:

Get files from USB camera
Hi I'm using delphi 2007 on windows VISTA and I'm having great fun getting images from a USB camera. Vista automatically mounts the camera in Computer\Canon DIGITAL IXUS i zoom\Removable storage\DCIM\100CANON So when I use a standard TOpenPictureDialog box it allows me to see the file quite happily as in vista explorer but when I select them and hit OK in the Files property of the TOpenPictureDialog there is only a list of filenames no sort of path structure. How do I then go and open/copy/move those files? Thanks Paul The FileName property should include the path. ...

Eof of file , file read and file write ! Problem !
Hello All, I want to do 2 things. I have a big file and I want to read file line by line upto last. and side by side i want to write it to new file with some change I am not getiing , in a read , linemode! how i will get End of file and how i will do all this. can you tell me script. I'm not sure I understand your question. From the PowerBuilder Help file, in linemode! FileRead() will return a 0 when it reaches End of File (EOF) so it should be trivial to code? This is just off the cuff but I would imagine it's something like li_Readfile = FileOpen( <my file to read information> ) <validate that file opened properly and return value is not null and greater than -1> li_WriteFile = FileOpen( <my new file to be written information> ) <validate that file opened properly and return value is not null and greater than -1> li_CharactersRead = FileRead( li_ReadFile, ls_Line) ll_TotalWritten = 0 DO While li_CharactersRead > 0 li_CharactersWritten = FileWrite( liWriteFile, ls_Line) <Validate that characters written is equal to characters read> ll_TotalWritten = ll_TotalWritten + li_CharactersRead li_CharactersRead = FileRead( li_ReadFile, ls_Line) END DO li_Return = FileClose( li_ReadFile) <Validate close succeeded> li_Return = FileClose( li_WriteFile) <Validate Close succeeded> There's an example in the online help for the examples fo...

Reading a text file in Delphi 2009
Hi, I recently downloaded a free 30 day trial of delphi 2009 for my computing AS level. I am currently using the program to write simple coonsole applications. I am having trouble with a certain command Reset. This is the code that i have entered and the error occurs when it reaches Reset. We have Delphi 7 at my school and i have used it on 7 and itt works but when i try and run it on 2009 it comes up with an error message abnd a warning saying; [DCC Warning] txtfilerandom.dpr(20): W1019 For loop control variable must be simple local variable [DCC Error] txtfilerandom.dpr(28): E2070 Unknow...

Reading files from file server
Hi all,I need help reading data from files . I am storing files in the file system and  unable to read the file from the file system. I am stroing doc and PDF files in my file system. Can any one help me in reading the  files back from the file system...  Here is my code  If (uploadPDF.HasFile = False Or uploadWord.HasFile = False) Then                           ' No file uploaded!&nbs...

Delphi control Samsung Tab3 camera over USB
Platform: DXE3 -> 32b .exe running on a Win7 laptop. I want my 32b .exe running on the laptop to be able to take control of the camera of the Samsung Tab 3 via a USB cable. I want my users to be able to use my .exe running on the laptop to be able to see on the Win7 laptop, what the camera is seeing, and click a "Take Picture" button to take the picture, and then have that picture automatically loaded to the Win7 laptop in a designated folder. Is there anything out there that does this? Thanks in advance for your help. Kevin wrote: > Is there anything out there th...

File read write on iOS using Delphi
Does anyone have sample code that shows how to read and write files on iOS device in Delphi? Or any other information on that topic? How is file i/o in iOS different on the Simulator and the actual iOS device itself? Thanks! Almost same in windows , but r/w speed is much slower :) {code} // // iOS Native Graphic Wrapper for Delphi // unit iOS_Files; interface {$mode delphi} {$modeswitch objectivec1} uses SysUtils, Types, Classes, Variants, Math, UITypes, CFBase,CFURL, CGContext,CGGeometry,CGColorSpace, iPhoneAll, NSHelpers, // By P...

how to choose and read doc or txt file in delphi project
hello, help me, i want to make choose file button in my delphi project, choose my .doc or .txt file and read it in my project. user user1 wrote: > hello, help me, i want to make choose file button in my delphi project, choose my .doc or .txt > file and read it in my project. Hi, The following should get you started: Drop a TButton and a TOpenDialog on a form. Double click on the button and fill in the following in the OnClick handler of the button: {code} procedure TForm2.Button1Click(Sender: TObject); var sl: TStringList; begin if not OpenDialog1.Execute(Handle) ...

Trying to read two files using a sub to get the data, but 2nd read on the 2nd file goes to EOF
------_=_NextPart_001_01C73F21.48FF8233 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Here is a snippet of the code: my $MyFileHand; =20 my $MyFileHand1; =20 =20 open($MyFileHand,"<$MyFileIn") || diet (3, $MyFileIn, $!); open($MyFileHand1,"<$MyFileIn1") || diet (3, $MyFileIn1, $!); =20 ............ =20 proc_getrcd( $MyFileHand , $MyEOFProd, $MyWorkp, $MyInp , $GlblInfo{compcnt}, $MyUnpackSw ); proc_getrcd( $MyFileHand1, $MyEOFTest, $MyWorkt, $MyInt , $GlblInf...

Is Anybody Working on a Delphi Class to Read PST Files?
See http://msdn.microsoft.com/en-us/library/ff385210(v=office.12).aspx The PST format is publicly documented now. John Jacobson wrote: > The PST format is publicly documented now The joking/cynical side of me wonders what the new file format for the *next* version of Outlook is going to be ... -- John Kaster http://blogs.embarcadero.com/johnk Embarcadero Developer Network: http://edn.embarcadero.com Features and bugs: http://qc.embarcadero.com Got source? http://cc.embarcadero.com On 5/27/2010 10:39 AM, John Kaster wrote: > John Jacobson wrote: > >> Th...

Simple read write usb hid delphi [Edit]
I'm working in Delphi2010 and looking for some simple code to find a USB HID device with a known PID VID then write a few bytes (not more than 6) and read a few bytes (not more than 40) from the device on occasion and handle the simple "it's missing" kind of thing. I already have a form with places to generate the outgoing data and handle the incoming data. The device (with a PIC) already has the code to be found as well as code to get and send data, but the computer Delphi end is driving me nuts. I can f ind all sorts of code that will make a list, and put another box on th...

Read an outlook (express or not) body of message file with Delphi
Hello to the Delphi gurus out there, Any idea on how to read the text of a message from a *.msg file Ms outlook or express we get a lot of deamon generated messages of bad addresses (I swear I do not engage in spamming) and we would like to extract the bad email to check them hence extracting the returns save them in a directory and extract who it was sent to I know how to do that if we convert each messages as a text file but it is a waste time it would be very fast that straight from the original I googled my fingers away but no results yes any clues Thanks Philippe Waatel Hi,...

Reading/Writing Really Large XML files... Delphi 2009
Hello Everyone, I was just wondering what the current preference is out there for reading and writing really large XML files? I used to use SAX - but it was not updated for Delphi 2009. I have tried a few others - but I am having issues with really large files - like over 800MB or so. Bradley unfortunatly you can try http://www.sourceforge.net/projects/alcinoe/ it's work weel with giga of data in SAX but i don't know if it's will run under d2009 ... "Bradley MacDonald" <bradsub@timeacct.com> wrote in message news:176382@forums.codegear.com....

Component to read, display and print xlsx files in Delphi 2010 ?
Dear All, I have purchased both flexcel and axolot for Delphi 2010. Not happy with the support from either of them. Flexcel has not yet delivered the dll for use in Delphi 2010 for xlsx files (purchased flexcel in april). Axolot support is extremely slow and xls spreadsheet 2 is unable to print xlsx files properly with margins and bitmaps. Can anyone suggest a component to read an xlsx file, display it on screen and then print it to a printer and export to pdf ? It is critical for me and require it asap. Thanks, Nirali Shah I'm surprised to hear that you are disapp...

Convert TSDFDataSet to Delphi 2009 ( read Text file like dataset )
Hi I'm looking TSdfDataSet for Delphi 2009 With Delphi 2007 , work all fine , but in Delphi 2009 i see only first char in every fields Somebody have already update this src ? Important point of src : unit SdfData; //----------------------------------------------------------------------------- { Unit Name : SdfData Application : TSdfDataSet TFixedFormatDataSet Components Version : 2.04 Author : Orlando Arrocha email: oarrocha@hotmail.com Purpose : This components are designed to access directly text files as database tabl...

'C:\INETPUB\WWWROOT\APP_DATA\ASPNETDB.MDF' cannot be upgraded because it is read-only or has read-only files. Make the database or files writeable, and rerun recovery.
I have developed an app with sql server express 2005 and IIS and when I try to run it on another computer I get the following error message: ASPNETDB.MDF' cannot be upgraded because it is read-only or has read-only files. Make the database or files writeable, and rerun recovery.Cannot open user default database. Login failed.Login failed for user 'IBM\ASPNET'. Help would be much appreciated. Thanks Darren ACLs on the folders, permissions, check to see if SQL Express is installed, etc. JeffPlease: Don't forget to click "Mark as Answer" on the post that helped you. That ...

Database 'C:\INETPUB\WWWROOT\HOURSREPORTING\APP_DATA\ASPNETDB.MDF' cannot be upgraded because it is read-only or has read-only files. Make the database or files writeable, and rerun recovery.
I have a website that runs on this computer through IIS. It was working fine until I went into it and added a textbox. Now it gives me this: Server Error in '/' Application. Database 'C:\INETPUB\WWWROOT\HOURSREPORTING\APP_DATA\ASPNETDB.MDF' cannot be upgraded because it is read-only or has read-only files. Make the database or files writeable, and rerun recovery.Cannot open user default database. Login failed.Login failed for user 'NT AUTHORITY\NETWORK SERVICE'. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.SqlClient.SqlException: Database 'C:\INETPUB\WWWROOT\HOURSREPORTING\APP_DATA\ASPNETDB.MDF' cannot be upgraded because it is read-only or has read-only files. Make the database or files writeable, and rerun recovery.Cannot open user default database. Login failed.Login failed for user 'NT AUTHORITY\NETWORK SERVICE'.Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. Stack Trace: [SqlException (0x80131904): Database 'C:\INETPUB\WWWROOT\HOURSREPORTING\APP_DATA\ASPNETDB.MDF' cannot be upgraded because it is read-only or has read-only files. Make the database or...

reading we.config file as XML file
Hi, I need to read web.config file of another application. I think it can be done by reading config file as xml file. How can i do this? If it possible, give me some sample code. Is there any other way to read it? Thanks in advance. /Mamun   Please refer below code snippetSuppose below is ur web.config file1 <configuration> 2 <appSettings> 3 <add key="Login" value="admin"/> 4 <add key="Password" value="admin123"/> 5 </appSettings> 6 <connectionStrings> 7 <...

Problem reading some fileds in xml file
It's part of xml file i'm gathering info ..... <ThirdPartyProductInfo> - <ThirdPartyProductDetails> <OfferingType>Used</OfferingType> <SellerId>A16MZ6IWWRWUP5</SellerId> <SellerNickname /> <ExchangeId>Y11M3385853M6777809</ExchangeId> <OfferingPrice>$169.99</OfferingPrice> <Condition>new</Condition> <ExchangeAvailability>Usually ships in 4-5 business days</ExchangeAvailability> <SellerCountry>NA</SellerCountry> <SellerState>NA&l...

File Read and File Delete. Concurrency
Keeping image files and their thumbnail image files in a directory and using a custom handler to show the miniatures (and create cache thumbnails mentioned before) I sometimes have a situation where a user downloads a file (the handler is being used) and admin wanting to delete the file in the same time. That creates a situation when file cannot be deleted due to access deny. Ideas how to let admin delete the file anyway?   Best regards,Jarosław Jaskułowski...

How to read file size of an existing file?
I was wondering if there was a way to read files byte size? I know there is System.IO namespace that interacts with the files/folders.  Any help will be highly appreciated. Thanksnimish   Hi nimish,  try this  FileInfo f = new FileInfo(@"c:\YourFileName.txt"); long fileSize = f.Length; Note: Don't forget to include System.IO namespace Thanks, Best Regards, Muhammad Akhtar SHiekhPlease remember to mark the appropriate replies as answer after your question is solved, thanks You can check the FileInfo class to work get properties of a certain fil...

Can't read an Excel 2010 32bit file from a Delphi 64bit program
Hello, I have a 64bit Delphi program that is trying to read an Excel spreadsheet using ADO. The platform is Windows 7 64bit with Office 2010 32bit installed. So I have a 64bit program trying to read Excel using 32bit drivers. I think this is the core of the problem. When I change my target platform and compile the program as 32bit, the code reads the Excel file correctly. When it fails I get the message 'Provider cannot be found. It may not be properly installed. Here is my procedure to read the file. I appreciate any help. Thanks in advance, Hardee Mahoney Washington, DC ...

I'm looking TSdfDataSet for Delphi 2009 ( read Text file like dataset )
Hi I'm looking TSdfDataSet for Delphi 2009 With Delphi 2007 , work all fine , but in Delphi 2009 i see only first char in every fields Somebody have already update this src ? Important point of src : unit SdfData; //----------------------------------------------------------------------------- { Unit Name : SdfData Application : TSdfDataSet TFixedFormatDataSet Components Version : 2.04 Author : Orlando Arrocha email: oarrocha@hotmail.com Purpose : This components are designed to access directly text files as database tabl...

How disable save file popup error message: file "could not be saved, because the source file could not be read." ; jor
When I save web pages (complete, not merely html, in order to save images) to my disk, while offline, I get about 10 pop up messages saying it can't load .js & .php files. I have to close each one of those 10 windows individually - a big waste of human time. Firefox 3.6.10 on Ubuntu Linux 10.4 Is there a way to 1) disable those info messages so they don't pop up, or 2) have ff put all the messages into merely one window, so I only have to close one window per web page. Thanks. :) = Popup window error message: {filename path to folder on disk} "could not...

Web resources about - Reading Files from a USB camera - embarcadero.delphi.nativeapi

Reading education in the United States - Wikipedia, the free encyclopedia
Reading education is the process by which individuals are taught to derive meaning from text. Government-funded scientific research on reading ...

Still Surprised By Trump? Then You’re Not Reading Scott Adams
Trump is typically regarded as the least scientific candidate, but according to Scott Adams, he is the best at using the "science of persuasion." ...

It’s time to check out the Philips Hue smartphone-controlled lights you keep reading about
... shot. The Philips 456194 Hue White and Color Ambiance A19 Starter Kit is now available from Amazon for just under $194 shipped. Continue reading... ...

A Reading for the Pigou Club
On British Columbia's carbon tax .

Weekend Reading: Robert Waldmann: New Keynesian Orthodoxy and Hysteresis
**Weekend Reading: Robert Waldmann**: [New Keynesian Orthdoxy and Hysteresis](http://angrybearblog.com/2016/02/new-keynesian-orthdoxy-and-hysteresis.html): ...

Ted Cruz likes to twerk and eat hair in Bad Lip Reading video
The US presidential race gets much more entertaining when Ted Cruz's comments are translated via YouTube series Bad Lip Reading. His new campaign ...

Bad Lip Reading Does Ted Cruz
I'm still laughing so hard at this. It had me in the first 30 seconds or so. Watch, laugh and share.

Ted Cruz Tells Baby ‘You’re The Devil’ In Latest ‘Bad Lip Reading’
Ted Cruz Tells Baby ‘You’re The Devil’ In Latest ‘Bad Lip Reading’

Recommended Reading: US Soccer uses VR to reveal new crest
US Soccer's Rebranding Gets an Assist From Virtual Reality Zach Schonbrun, New York Times When the time came to reveal its new crest, the US ...

Watch Jon Cryer and Wife Lisa Joyner's Emotional Reading on 'Long Island Medium'
The 'Long Island Medium' special, live, two-hour event airs Sunday, March 6 on TLC.

Resources last updated: 3/8/2016 10:21:04 AM