VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "PCScale - Exemplo de utilização VB5.0"
   ClientHeight    =   3660
   ClientLeft      =   3105
   ClientTop       =   3000
   ClientWidth     =   6585
   LinkTopic       =   "Form1"
   ScaleHeight     =   3660
   ScaleWidth      =   6585
   Begin VB.Frame Frame4 
      Caption         =   "Unidade"
      Height          =   855
      Left            =   4560
      TabIndex        =   9
      Top             =   720
      Width           =   1215
      Begin VB.Label PUnit 
         Alignment       =   2  'Center
         Height          =   195
         Left            =   240
         TabIndex        =   10
         Top             =   360
         Width           =   720
      End
   End
   Begin VB.Frame Frame3 
      Caption         =   "Líquido"
      Height          =   855
      Left            =   3240
      TabIndex        =   3
      Top             =   720
      Width           =   1215
      Begin VB.Label PLiquido 
         Alignment       =   2  'Center
         Height          =   195
         Left            =   240
         TabIndex        =   6
         Top             =   360
         Width           =   720
      End
   End
   Begin VB.Frame Frame2 
      Caption         =   "Tara"
      Height          =   855
      Left            =   1920
      TabIndex        =   2
      Top             =   720
      Width           =   1215
      Begin VB.Label PTara 
         Alignment       =   1  'Right Justify
         Height          =   195
         Left            =   240
         TabIndex        =   5
         Top             =   360
         Width           =   720
      End
   End
   Begin VB.Frame Frame1 
      Caption         =   "Bruto"
      Height          =   855
      Left            =   600
      TabIndex        =   1
      Top             =   720
      Width           =   1215
      Begin VB.Label PBruto 
         Alignment       =   1  'Right Justify
         Height          =   195
         Left            =   240
         TabIndex        =   4
         Top             =   360
         Width           =   765
      End
   End
   Begin VB.Timer Timer1 
      Enabled         =   0   'False
      Interval        =   50
      Left            =   120
      Top             =   120
   End
   Begin VB.CommandButton ButtonTeste 
      Caption         =   "Teste"
      Height          =   735
      Left            =   2280
      TabIndex        =   0
      Top             =   2520
      Width           =   1815
   End
   Begin VB.Label Label1 
      Alignment       =   2  'Center
      Caption         =   "COM2, 4800, 7, e, 2"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H80000017&
      Height          =   255
      Left            =   1080
      TabIndex        =   8
      Top             =   240
      Width           =   4215
   End
   Begin VB.Label LabelError 
      Alignment       =   2  'Center
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H80000017&
      Height          =   255
      Left            =   1080
      TabIndex        =   7
      Top             =   1920
      Width           =   4215
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim hScale As Long
  
 
Private Sub ButtonTeste_Click()
     
     Dim COM, BaudRate, ByteSize, StopBits, Parity, Status As Long
     
     If ButtonTeste.Caption = "Teste" Then
          COM = 2         '  // comunication port
          BaudRate = 4800 '  // BaudRate
          ByteSize = 7    '  // number of bits/byte, 4-8
          StopBits = 2    '  // 0,1,2 = 1, 1.5, 2
          Parity = 2      '  // 0-4=no,odd,even,mark,space

          Status = AttachScale(hScale, COM, BaudRate, ByteSize, StopBits, Parity)
          If (Status < 0) Then
            Select Case Status
              Case -2
                LabelError.Caption = "Erro abrindo COM"
              Case -3
                LabelError.Caption = "COM inválida"
              Case -4
                LabelError.Caption = "Muitos arquivos abertos"
              Case -5
                LabelError.Caption = "Acesso à COM não permitido"
              Case -6
                LabelError.Caption = "Erro setando parâmetros de comunicação"
              Case -7
                LabelError.Caption = "Erro setando timeout de comunicação"
              Case -100
                LabelError.Caption = "Arquivo vazio"
              Case -101
                LabelError.Caption = "Disco cheio"
              Case -106
                LabelError.Caption = "Input inválido"
              Case Else
                LabelError.Caption = "Erro Genérico"
            End Select
          Else
            Timer1.Enabled = True
            ButtonTeste.Caption = "Parar"
          End If
     Else
          Timer1.Enabled = False
          DettachScale (hScale)
          ButtonTeste.Caption = "Teste"
          LabelError.Caption = ""
     End If
End Sub

Private Sub Timer1_Timer()

    Const ScaleError As Long = 0
    Const ScaleInMotion As Long = 1
    Const ScaleStable As Long = 2
    Const ScaleOutOfRange As Long = 3
    Const ProteqNotFound As Long = 4
    
    Const BIDS As Long = 0
    Const BIQP810 As Long = 1
    Const B9091 As Long = 2
    Const B8132 As Long = 3
    Const BID10000 As Long = 4
    Const BBP As Long = 5
    
    Dim Status As Long
    Dim grossbuf As String, tarebuf As String, netbuf As String, unitbuf As String

    'Esses buffers DEVEM ser limpos antes da chamada da função ReadScale.
    grossbuf = String(9, Chr(0))
    tarebuf = String(9, Chr(0))
    netbuf = String(9, Chr(0))
    unitbuf = String(3, Chr(0))
     
    Status = ReadScale(hScale, BIDS, grossbuf, tarebuf, netbuf, unitbuf)
     
    Select Case Status
       Case ScaleError
         LabelError.Caption = "Erro de leitura da balança"
       Case ScaleOutOfRange
         LabelError.Caption = "Sobrecarga"
       Case ProteqNotFound
         LabelError.Caption = "Chave de licença não encontrada"
       Case ScaleInMotion
         LabelError.Caption = "Peso oscilando"
       Case ScaleStable
         LabelError.Caption = "Peso estável"
    End Select
     
    PBruto.Caption = grossbuf
    PTara.Caption = tarebuf
    PLiquido.Caption = netbuf
    PUnit.Caption = unitbuf
End Sub
