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

Asked

Viewed 1,822 times

0

I’m developing a ERP you need to use SAT to issue an Electronic Tax Coupon, but I don’t know how to use the PHP to access the DLL of the Offline Emulator.

I’ve been researching and it seems that it is possible to access with new COM(), but I saw little content concerning this.

Someone knowledgeable to give a help?

  • The new COM only releases the functions of the Dlls or port (depends on what you will do), but basically what you need is the documentation of such Dlls and that they have an "activex" (COM server...??) to know the commands and not PHP necessarily.

  • Actually I need to access the functions of this DLL. I have the manual with the functions that the SAT dll offers, but I’m not able to access the dll. I try to access with the class with passing DLL name (new COM(name_da_dl.dl)) but returns the error Fatal error: Uncaught Exception 'com_exception' with message 'Failed to create COM Object'

  • A dll is registered (with REGSVR32)? Note that according to the PHP documentation, if the DLL does not have support for COM server or IDispatch then PHP won’t be able to do anything, PHP won’t access Dlls, it accesses DLL COM.

  • Diego that new COM(nome_da_dl.dl) does not make sense, COM is to access registered Dlls, are you sure you really read the php doc? I will pass the link and try to formulate a reply, following the doc link: http://php.net/manual/faq.com.php

  • Thank you for your answers, William. The dll is not registered, is provided by Sefaz and do not know if it has support COM or Idispatch, in the manual there is no reference to this. The problem is the lack of examples and documentation to access the functions to communicate with the SAT Emulator in PHP. I’m 2 days researching and nothing :(.

  • PHP has no way to document any of this, what it does is to free up access to functions, see if you can understand the answer I posted and try to use the new COM and then tells me the error/Exception that occurs exactly

Show 1 more comment

1 answer

1


To use the class COM 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 class new COM doesn’t have much documentation anyway, because there’s nothing to talk about, this because the only thing he does is release the functions of a Registered DLL in the operating system.

  • The class does not load or read Dlls, it only loads the registered Dlls functions, as example of some Activex usage.

  • WITH IT 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 new COM, as I said this is not a class to load Dlls but to load the Dlls functions registered in the System.

    i do not know whether it is possible to access all Activex, COM+ and DCOM, which are other technologies of the same track, I will edit the answer as soon as I can confirm.

To register a Dlls it is necessary to run the command REGSVR32:

REGSVR32 minhadll.dll

If the DLL has the COM interface and the record occurs all right, then you will have access via PHP normally, something like (hypothetical example):

  • Register:

    REGSVR32 FooBar.dll
    
  • Use:

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

Run DLL by command line

Assuming that the documentation provides some access to a command line tool of the SAT itself, could use a shell_exec thus:

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

echo $resposta;

You can also try running 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 in:

I found the documentation and an example with the DLL, in the example they put an extra quote, maybe it is typo new COM('"SATscript.DLL.object'), yet if you fail try this new COM('SATscript.DLL.object').

First download the http://sistemas.sweda.com.br/downloads/suporte/SATscript.zip then rotate the REGSATscript.exe that this inside the compact, it will register the DLL, should run version 64bit if you are using Windows 64bit, any questions or problem inside the folder has this file SATscript.zip\Manual\ManualdoUsuarioSATScript.pdf, 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";
}
  • Thanks William, I will look for another way, because the dll is not 'registrable', but your answer will make me try another way, because I still do not know which method to use to communicate with this SAT emulator in PHP.

  • @Diegoqueiroz Outside the Dlls, does this SAT have a command line? Because if you already have an answer :)

  • @Diegoqueiroz edited the answer, see if the example suits you, note that such SAT should have a doc that will provide examples of use to then try the RUNDLL or such tool that I quoted.

  • @Gilhermenascim was able to communicate with the SAT emulator app in this way, thank you. I’m still not able to pass the function parameters correctly. The function is Senddatasell and it expects 3 parameters. I tried to pass like this = RUNDLL32.EXE dllsat.dll, EnviarDadosVenda 012346 12345678 xml. How do I step the parameters?

  • @Diegoqueiroz I think there’s a space left after the comma dllsat.dll, EnviarDadosVenda, would be so dllsat.dll,EnviarDadosVenda, the arguments just taking the documentation from dll and really I didn’t find anything on the net about dllsat.dll :/

  • @I tested with RUNDLL32.exe, could communicate with SAT emulator, but could not pass the parameters correctly. Maybe this dll is not prepared for this, I can not say, because I am layman in this part. Anyway, I ended up going another way using a program that uses sockets and intermediates between my program and the SAT emulator. Thanks for the help!

  • @Diegoqueiroz that of the socket was mass, formula an answer later ;)

  • @Diegoqueiroz managed to find on the site the manual and the tool to register the DLL, I edited the answer and put an example

  • 1

    @Guilermenascimento I haven’t had time to test this solution you found. I will take a little time today in the late afternoon and give you answer. Vlw!

  • @I tested this solution from Satscript, but it only works on SWEDA brand Sats as far as I could see. As I will have several brands of customer-like SAT the only solution I found for now was even the use of ACBR Monitor PLUS. Vlw!

Show 5 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.