How to use the PHP COM class to access functions of the SAT emulator dll?

0

I'm developing a ERP that needs to use SAT for Electronic Tax Coupon, but I do not know how to use PHP to access DLL of Emulator Offline.

I've been searching and it looks like it's possible to access with new COM() , but I've seen very little content about it.

Someone with knowledge to give a help?

    
asked by anonymous 27.10.2016 / 18:53

1 answer

1

To use the COM class it is necessary to activate the extension php_com_dotnet.dll in php.ini (clearly this is only for Windows), something like this:

extension=php_com_dotnet.dll

After this you need to restart Apache / Nginx / lighttpd (or restart the server / machine).

  • The new COM class does not have much documentation, because it has nothing to talk about, because the only thing it does is to release the functions of a registered DLL in the operating system .

  • COM means Component Object Model , ie the class will only access DLLs that use things like OLE, basically if the DLL is not made with OLE and compatible, it will not be possible to use% because as I said this is not a class to load DLLs but rather to load the functions of DLLs registered in the System.

      

    I do not know if it is possible to access all ActiveX, COM + and DCOM, which are other technologies of the same tracking, I will edit the response as soon as I can confirm.

To register a DLL, you must eventually run the REGSVR32 command:

REGSVR32 minhadll.dll

If the DLL has the COM interface and the registry is fine then you will have access via PHP normally, something like (hypothetical example):

  • Register:

    REGSVR32 FooBar.dll
    
  • Use:

    $my_dll = new COM('FooBar.Functions');
    

Execute Command Line DLL

Assuming the documentation provides some access to a command line tool of the SAT itself, you could use a new COM like this:

$comando = escapeshellcmd('ferramenta_sat_hipotetica.exe comando1 comando2 arg3');
$resposta = shell_exec($comando);

echo $resposta;

You can also try to run the windows RUNDLL32 command:

RUNDLL32.EXE <dllname>,<entrypoint> <optional arguments>

It would look something like:

RUNDLL32.EXE MINHADLL.DLL,Install 200 Argumento

In PHP it would look like this:

$comando = escapeshellcmd('RUNDLL.EXE MINHADLL.DLL,Install 200 Argumento');
$resposta = shell_exec($comando);

echo $resposta;

Read more about RUNDLL at:

I found the documentation and an example with the DLL, in the example they put an extra quotation mark, maybe it is typing error shell_exec , however if it fails try new COM('"SATscript.DLL.object') .

First download the link after running the new COM('SATscript.DLL.object') that is inside the compact, it will register the DLL, should run the 64bit version if you are using Windows 64bit, any doubt or problem inside the folder has this REGSATscript.exe file, after registering the DLL just run:

<?php

try {
    $SATsw = new COM('"SATscript.DLL.object') OR die ('NÃO POSSO CRIAR OBJETO');

    // "?????????????????    S T A T U S   ???????????????????????????"
    // "Índice       Retorno 0                     Retorno 1 "
    // "  1    Impressora operacional        Impressora em falha" 
    // "  2    Off Line                      On Line "
    // "  3    Papel OK                      Fim de papel "
    // "  4    Guilhotina não detectada      Guilhotina detectada "
    // "  5    Tampa térmica fechada         Tampa térmica aberta "
    // "  6    Sem papel sobre o sensor      Papel posicionado sobre o sensor "
    // "  7    Gaveta fechada                Gaveta aberta. "
    // "  8    Cheque inserido               SEM CHEQUE."

    $LF = '<br>';

    $retorno = $SATsw->Status_SI300 ("1");  
    echo 'Status_SAT ("1")   ->  Operacional?    = ', $retorno, $LF;

    $retorno = $SATsw->Status_SI300 ("2");  
    echo 'Status_SAT ("2")   ->  ON/OFF?         = ', $retorno, $LF;

    $retorno = $SATsw->Status_SI300 ("3");  
    echo 'Status_SAT ("3")   ->  FIM Papel?      = ', $retorno, $LF;

    $retorno = $SATsw->Status_SI300 ("4");  
    echo 'Status_SAT ("4")   ->  Guilhotina?     = ', $retorno, $LF;

    $retorno = $SATsw->Status_SI300 ("5");  
    echo 'Status_SAT ("5")   ->  Tampa?          = ', $retorno, $LF;

    $retorno = $SATsw->Status_SI300 ("6");  
    echo 'Status_SAT ("6")   ->  Papel acabando? = ', $retorno, $LF;

    $retorno = $SATsw->Status_SI300 ("7");  
    echo 'Status_SAT ("7")   ->  Gaveta?         = ', $retorno, $LF;

    $retorno = $SATsw->Status_SI300 ("8");  
    echo 'Status_SAT ("8")   ->  Cheque?         = ', $retorno, $LF;

    $retorno = $SATsw->StatusGuilhotina_SI300 ();
    echo 'StatusGuilhotina_SI300 () -> Guilhotina? = ', $retorno, $LF;

} catch (Exception $e) {
    echo 'resultado: ', $e->getMessage(), "\n";
}
    
27.10.2016 / 19:34