Comunicação com DLL da Balança Weightech
12/06/2015
0
Estou tentando fazer a comunicação com uma balança WeighTech, modelo WT1000. A empresa disponibiliza a DLL, e os códigos fontes em VB.NET e DELPH 7. Quando rodo os fontes deles, eles funcionam. Pegam o peso da balança e colocam em um textFild. Preciso fazer isso em Java. Alguém tem idéia de como fazer?
Os códigos e a DLL está no site da balança
www.weightech.com.br/downloads
Última opção de download
Segue o código em VB.NET
Os códigos e a DLL está no site da balança
www.weightech.com.br/downloads
Última opção de download
Segue o código em VB.NET
Option Strict Off Option Explicit On Friend Class frmWtRD Inherits System.Windows.Forms.Form Private Declare Function Peso Lib "WtRd.dll" () As Double Private Declare Function Status Lib "WtRd.dll" () As Short Private Declare Function Ponto Lib "WtRd.dll" () As Short Private Declare Function LePeso Lib "WtRd.dll" () As Boolean Private Declare Function Iniciar Lib "WtRd.dll" (ByVal Indicador As Short, ByVal PortaCom As Short, ByVal BaudRate As Integer, ByVal Paridade As Short, ByVal DataBits As Short, ByVal StopBits As Short) As Integer Private Declare Sub Parar Lib "WtRd.dll" () Private Declare Function Indicador Lib "WtRd.dll" () As Integer Private Sub btnParar_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles btnParar.Click Parar() btnLeituraContinua.Enabled = True btnLerUmaVez.Enabled = True tmrLepeso.Enabled = False lblPeso.Text = "------" End Sub Private Sub Command1_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles btnIniciar.Click Dim intStatus As Short Try intStatus = Iniciar(CShort(txtIndicador.Text), CShort(txtPorta.Text), CInt(txtBaudRate.Text), CShort(txtParidade.Text), CShort(txtDataBits.Text), CShort(txtStopBits.Text)) Select Case intStatus Case Is = 0 tmrLepeso.Enabled = True btnLeituraContinua.Enabled = True btnLerUmaVez.Enabled = True Case Is = 1 : MsgBox("Porta inválida!!") Case Is = 2 : MsgBox("Porta já está aberta!") Case Is = 3 : MsgBox("Parâmetros inválidos!") Case Is = 4 : MsgBox("Comunicação já foi iniciada!") Case Is = 5 : MsgBox("Falha genérica!") End Select Catch ex As Exception ExibeErro("Passando parâmetros para a Dll" & vbLf & ex.Message) End Try End Sub Private Sub frmWtRD_FormClosed(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed tmrLepeso.Enabled = False Parar() End Sub Private Sub tmrLepeso_Tick(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles tmrLepeso.Tick If LePeso() Then dadosDoPeso() End If End Sub Private Sub dadosDoPeso() Dim intPonto As Integer Dim Masc As String If Status = 3 Then lblPeso.Text = "Falha" ElseIf Status = 2 Then lblPeso.Text = "Sobre Carga" Else intPonto = Ponto If intPonto = 0 Then Masc = "0" Else Masc = "0." & New String("0", Ponto) End If lblPeso.Text = VB6.Format(Peso, Masc) End If lblEstavel.Visible = (Status = 0) lblOscilando.Visible = (Status = 1) If EErro("Teste WtRd - Lendo Peso") Then tmrLepeso.Enabled = False Parar() End If End Sub Private Sub ExibeErro(ByRef Acao As String) If Err.Number <> 0 Then MsgBox(Acao & vbLf & "Erro nº " & Err.Number & " - " & Err.Description) Err.Clear() End If End Sub Private Function EErro(ByRef Acao As String) As Boolean If Err.Number <> 0 Then MsgBox(Acao & vbLf & "Erro nº " & Err.Number & " - " & Err.Description) Err.Clear() EErro = True End If End Function Private Sub btnLerUmaVez_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLerUmaVez.Click If LePeso Then dadosDoPeso() Else lblPeso.Text = "Indisponível" End If End Sub Private Sub btnLeituraContinua_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLeituraContinua.Click btnLerUmaVez.Enabled = False tmrLepeso.Enabled = True End Sub Private Sub frmWtRD_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub Private Sub Label2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label2.Click End Sub End Class
Holden Offmenn
Curtir tópico
+ 0
Responder
Clique aqui para fazer login e interagir na Comunidade :)