Usuário com melhor resposta
Abrir porta LPT1

Pergunta
-
Bom dia, pessoal.
Alguém sabe como posso abrir e escrever diretamente na porta LPT1 ?
Achei algo na internet, mas não está funcionando:
[
DllImport("inpout32.dll", EntryPoint = "Out32")]
public static extern void Output(int adress, int value);
Unable to load DLL 'inpout32.dll': Não foi possível encontrar o módulo especificado. (Exception from HRESULT: 0x8007007E)
Obrigado!
Respostas
-
Respondendo à pergunta:
public
class MPrinter : MarshalByRefObject{
public ErrorPrinter(){
}
const uint GENERIC_READ = 0x80000000; const uint GENERIC_WRITE = 0x40000000; const uint OPEN_EXISTING = 3;[
DllImport("kernel32.dll", SetLastError = true)] static extern Microsoft.Win32.SafeHandles.SafeFileHandle CreateFile(string lpFileName, uint dwDesiredAccess, uint dwShareMode, IntPtr lpSecurityAttributes, uint dwCreationDisposition, uint dwFlagsAndAttributes, IntPtr hTemplateFile);{
Console.WriteLine("Message is: {0}", msg);Microsoft.Win32.SafeHandles.
SafeFileHandle handleValue = null; string toPrint = string.Format("{0:dd/MM/yy hh:mm:ss}: {1}\n", DateTime.Now,msg); // open LPT1 for WritinghandleValue = CreateFile(
"LPT1:", GENERIC_WRITE, 0, IntPtr.Zero,OPEN_EXISTING, 0,
IntPtr.Zero); if (handleValue.IsInvalid) return; FileStream f = new FileStream(handleValue, FileAccess.Write); byte[] buffer = Encoding.ASCII.GetBytes(toPrint);f.Write(buffer, 0, buffer.Length);
f.Flush();
f.Close();
}
}
Todas as Respostas
-
Respondendo à pergunta:
public
class MPrinter : MarshalByRefObject{
public ErrorPrinter(){
}
const uint GENERIC_READ = 0x80000000; const uint GENERIC_WRITE = 0x40000000; const uint OPEN_EXISTING = 3;[
DllImport("kernel32.dll", SetLastError = true)] static extern Microsoft.Win32.SafeHandles.SafeFileHandle CreateFile(string lpFileName, uint dwDesiredAccess, uint dwShareMode, IntPtr lpSecurityAttributes, uint dwCreationDisposition, uint dwFlagsAndAttributes, IntPtr hTemplateFile);{
Console.WriteLine("Message is: {0}", msg);Microsoft.Win32.SafeHandles.
SafeFileHandle handleValue = null; string toPrint = string.Format("{0:dd/MM/yy hh:mm:ss}: {1}\n", DateTime.Now,msg); // open LPT1 for WritinghandleValue = CreateFile(
"LPT1:", GENERIC_WRITE, 0, IntPtr.Zero,OPEN_EXISTING, 0,
IntPtr.Zero); if (handleValue.IsInvalid) return; FileStream f = new FileStream(handleValue, FileAccess.Write); byte[] buffer = Encoding.ASCII.GetBytes(toPrint);f.Write(buffer, 0, buffer.Length);
f.Flush();
f.Close();
}
}
-
Bem ...Não sei se isso que vc quer,mas se for para aumentar a velocidade da net,vai em: Painel de controle-Sistemas-Gerenciador de dispositivo eclica em portas (Com e LPT) +porta com 1+config. de porta e em bits por segundo coloca talado. vc vai ver a diferença da sua net.
vai tbm em portas COM 2 e faz o mesmo procedimento.sua net vai bombar igual as de lan-house.
Abçs