USB x Paralela: DLL em VB6 para C#
Tenho uma dll que funciona em VB6 para acessar a USB x Paralela, quando utilizo em C# ela só reconhece o equipamento (porta paralela), porém não consigo enviar nem receber dados. Alguém teria uma forma de fazer com que permitisse o acesso em C#?
Ronaldo
Curtidas 0
Respostas
Marcio Silveira
19/07/2011
Ronaldo,
Se essa sua dll é um objeto COM+ deveria funcionar normalmente no C#, basta fazer a referência.
Se essa sua dll é um objeto COM+ deveria funcionar normalmente no C#, basta fazer a referência.
GOSTEI 0
Ronaldo
19/07/2011
Já fiz a referência ela reconhece e na hora de acessar que esta dando problema, parece que esta sendo bloqueada.
Veja a referencia:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices; namespace paralela_usb
{
unsafe class paralela
{
[DllImport("RCOM_USB_LPT.dll")]
public static extern unsafe bool TestaBit(byte valor, byte bit);
[DllImport("RCOM_USB_LPT.dll")]
public static extern unsafe byte LigaBit(byte Valor, byte Bit);
[DllImport("RCOM_USB_LPT.dll")]
public static extern unsafe byte DesligaBit(byte Valor, byte Bit);
[DllImport("RCOM_USB_LPT.dll")]
public static extern unsafe int LPT_Abrir_Porta(string NomePorta);
[DllImport("RCOM_USB_LPT.dll")]
public static extern unsafe int LPT_WriteByte(long hDevice, byte pRegIndex, byte pRegValue);
[DllImport("RCOM_USB_LPT.dll" )]
public static extern unsafe byte LPT_ReadByte(long hDevice, byte pRegIndex);
[DllImport("RCOM_USB_LPT.dll" )]
public static extern unsafe bool CheckDriver(long hDevice);
[DllImport("kernel32")]
public static extern long CloseHandle (long hObject);
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices; namespace paralela_usb
{
unsafe class paralela
{
[DllImport("RCOM_USB_LPT.dll")]
public static extern unsafe bool TestaBit(byte valor, byte bit);
[DllImport("RCOM_USB_LPT.dll")]
public static extern unsafe byte LigaBit(byte Valor, byte Bit);
[DllImport("RCOM_USB_LPT.dll")]
public static extern unsafe byte DesligaBit(byte Valor, byte Bit);
[DllImport("RCOM_USB_LPT.dll")]
public static extern unsafe int LPT_Abrir_Porta(string NomePorta);
[DllImport("RCOM_USB_LPT.dll")]
public static extern unsafe int LPT_WriteByte(long hDevice, byte pRegIndex, byte pRegValue);
[DllImport("RCOM_USB_LPT.dll" )]
public static extern unsafe byte LPT_ReadByte(long hDevice, byte pRegIndex);
[DllImport("RCOM_USB_LPT.dll" )]
public static extern unsafe bool CheckDriver(long hDevice);
[DllImport("kernel32")]
public static extern long CloseHandle (long hObject);
}
GOSTEI 0
Marcio Silveira
19/07/2011
Ronaldo,
Qual a mensagem de erro?
Pensei numa coisa aqui, mas não faz muito sentido, porque quem interage com o hardware é o COM+, mas existem algumas configurações de segurança na framework que podem estar com baixo nível de confiança para o DotNet.
Mas faz o seguinte, tenta fazer um try/catch para pegar a InnerException. Assim talvez possamos ajudar mais.
Qual a mensagem de erro?
Pensei numa coisa aqui, mas não faz muito sentido, porque quem interage com o hardware é o COM+, mas existem algumas configurações de segurança na framework que podem estar com baixo nível de confiança para o DotNet.
Mas faz o seguinte, tenta fazer um try/catch para pegar a InnerException. Assim talvez possamos ajudar mais.
GOSTEI 0
Ronaldo
19/07/2011
Não ocorre erro, simplesmente ele não envia o dado. Preciso saber de uma maneira para passar pelo framework para conseguir acessar de forma direta, fiz em C funcionou, porém em C# não consigo enviar o dado...
GOSTEI 0