Gostaria de algum tutorial para utilização dessa tecnologia.
Tenho uma aplicação onde coleta informações de uma dll. Essa dll e carregada com informações de uma maquina progamada em clp. Tenho as variaveis e metodos a utilizacao dos metodos ate agora tudo bem mais somente coletar o valor de uma valriavel da dll estou efetuando problemas. Teria alguma ajuda nesse procedimento.
Usando um descopilador essa seria minha dll com seus metodos e variaveis
’ Methods
<DllImport(“Atos2Pc.dll”, CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)> _
Public Shared Function EnviaAck(ByVal PlcAddress As Integer, ByVal hCom As Integer, ByVal Timeout As Integer, ByRef Erro As Integer, <MarshalAs(UnmanagedType.VBByRefStr)> ByRef BufferTx As String, <MarshalAs(UnmanagedType.VBByRefStr)> ByRef BufferRx As String) As Integer
End Function
<DllImport("Atos2Pc.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)> _
Public Shared Function EnviaBloc(ByVal PlcAddress As Integer, ByVal MemoryAddress As Integer, ByVal Quantidade As Integer, ByRef ValorMB As Byte, ByVal hCom As Integer, ByVal Timeout As Integer, ByRef Erro As Integer, <MarshalAs(UnmanagedType.VBByRefStr)> ByRef BufferTx As String, <MarshalAs(UnmanagedType.VBByRefStr)> ByRef BufferRx As String) As Integer
End Function
<DllImport("Atos2Pc.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)> _
Public Shared Function EnviaByte(ByVal PlcAddress As Integer, ByVal MemoryAddress As Integer, ByVal ValorB As Byte, ByVal hCom As Integer, ByVal Timeout As Integer, ByRef Erro As Integer, <MarshalAs(UnmanagedType.VBByRefStr)> ByRef BufferTx As String, <MarshalAs(UnmanagedType.VBByRefStr)> ByRef BufferRx As String) As Integer
End Function
<DllImport("Atos2Pc.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)> _
Public Shared Function EnviaVar(ByVal PlcAddress As Integer, ByVal MemoryAddress As Integer, ByRef ValorM As Byte, ByVal hCom As Integer, ByVal Timeout As Integer, ByRef Erro As Integer, <MarshalAs(UnmanagedType.VBByRefStr)> ByRef BufferTx As String, <MarshalAs(UnmanagedType.VBByRefStr)> ByRef BufferRx As String) As Integer
End Function
<DllImport("Atos2Pc.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)> _
Public Shared Function EnviaVarInt(ByVal PlcAddress As Integer, ByVal MemoryAddress As Integer, ByVal ValorI As Integer, ByVal hCom As Integer, ByVal Timeout As Integer, ByRef Erro As Integer, <MarshalAs(UnmanagedType.VBByRefStr)> ByRef BufferTx As String, <MarshalAs(UnmanagedType.VBByRefStr)> ByRef BufferRx As String) As Integer
End Function
<DllImport("Atos2Pc.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)> _
Public Shared Function EnviaVarIntBcd(ByVal PlcAddress As Integer, ByVal MemoryAddress As Integer, ByVal ValorIBcd As Integer, ByVal hCom As Integer, ByVal Timeout As Integer, ByRef Erro As Integer, <MarshalAs(UnmanagedType.VBByRefStr)> ByRef BufferTx As String, <MarshalAs(UnmanagedType.VBByRefStr)> ByRef BufferRx As String) As Integer
End Function
<DllImport("Atos2Pc.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)> _
Public Shared Function GetChannel(ByRef hCom As Integer, ByRef Erro As Integer, ByVal Canal As Integer, ByVal Timeout As Integer, ByVal BaudRate As Integer, ByVal StopBits As Integer, ByVal DataBits As Integer, ByVal Paridade As Byte) As Integer
End Function
<DllImport("Atos2Pc.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)> _
Public Shared Sub GetDllVersion(<MarshalAs(UnmanagedType.VBByRefStr)> ByRef Versao As String)
End Sub
<DllImport("Atos2Pc.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)> _
Public Shared Function PedeBloc(ByVal PlcAddress As Integer, ByVal MemoryAddress As Integer, ByVal Quantidade As Integer, ByRef ValorMB As Byte, ByVal hCom As Integer, ByVal Timeout As Integer, ByRef Erro As Integer, <MarshalAs(UnmanagedType.VBByRefStr)> ByRef BufferTx As String, <MarshalAs(UnmanagedType.VBByRefStr)> ByRef BufferRx As String) As Integer
End Function
<DllImport("Atos2Pc.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)> _
Public Shared Function PedeByte(ByVal PlcAddress As Integer, ByVal MemoryAddress As Integer, ByRef ValorB As Byte, ByVal hCom As Integer, ByVal Timeout As Integer, ByRef Erro As Integer, <MarshalAs(UnmanagedType.VBByRefStr)> ByRef BufferTx As String, <MarshalAs(UnmanagedType.VBByRefStr)> ByRef BufferRx As String) As Integer
End Function
<DllImport("Atos2Pc.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)> _
Public Shared Function PedeVar(ByVal PlcAddress As Integer, ByVal MemoryAddress As Integer, ByRef ValorM As Byte, ByVal hCom As Integer, ByVal Timeout As Integer, ByRef Erro As Integer, <MarshalAs(UnmanagedType.VBByRefStr)> ByRef BufferTx As String, <MarshalAs(UnmanagedType.VBByRefStr)> ByRef BufferRx As String) As Integer
End Function
<DllImport("Atos2Pc.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)> _
Public Shared Function PedeVarInt(ByVal PlcAddress As Integer, ByVal MemoryAddress As Integer, ByRef ValorI As Integer, ByVal hCom As Integer, ByVal Timeout As Integer, ByRef Erro As Integer, <MarshalAs(UnmanagedType.VBByRefStr)> ByRef BufferTx As String, <MarshalAs(UnmanagedType.VBByRefStr)> ByRef BufferRx As String) As Integer
End Function
<DllImport("Atos2Pc.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)> _
Public Shared Function PedeVarIntBcd(ByVal PlcAddress As Integer, ByVal MemoryAddress As Integer, ByRef ValorIBcd As Integer, ByVal hCom As Integer, ByVal Timeout As Integer, ByRef Erro As Integer, <MarshalAs(UnmanagedType.VBByRefStr)> ByRef BufferTx As String, <MarshalAs(UnmanagedType.VBByRefStr)> ByRef BufferRx As String) As Integer
End Function
<DllImport("Atos2Pc.dll", CharSet:=CharSet.Ansi, SetLastError:=True, ExactSpelling:=True)> _
Public Shared Function ReleaseChannel(ByVal hCom As Integer) As Integer
End Function
' Fields
Public Shared BaudRate As Integer
Public Shared BufferRx As FixedLengthString = New FixedLengthString(100)
Public Shared BufferTx As FixedLengthString = New FixedLengthString(100)
Public Shared Canal As Integer
Public Shared CanalOk As Boolean
Public Shared DataBits As Integer
Public Shared Erro As Integer
Public Shared hCom As Integer
Public Shared MemoryAddress As Integer
Public Shared Paridade As Byte
Public Shared PlcAddress As Integer
Public Shared Quantidade As Integer
Public Shared StopBits As Integer
Public Shared Timeout As Integer
Public Shared ValorB As Byte
Public Shared ValorI As Integer
Public Shared ValorIBcd As Integer
Public Shared ValorM As Byte() = New Byte(3 - 1) {}
Public Shared ValorMB As Byte() = New Byte(9 - 1) {}
Public Shared ValorMB4 As Integer
Public Shared Versao As FixedLengthString = New FixedLengthString(4)
End Class
Me codigo Java
import java.lang.reflect.Field;
import com.sun.jna.Native;
public class Conexao {
public static void main(String args[]){
MySharedLibrary lib = (MySharedLibrary) Native.loadLibrary(“Atos2Pc”, MySharedLibrary.class);
lib.PedeVarIntBcd(1, 2, 2, 2, 2, 2);
}
}
import com.sun.jna.Library;
public interface MySharedLibrary extends Library {
public void PedeVarIntBcd(Integer PlcAddress, Integer MemoryAddress, Integer ValorIBcd, Integer hCom, Integer Timeout, Integer Erro);
}
Usando um metodo para teste funcionou mais queria somente coletar dados de uma variavel que tem dentro da dll. Essa dll serve apenas de comunicacao com o clp e o computador.
Muito Obrigado