GSM Shop GSM Shop
GSM-Forum  

Welcome to the GSM-Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features.
Only registered members may post questions, contact other members or search our database of over 8 million posts.

Registration is fast, simple and absolutely free so please - Click to REGISTER!

If you have any problems with the registration process or your account login, please contact contact us .

Go Back   GSM-Forum > Other Gsm/Mobile Related Forums > GSM Programming & Reverse Engineering


GSM Programming & Reverse Engineering Here you can post all Kind of GSM Programming and Reverse Engineering tools and Secrets.

Reply
 
LinkBack Thread Tools Display Modes
Old 04-29-2018, 03:08   #1 (permalink)
Junior Member
 
Join Date: May 2014
Location: Turkey
Posts: 36
Member: 2184561
Status: Offline
Thanks Meter: 2
Sony write usb port delphi...


Hello guys.I am preparing a program on sony devices.How do I write and send data in Delphi ?


I am using this unit but unfortunately it did not work...


PHP Code:
unit USB;

interface
Uses SysUtilsFormsWindows;

{******************************************************************************}
{*                       
USB Read Write Unit                              *}
{*                          
by Harald Kubovy                                  *}
{*                                                                            *}
{*  
How To USE:                                                               *}
{*  
Sending and Reading Data to Device:                                       *}
{*  
string_result:= RWUSB('DATA TO SEND IN HEX'ReadTimeout);              *}
{*                                                                            *}
{*  
EXAMPLE (ONLY SENDING):                                                   *}
{*  
s:= RWUSB('FF FF FF');                                                    *}
{*                                                                            *}
{*  
s is String Result of Readed Data from Device                             *}
{*  
'FF FF FF' is Data to Send in Hex  (this will send FFFFFF to Device       *}
{*                                                                            *}
{*                                                                            *}
{*  
EXAMPLE WITH READING AFTER WRITING:                                       *}
{*  
s:= RWUSB('FFFF'16);                                                    *}
{*                                                                            *}
(*  
16 How mutch to Read for no Reading                                 *)
{*                                                                            *}
{*  
EXAMPLE WITH TIMEOUT:                                                     *}
{*  
s:= RWUSB('FFFF'16100);                                               *}
{*                                                                            *}
{*  
100 is the Reading TimeoutStandart is 500/ms.                           *}
{*                                                                            *}
{*                                                                            *}
{* 
Copyright - Do whatever you whant with it  ;o)                             *}
{******************************************************************************}



type
TSetofChars 
Set of Char;

  Function 
USBOpenDriver:boolean;
  Function 
USBCloseDriver:boolean;
  function 
USBReadText(BytesReadcardinaltimeoutcardinal 500): string;
  function 
USBReadHEX(BytesReadcardinaltimeoutcardinal 500): string;
  function 
RWUSB(framestringreadLen:integer 0ReadTimeoutinteger 500Typ String 'HEX') : string;
  
procedure USBWriteHEX(framestring);

implementation


Get Handle of DeviceDriver }
var 
USBPORT:Thandle INVALID_HANDLE_VALUE;

{
$HINTS OFF}
Open USB Driver }
Function 
USBOpenDriver:boolean;
begin
  
// Open Device Path  \\?\USB#Vid_058b&Pid_0015#5&25ea51ff&0&1#{a5dcbf10-6530-11d2-901f-00c04fb951ed}
  
USBPORT:= CreateFile('\??\USB#VID_0FCE&PID_ADDE#5&dc4a972&0&10#{a5dcbf10-6530-11d2-901f-00c04fb951ed}'GENERIC_WRITE or GENERIC_READ,
  
FILE_SHARE_WRITE or FILE_SHARE_READnilOPEN_EXISTINGFILE_FLAG_OVERLAPPED OR FILE_ATTRIBUTE_NORMAL0);
  
USBOpenDriver:= USBPORT <> INVALID_HANDLE_VALUE;
  if 
USBPORT INVALID_HANDLE_VALUE then // error at open port
    
begin
      result
:=false;
    
end else result:=true;
end;
{
$HINTS ON}


Function 
USBCloseDriver:boolean;
begin
  USBCloseDriver 
:= CloseHandle(USBPORT);
  
USBPORT := INVALID_HANDLE_VALUE;
end;


function 
NurBestimmteZeichen (const aValue StringaChars TSetofChars) : String;
var
  
iInteger;
  
newString string;
begin
  newString 
:= '';
  for 
:= 0 to Length(aValue) do
  
begin
    
if aValue[iin aChars then
    begin
      newString 
:= newString aValue[i];
    
end;
  
end;
  
result := newString;
end;



Function 
HexToStr(sString): String;
Var
 
Integer;
Begin
  Result
:=''i:=1;
  While 
i<Length(s) Do
  
Begin
    Result
:=Result+Chr(StrToIntDef('$'+Copy(s,i,2),0));
    
Inc(i,2);
  
End;
End;


Function 
StrToHex(sString): String;
Var
  
Integer;
Begin
  Result
:='';
  If 
Length(s)>0 Then
    
For i:=1 To Length(s) Do Result:=Result+IntToHex(Ord(s[i]),2);
End;



Function 
USBReadTEXT(BytesRead dWordtimeoutcardinal 500) : string;
var
  
d: array[0..10000of byte; {Readed Data}
  
sbufferstring;
  
iTmpInteger;
  
Ovr TOverlapped;
  
count :cardinal; {Count How mutch Readed Bytes}
begin
  Result 
:= '';
  
count:=0;
  
Fillchardsizeof(d), );
  
FillChar(OvrSizeOf(TOverlapped), 0);
  
Ovr.hEvent := CreateEvent(niltrueFALSEnil);
  if 
not ReadFile(USBPORTdBytesReadcount, @ovrthen
    
if GetLastError=Error_IO_Pending then
      
if WaitForSingleObject(ovr.hEventtimeout) = WAIT_OBJECT_0 then
        GetOverlappedResult
(USBPORTovrcountfalse)
  else 
CancelIo(USBPORT);
  
CloseHandle(Ovr.hEvent);
  
:= '';
  for 
:= 0 to count-do
  
begin
    Tmp
:=ord(d[i]);
    
:= Char(Tmp);
  
end;
  {
Convert to String Text}
  
:= strtohex(s);
  
buffer:='';
  for 
i:=1 to length(s) do
  
begin
    
if Odd(ithen
    begin
      buffer 
:= '';
      
buffer := hextostr(s[i] + s[i+1]);
      
buffer := NurBestimmteZeichen(buffer,['0'..'9','a'..'z','A'..'Z','.'..':',' '..'?']);
      
result := result+buffer;
    
end;
  
end;
end;



Function 
USBReadHEX(BytesRead dWordtimeoutcardinal 500) : string;
var
  
d: array[0..10000of byte; {Readed Data}
  
sstring;
  
iTmpInteger;
  
Ovr TOverlapped;
  
count :cardinal; {Count How mutch Readed Bytes}
begin
  Result 
:= '';
  
count:=0;
  
Fillchardsizeof(d), );
  
FillChar(OvrSizeOf(TOverlapped), 0);
  
Ovr.hEvent := CreateEvent(niltrueFALSEnil);
  if 
not ReadFile(USBPORTdBytesReadcount, @ovrthen
    
if GetLastError=Error_IO_Pending then
      
if WaitForSingleObject(ovr.hEventtimeout) = WAIT_OBJECT_0 then
        GetOverlappedResult
(USBPORTovrcountfalse)
  else 
CancelIo(USBPORT);
  
CloseHandle(Ovr.hEvent);
  
:= '';
  for 
:= 0 to count-do
  
begin
    Tmp
:=ord(d[i]);
    
:= Char(Tmp);
  
end;
  
Result := strtohex(s);
end;



Function 
_USBWritePointerA(bp PointerSizeToSend DWordtimeoutinteger) : Cardinal;
var
  
Ovr TOverlapped;
begin
    Result 
:= 0;
    
FillChar(OvrSizeOf(TOverlapped), 0);
    
Ovr.hEvent := CreateEvent(niltrueFALSEnil);
    if 
not WriteFile(USBPortbp^, SizeToSendResult, @ovrthen
        
if GetLastError=Error_IO_Pending then
            
if WaitForSingleObject(ovr.hEventtimeout) = WAIT_OBJECT_0 then
                GetOverlappedResult
(USBPORTovrResultfalse)
            else 
CancelIo(USBPORT);
    
CloseHandle(Ovr.hEvent);
end;



procedure USBWriteHEX(framestring);
var
  
BytesWrittenDWord;
begin
  
while Pos(' 'FRAME) > do Delete(FRAME,Pos(' 'FRAME),1);
  
frame:=hextostr(frame);
  
WriteFile(USBPORT, (Pchar(frame))^, SizeOf(frame), BytesWrittennil);
end;




Function 
USBWritePointerA(bp PointerSizeToSend DWord) : boolean;
begin
  Result 
:= _USBWritePointerA(bpSizeToSend, $688) = SizeToSend;
end;



Function 
USBWriteStringA(SendString String) : boolean;
var
  
StrSize Word;
begin
  StrSize 
:= Length(SendString);
  
Result := _USBWritePointerA(@SendString[1], StrSize, $688) = StrSize;
end;


function 
RWUSB(framestringreadLen:integer 0ReadTimeoutinteger 500Typ String 'HEX') : string;
begin
  
while Pos(' 'FRAME) > do Delete(FRAME,Pos(' 'FRAME),1);
  if 
length(frame) >0 then USBWriteStringA(hextostr(frame));
  
Application.ProcessMessages;
  
sleep(ReadTimeout);
  if (
ReadLen >0) and (Typ='HEX')    then result:=USBReadHEX(readLenReadTimeout);
  if (
ReadLen >0) and (Typ='STRING'then result:=USBReadText(readLenReadTimeout);
end;


end
  Reply With Quote
Old 05-03-2018, 19:57   #2 (permalink)
No Life Poster
 
Join Date: Oct 2010
Posts: 723
Member: 1422878
Status: Offline
Thanks Meter: 164
search about Comport component fro delphi
  Reply With Quote
Old 05-04-2018, 05:48   #3 (permalink)
Junior Member
 
Join Date: May 2014
Location: Turkey
Posts: 36
Member: 2184561
Status: Offline
Thanks Meter: 2
Quote:
Originally Posted by helpinterchange View Post
search about Comport component fro delphi
no comport bro.i need a usb port plugin but i could not find it...
  Reply With Quote
Old 05-04-2018, 09:17   #4 (permalink)
No Life Poster
 
fr3nsis's Avatar
 
Join Date: Oct 2005
Location: Rome , Italy
Posts: 1,530
Member: 190882
Status: Offline
Sonork: BB PIN: 7C83D9CE
Thanks Meter: 1,282
Donate money to this user
check the device path
  Reply With Quote
Old 05-04-2018, 14:11   #5 (permalink)
No Life Poster
 
Join Date: Oct 2010
Posts: 723
Member: 1422878
Status: Offline
Thanks Meter: 164
Check this links

https://sourceforge.net/projects/winusb-delphi/

https://stackoverflow.com/questions/...vice-in-delphi
  Reply With Quote
Old 05-04-2018, 15:29   #6 (permalink)
Junior Member
 
Join Date: May 2014
Location: Turkey
Posts: 36
Member: 2184561
Status: Offline
Thanks Meter: 2
Quote:
Originally Posted by fr3nsis View Post
check the device path
I checked it, I can open the device, but I can not read ...

I am writing data but I can not read...
  Reply With Quote
Old 05-11-2018, 14:08   #7 (permalink)
Junior Member
 
Join Date: May 2014
Location: Turkey
Posts: 36
Member: 2184561
Status: Offline
Thanks Meter: 2
I could not find a solution...
  Reply With Quote
Reply

Bookmarks


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


 



All times are GMT +1. The time now is 10:01.



Powered by Searchlight © 2024 Axivo Inc.
vBulletin Optimisation provided by vB Optimise (Pro) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
- GSM Hosting Ltd. - 1999-2023 -
Page generated in 0.37822 seconds with 9 queries

SEO by vBSEO