Imports CesnaActiveX
Public Class Form1
    Dim WithEvents MyCesna As New CesnaActiveX.Cesna

    'Estados das Bombas
    Public Const ESTADO_INDEFINIDO As Byte = 1
    Public Const BOMBA_PRONTA As Byte = 2
    Public Const BOMBA_PEDE_AUTORIZACAO As Byte = 3
    Public Const BOMBA_AGUARDANDO_CARTAO As Byte = 4
    Public Const BOMBA_LIBERADA As Byte = 5
    Public Const BOMBA_ABASTECENDO As Byte = 6
    Public Const BOMBA_ABASTECEU As Byte = 7
    Public Const BOMBA_TROCOU_PRECO_POR_LITRO As Byte = 8
    Public Const BOMBA_RESERVADA_PRE_PAGO As Byte = 9
    Public Const BOMBA_BLOQUEADA As Byte = 10
    Public Const BOMBA_DESBLOQUEADA As Byte = 11
    Public Const BOMBA_INFORMOU_FALHA As Byte = 12
    Public Const BOMBA_NAO_RESPONDE As Byte = 13

    'Estados do Concentrador
    Public Const CONCENTRADOR_INFORMOU_VERSAO As Byte = 14
    Public Const CONCENTRADOR_ACEITOU_CONFIGURACAO As Byte = 15
    Public Const FALHA_COMUNICACAO_CONCENTRADOR As Byte = 16
    Public Const CONCENTRADOR_INFORMOU_EVENTO As Byte = 17
    Public Const RESET_CONCENTRADOR As Byte = 18
    Public Const EVENTO_RETORNO_ESPECIAL As Byte = 19
    Public Const RETORNO_ABAST_FLASH As Byte = 20
    Public Const MAB_RESPONDEU_ACK As Byte = 21
    Public Const MAB_TIMEOUT_ACK As Byte = 22

    Public Sub Imprime(ByVal Texto As String)

        If (RchTxtBoxDisplay.Lines.Count > 999) Then
            RchTxtBoxDisplay.Clear()
        End If

        RchTxtBoxDisplay.Text = RchTxtBoxDisplay.Text & Format(RchTxtBoxDisplay.Lines.Count(), "0000: ") & Texto & Chr(13) & Chr(10)

        RchTxtBoxDisplay.SelectionStart = RchTxtBoxDisplay.TextLength
        RchTxtBoxDisplay.ScrollToCaret()

    End Sub
    Public Sub ObtemEnderecos(ByRef EndMab As Byte, ByRef EndBomba As Byte, ByRef EndBico As Byte)
        EndMab = Convert.ToByte(CmbBoxEndMab.SelectedIndex + 1)
        EndBomba = Convert.ToByte(CmbBoxEndBomba.SelectedIndex + 1)
        EndBico = Convert.ToByte(CmbBoxEndBico.SelectedIndex + 1)
    End Sub

    Private Sub BtnOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnOpen.Click
        Dim Retorno As Integer

        Retorno = MyCesna.IdCodeOpen(1)
        If Retorno = 1 Then
            Imprime("Open: Ok")
        Else
            Imprime("Open: Erro " + Retorno.ToString())
        End If
    End Sub
    Private Sub BtnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnClose.Click
        Dim Retorno As Integer
        Retorno = MyCesna.IdCodeClose()
        If Retorno = 1 Then
            Imprime("Close: Ok")
        Else
            Imprime("Close: Erro " + Retorno.ToString())
        End If
    End Sub
    Private Sub BtnVersaoDll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnVersaoDll.Click
        Dim Retorno As Integer
        Retorno = MyCesna.IdCodeVersaoDll()
        Imprime("Versão Dll: " + Retorno.ToString())
    End Sub
    Private Sub BtnConfiguraMab_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnConfiguraMab.Click
        Dim Retorno As Integer
        Dim Mab As Byte
        Dim NumeroBombas As Byte
        Dim TipoBomba As Byte
        Dim ModoOperacao As Byte

        Mab = Convert.ToByte(CmbBoxMab.SelectedIndex + 1)
        NumeroBombas = Convert.ToByte(CmbBoxBomba.SelectedIndex + 1)
        TipoBomba = Convert.ToByte(CmbBoxTipoBomba.SelectedIndex + 1)
        ModoOperacao = Convert.ToByte(CmbBoxModoOperacao.SelectedIndex + 10) 'Somado mais 10 para acertar o caracter depois da conversão para hexadecimal: 0x0A, 0x0B ou 0x0C

        Retorno = MyCesna.IdCodeConfiguraMab(Mab, NumeroBombas, TipoBomba, ModoOperacao)
        If Retorno = 1 Then
            Imprime("Configura MAB: Ok")
        Else
            Imprime("Configura MAB: Erro " + Retorno.ToString())
        End If
    End Sub
    Private Sub BtnObtemConfiguracaoMab_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnObtemConfiguracaoMab.Click
        Dim Retorno As Integer
        Dim Mab As Byte

        Mab = Convert.ToByte(CmbBoxMab.SelectedIndex + 1)
        Retorno = MyCesna.IdCodeObtemConfiguracaoMab(Mab)
        If Retorno <> 1 Then
            Imprime("Obtém Configuração MAB: Erro " + Retorno.ToString())
        End If
    End Sub
    Private Sub BtnNumAbastOffline_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnNumAbastOffline.Click
        Dim Retorno As Integer
        Dim Mab As Byte

        Mab = Convert.ToByte(CmbBoxMab.SelectedIndex + 1)
        Retorno = MyCesna.IdCodeObtemNumAbastOff(Mab)
        If Retorno <> 1 Then
            Imprime("Obtém Número Abastecimentos Off-line: Erro " + Retorno.ToString())
        End If
    End Sub
    Private Sub BtnEstado_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnEstado.Click
        Dim Retorno As Integer
        Dim Mab As Byte
        Dim Bomba As Byte

        ObtemEnderecos(Mab, Bomba, 0)
        If ChkBoxTodasBombas.Checked = True Then
            Retorno = MyCesna.IdCodeObtemStatusBomba(Mab, 0)
        Else
            Retorno = MyCesna.IdCodeObtemStatusBomba(Mab, Bomba)
        End If

        If Retorno <> 1 Then
            Imprime("Obtém Estado: Erro" + Retorno.ToString())
        End If
    End Sub
    Private Sub BtnTotalizador_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnTotalizador.Click
        Dim Retorno As Integer
        Dim Mab As Byte
        Dim Bomba As Byte
        Dim Bico As Byte

        ObtemEnderecos(Mab, Bomba, Bico)
        Retorno = MyCesna.IdCodeObtemTotalizador(Mab, Bomba, Bico)
        If Retorno <> 1 Then
            Imprime("Obtém Totalizador: Erro " + Retorno.ToString())
        End If
    End Sub
    Private Sub BtnUltimoVolume_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnUltimoVolume.Click
        Dim Retorno As Integer
        Dim Mab As Byte
        Dim Bomba As Byte
        Dim Bico As Byte

        ObtemEnderecos(Mab, Bomba, Bico)
        Retorno = MyCesna.IdCodeObtemUltimoVolume(Mab, Bomba, Bico)
        If Retorno <> 1 Then
            Imprime("Último Volume: Erro " + Retorno.ToString())
        End If
    End Sub
    Private Sub BtnObtemPreco_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnObtemPreco.Click
        Dim Retorno As Integer
        Dim Mab As Byte
        Dim Bomba As Byte
        Dim Bico As Byte

        ObtemEnderecos(Mab, Bomba, Bico)
        Retorno = MyCesna.IdCodeObtemPrecoPorLitro(Mab, Bomba, Bico)
        If Retorno <> 1 Then
            Imprime("Preço Por Litro: Erro " + Retorno.ToString())
        End If
    End Sub
    Private Sub BtnTravaBomba_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnTravaBomba.Click
        Dim Retorno As Integer
        Dim Mab As Byte
        Dim Bomba As Byte
        Dim Bico As Byte

        ObtemEnderecos(Mab, Bomba, Bico)
        Retorno = MyCesna.IdCodeTravaBomba(Mab, Bomba, Bico)
        If Retorno <> 1 Then
            Imprime("Trava bomba: " + Retorno.ToString())
        End If
    End Sub
    Private Sub BtnDestravaBomba_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnDestravaBomba.Click
        Dim Retorno As Integer
        Dim Mab As Byte
        Dim Bomba As Byte
        Dim Bico As Byte

        ObtemEnderecos(Mab, Bomba, Bico)
        Retorno = MyCesna.IdCodeDestravaBomba(Mab, Bomba, Bico)
        If Retorno <> 1 Then
            Imprime("Destrava bomba: " + Retorno.ToString())
        End If
    End Sub
    Private Sub BtnAutorizaBomba_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnAutorizaBomba.Click
        Dim Retorno As Integer
        Dim Mab As Byte
        Dim Bomba As Byte
        Dim Bico As Byte

        ObtemEnderecos(Mab, Bomba, Bico)
        Retorno = MyCesna.IdCodeAutorizaAbastecimento(Mab, Bomba, Bico)
        If Retorno <> 1 Then
            Imprime("Autoriza Abastecimento: Erro " + Retorno.ToString())
        End If
    End Sub
    Private Sub BtnPrePago_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnPrePago.Click
        Dim Retorno As Integer
        Dim Mab As Byte
        Dim Bomba As Byte
        Dim Bico As Byte
        Dim Volume As Integer
        Dim Aux As String

        ObtemEnderecos(Mab, Bomba, Bico)
   
        Aux = MskBoxPrePago.Text
        Aux = Replace(Aux, ",", "") 'Remove a virgula para passar o valor como inteiro
        Volume = Convert.ToInt32(Aux)

        Retorno = MyCesna.IdCodeSetaPrePago(Mab, Bomba, Bico, Volume, 3)    'Número de casas decimais fixado como 3
        If Retorno <> 1 Then
            Imprime("Pré-pago: Erro " + Retorno.ToString())
        End If
    End Sub
    Private Sub BtnTrocaPreco_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnTrocaPreco.Click
        Dim Retorno As Integer
        Dim Mab As Byte
        Dim Bomba As Byte
        Dim Bico As Byte
        Dim Preco As Integer
        Dim Aux As String

        ObtemEnderecos(Mab, Bomba, Bico)
        Aux = MskBoxTrocaPreco.Text
        Aux = Replace(Aux, ",", "")
        Preco = Convert.ToInt32(Aux)

        Retorno = MyCesna.IdCodeTrocaPrecoPorLitro(Mab, Bomba, Bico, Preco, 3) 'Número de casas decimais fixado como 3
        If Retorno <> 1 Then
            Imprime("Troca Preço: Erro " + Retorno.ToString())
        End If
    End Sub
    Sub MyCesna_IdCodeMudancaDeEstado(ByVal Mab As Byte, ByVal Bomba As Byte, ByVal Bico As Byte, ByVal Estado As Byte) Handles MyCesna.IdCodeMudancaDeEstado
        Select Case Estado
            Case ESTADO_INDEFINIDO
                Imprime("Mab: " + Convert.ToString(Mab) + " Bo: " + Convert.ToString(Bomba) + " Bi: " + Convert.ToString(Bico) + " - ESTADO_INDEFINIDO")
            Case BOMBA_PRONTA
                Imprime("Mab: " + Convert.ToString(Mab) + " Bo: " + Convert.ToString(Bomba) + " Bi: " + Convert.ToString(Bico) + " - BOMBA_PRONTA")
            Case BOMBA_PEDE_AUTORIZACAO
                Imprime("Mab: " + Convert.ToString(Mab) + " Bo: " + Convert.ToString(Bomba) + " Bi: " + Convert.ToString(Bico) + " - BOMBA_PEDE_AUTORIZACAO")
            Case BOMBA_AGUARDANDO_CARTAO
                Imprime("Mab: " + Convert.ToString(Mab) + " Bo: " + Convert.ToString(Bomba) + " Bi: " + Convert.ToString(Bico) + " - BOMBA_AGUARDANDO_CARTAO")
            Case BOMBA_LIBERADA
                Imprime("Mab: " + Convert.ToString(Mab) + " Bo: " + Convert.ToString(Bomba) + " Bi: " + Convert.ToString(Bico) + " - BOMBA_LIBERADA")
            Case BOMBA_ABASTECENDO
                Imprime("Mab: " + Convert.ToString(Mab) + " Bo: " + Convert.ToString(Bomba) + " Bi: " + Convert.ToString(Bico) + " - BOMBA_ABASTECENDO")
            Case BOMBA_ABASTECEU
                Imprime("Mab: " + Convert.ToString(Mab) + " Bo: " + Convert.ToString(Bomba) + " Bi: " + Convert.ToString(Bico) + " - BOMBA_ABASTECEU")
            Case BOMBA_TROCOU_PRECO_POR_LITRO
                Imprime("Mab: " + Convert.ToString(Mab) + " Bo: " + Convert.ToString(Bomba) + " Bi: " + Convert.ToString(Bico) + " - BOMBA_TROCOU_PRECO_POR_LITRO")
            Case BOMBA_RESERVADA_PRE_PAGO
                Imprime("Mab: " + Convert.ToString(Mab) + " Bo: " + Convert.ToString(Bomba) + " Bi: " + Convert.ToString(Bico) + " - BOMBA_RESERVADA_PRE_PAGO")
            Case BOMBA_BLOQUEADA
                Imprime("Mab: " + Convert.ToString(Mab) + " Bo: " + Convert.ToString(Bomba) + " Bi: " + Convert.ToString(Bico) + " - BOMBA_BLOQUEADA")
            Case BOMBA_DESBLOQUEADA
                Imprime("Mab: " + Convert.ToString(Mab) + " Bo: " + Convert.ToString(Bomba) + " Bi: " + Convert.ToString(Bico) + " - BOMBA_DESBLOQUEADA")
            Case BOMBA_INFORMOU_FALHA
                Imprime("Mab: " + Convert.ToString(Mab) + " Bo: " + Convert.ToString(Bomba) + " Bi: " + Convert.ToString(Bico) + " - BOMBA_INFORMOU_FALHA")
            Case BOMBA_NAO_RESPONDE
                Imprime("Mab: " + Convert.ToString(Mab) + " Bo: " + Convert.ToString(Bomba) + " Bi: " + Convert.ToString(Bico) + " - BOMBA_NAO_RESPONDE")
            Case CONCENTRADOR_ACEITOU_CONFIGURACAO
                Imprime("Mab: " + Convert.ToString(Mab) + " Bo: " + Convert.ToString(Bomba) + " Bi: " + Convert.ToString(Bico) + " - CONCENTRADOR_ACEITOU_CONFIGURACAO")
            Case FALHA_COMUNICACAO_CONCENTRADOR
                Imprime("Mab: " + Convert.ToString(Mab) + " Bo: " + Convert.ToString(Bomba) + " Bi: " + Convert.ToString(Bico) + " - FALHA_COMUNICACAO_CONCENTRADOR")
            Case RETORNO_ABAST_FLASH
                Imprime("Mab: " + Convert.ToString(Mab) + " Bo: " + Convert.ToString(Bomba) + " Bi: " + Convert.ToString(Bico) + " - RETORNO_ABAST_FLASH")
        End Select

    End Sub
    Sub MyCesna_IdCodeAbasteceu(ByVal Mab As Byte, ByVal Bomba As Byte, ByVal Bico As Byte, ByVal Volume As Integer, ByVal VolumeCasaDecimal As Byte,
                                ByVal TotalInicial As Integer, ByVal TotalInicialCasaDecimal As Byte, ByVal TotalFinal As Integer, ByVal TotalFinalCasaDecimal As Byte,
                                ByVal PrecoPorLitro As Integer, ByVal PrecoPorLitroCasaDecimal As Byte, ByVal Data As Integer, ByVal Hora As Integer,
                                ByVal TagFrentista As String, ByVal TagCliente As String, ByVal FlagAbastecimento As Byte, ByVal NumeroAbastecimento As Integer) Handles MyCesna.IdCodeAbasteceu
        Dim VolumeAbast As String
        Dim PrecoAbast As String
        Dim TotalIniAbast As String
        Dim TotalFinAbast As String
        Dim DataAbast As String
        Dim HoraAbast As String


        Select Case VolumeCasaDecimal
            Case 0
                VolumeAbast = Volume.ToString("0.0")
            Case 1
                VolumeAbast = (Volume / 10).ToString("0.0")
            Case 2
                VolumeAbast = (Volume / 100).ToString("0.00")
            Case 3
                VolumeAbast = (Volume / 1000).ToString("0.000")
            Case Else
                VolumeAbast = Volume.ToString("0.0")
        End Select

        Select Case TotalInicialCasaDecimal
            Case 0
                TotalIniAbast = TotalInicial.ToString("0.0")
            Case 1
                TotalIniAbast = (TotalInicial / 10).ToString("0.0")
            Case 2
                TotalIniAbast = (TotalInicial / 100).ToString("0.00")
            Case 3
                TotalIniAbast = (TotalInicial / 1000).ToString("0.000")
            Case Else
                TotalIniAbast = TotalInicial.ToString("0.0")
        End Select

        Select Case TotalFinalCasaDecimal
            Case 0
                TotalFinAbast = TotalFinal.ToString("0.0")
            Case 1
                TotalFinAbast = (TotalFinal / 10).ToString("0.0")
            Case 2
                TotalFinAbast = (TotalFinal / 100).ToString("0.00")
            Case 3
                TotalFinAbast = (TotalFinal / 1000).ToString("0.000")
            Case Else
                TotalFinAbast = TotalFinal.ToString("0.0")
        End Select

        Select Case PrecoPorLitroCasaDecimal
            Case 0
                PrecoAbast = PrecoPorLitro.ToString("0.0")
            Case 1
                PrecoAbast = (PrecoPorLitro / 10).ToString("0.0")
            Case 2
                PrecoAbast = (PrecoPorLitro / 100).ToString("0.00")
            Case 3
                PrecoAbast = (PrecoPorLitro / 1000).ToString("0.000")
            Case Else
                PrecoAbast = PrecoPorLitro.ToString("0.0")
        End Select

        DataAbast = Convert.ToString(Data)
        If DataAbast.Length < 6 Then
            DataAbast = "0" + DataAbast
        End If
        DataAbast = DataAbast.Substring(0, 2) + "/" + DataAbast.Substring(2, 2) + "/" + DataAbast.Substring(4, 2)

        HoraAbast = Convert.ToString(Hora)
        Select Case HoraAbast.Length
            Case 1
                HoraAbast = "00000" + HoraAbast
                HoraAbast = HoraAbast.Substring(0, 2) + ":" + HoraAbast.Substring(2, 2) + ":" + HoraAbast.Substring(4, 2)
            Case 2
                HoraAbast = "0000" + HoraAbast
                HoraAbast = HoraAbast.Substring(0, 2) + ":" + HoraAbast.Substring(2, 2) + ":" + HoraAbast.Substring(4, 2)
            Case 3
                HoraAbast = "000" + HoraAbast
                HoraAbast = HoraAbast.Substring(0, 2) + ":" + HoraAbast.Substring(2, 2) + ":" + HoraAbast.Substring(4, 2)
            Case 4
                HoraAbast = "00" + HoraAbast
                HoraAbast = HoraAbast.Substring(0, 2) + ":" + HoraAbast.Substring(2, 2) + ":" + HoraAbast.Substring(4, 2)
            Case 5
                HoraAbast = "0" + HoraAbast
                HoraAbast = HoraAbast.Substring(0, 2) + ":" + HoraAbast.Substring(2, 2) + ":" + HoraAbast.Substring(4, 2)
            Case Else
                HoraAbast = HoraAbast.Substring(0, 2) + ":" + HoraAbast.Substring(2, 2) + ":" + HoraAbast.Substring(4, 2)
        End Select

        Imprime("Total Inicia: " + TotalIniAbast)
        Imprime("Total Final: " + TotalFinAbast)
        Imprime("Volume: " + VolumeAbast)
        Imprime("Preço Por Litro: " + PrecoAbast)
        Imprime("Data: " + DataAbast)
        Imprime("Hora: " + HoraAbast)
        Imprime("Tag Frentista: " + TagFrentista)
        Imprime("Tag Cliente: " + TagCliente)
        Imprime("Número do Abastecimento: " + Convert.ToString(NumeroAbastecimento))

        If FlagAbastecimento = 0 Then
            Imprime("Abastecimento: On-line")
        Else
            Imprime("Abastecimento: Off-line")
        End If


    End Sub
    Sub MyCesna_IdCodeConfigMab(ByVal Mab As Byte, ByVal NumeroBombas As Byte, ByVal ModoOperacao As Byte, ByVal TipoBomba As Byte) Handles MyCesna.IdCodeConfigMab
        Imprime("Mab: " + Convert.ToString(Mab) + " NumBo: " + Convert.ToString(NumeroBombas) + " ModoOp: " + Convert.ToChar(ModoOperacao) + " TipoBo: " + Convert.ToString(TipoBomba))
        'Os códigos para os tipos de bombas encontram-se no manual Desenvolvedores IDcode
    End Sub
    Sub MyCesna_IdCodeNumAbastOff(ByVal Mab As Byte, ByVal NumeroAbastecimentosOffline As Integer) Handles MyCesna.IdCodeNumAbastOff
        Imprime("Mab: " + Convert.ToString(Mab) + " Número Abastecimentos Offline: " + Convert.ToString(NumeroAbastecimentosOffline))
    End Sub
    Sub MyCesna_IdCodeTotalizador(ByVal Mab As Byte, ByVal Bomba As Byte, ByVal Bico As Byte, ByVal Totalizador As Integer, ByVal TotalizadorCasaDecimal As Byte) Handles MyCesna.IdCodeTotalizador
        Dim Total As String

        Select Case TotalizadorCasaDecimal
            Case 0
                Total = Totalizador.ToString("0.0")
            Case 1
                Total = (Totalizador / 10).ToString("0.0")
            Case 2
                Total = (Totalizador / 100).ToString("0.00")
            Case 3
                Total = (Totalizador / 1000).ToString("0.000")
            Case Else
                Total = Totalizador.ToString("0.0")
        End Select

        Imprime("Mab: " + Convert.ToString(Mab) + " Bo: " + Convert.ToString(Bomba) + " Bi: " + Convert.ToString(Bico) + " Totalizador: " + Total)
    End Sub
    Sub MyCesna_IdCodeVolume(ByVal Mab As Byte, ByVal Bomba As Byte, ByVal Bico As Byte, ByVal Volume As Integer, ByVal VolumeCasaDecimal As Byte) Handles MyCesna.IdCodeVolume
        Dim Vol As String

        Select Case VolumeCasaDecimal
            Case 0
                Vol = Volume.ToString("0.0")
            Case 1
                Vol = (Volume / 10).ToString("0.0")
            Case 2
                Vol = (Volume / 100).ToString("0.00")
            Case 3
                Vol = (Volume / 1000).ToString("0.000")
            Case Else
                Vol = Volume.ToString("0.0")
        End Select

        Imprime("Mab: " + Convert.ToString(Mab) + " Bo: " + Convert.ToString(Bomba) + " Bi: " + Convert.ToString(Bico) + " Último Volume: " + Vol)
    End Sub
    Sub MyCesna_IdCodePrecoPorLitro(ByVal Mab As Byte, ByVal Bomba As Byte, ByVal Bico As Byte, ByVal PrecoPorLitro As Integer, ByVal PrecoPorLitroCasaDecimal As Byte) Handles MyCesna.IdCodePrecoPorLitro
        Dim Preco As String

        Select Case PrecoPorLitroCasaDecimal
            Case 0
                Preco = PrecoPorLitro.ToString("0.0")
            Case 1
                Preco = (PrecoPorLitro / 10).ToString("0.0")
            Case 2
                Preco = (PrecoPorLitro / 100).ToString("0.00")
            Case 3
                Preco = (PrecoPorLitro / 1000).ToString("0.000")
            Case Else
                Preco = PrecoPorLitro.ToString("0.0")
        End Select

        Imprime("Mab: " + Convert.ToString(Mab) + " Bo: " + Convert.ToString(Bomba) + " Bi: " + Convert.ToString(Bico) + " Preço: " + Preco)
    End Sub
    Sub MyCesna_IdCodeValorBombaAbast(ByVal Mab As Byte, ByVal Bomba As Byte, ByVal Bico As Byte, ByVal Valor As Integer, ByVal ValorCasaDecimal As Byte) Handles MyCesna.IdCodeValorBombaAbast
        Dim Val As String

        Select Case ValorCasaDecimal
            Case 0
                Val = Valor.ToString("0.0")
            Case 1
                Val = (Valor / 10).ToString("0.0")
            Case 2
                Val = (Valor / 100).ToString("0.00")
            Case 3
                Val = (Valor / 1000).ToString("0.000")
            Case Else
                Val = Valor.ToString("0.0")
        End Select

        Imprime("Mab: " + Convert.ToString(Mab) + " Bo: " + Convert.ToString(Bomba) + " Bi: " + Convert.ToString(Bico) + " Valor do Abastecimento: " + Valor)
    End Sub
    Sub MyCesna_IdCodeInfoEvento(ByVal Mab As Byte, ByVal Bomba As Byte, ByVal Bico As Byte, ByVal Evento As Byte) Handles MyCesna.IdCodeInfoEvento
        Imprime("Mab: " + Convert.ToString(Mab) + " Bo: " + Convert.ToString(Bomba) + " Bi: " + Convert.ToString(Bico) + " Evento: " + Convert.ToString(Evento))
    End Sub
    Sub MyCesna_IdCodeErroCrcTab(ByVal Mab As Byte, ByVal Crc As Integer) Handles MyCesna.IdCodeErroCrcTab
        Imprime("Mab: " + Convert.ToString(Mab) + " Erro CRC: " + Convert.ToString(Crc))
    End Sub

    Sub MyCesna_IdCodeRetornoAbatFlash(ByVal Mab As Byte, ByVal Bomba As Byte, ByVal Bico As Byte, ByVal Volume As Integer, ByVal VolumeCasaDecimal As Byte,
                                        ByVal TotalInicial As Integer, ByVal TotalInicialCasaDecimal As Byte, ByVal TotalFinal As Integer, ByVal TotalFinalCasaDecimal As Byte,
                                        ByVal PrecoPorLitro As Integer, ByVal PrecoPorLitroCasaDecimal As Byte, ByVal Data As Integer, ByVal Hora As Integer,
                                        ByVal TagFrentista As String, ByVal TagCliente As String, ByVal FlagAbastecimento As Byte, ByVal NumeroAbastecimento As Integer) Handles MyCesna.IdCodeRetornoAbatFlash
        Dim VolumeAbast As String
        Dim PrecoAbast As String
        Dim TotalIniAbast As String
        Dim TotalFinAbast As String
        Dim DataAbast As String
        Dim HoraAbast As String


        Select Case VolumeCasaDecimal
            Case 0
                VolumeAbast = Volume.ToString("0.0")
            Case 1
                VolumeAbast = (Volume / 10).ToString("0.0")
            Case 2
                VolumeAbast = (Volume / 100).ToString("0.00")
            Case 3
                VolumeAbast = (Volume / 1000).ToString("0.000")
            Case Else
                VolumeAbast = Volume.ToString("0.0")
        End Select

        Select Case TotalInicialCasaDecimal
            Case 0
                TotalIniAbast = TotalInicial.ToString("0.0")
            Case 1
                TotalIniAbast = (TotalInicial / 10).ToString("0.0")
            Case 2
                TotalIniAbast = (TotalInicial / 100).ToString("0.00")
            Case 3
                TotalIniAbast = (TotalInicial / 1000).ToString("0.000")
            Case Else
                TotalIniAbast = TotalInicial.ToString("0.0")
        End Select

        Select Case TotalFinalCasaDecimal
            Case 0
                TotalFinAbast = TotalFinal.ToString("0.0")
            Case 1
                TotalFinAbast = (TotalFinal / 10).ToString("0.0")
            Case 2
                TotalFinAbast = (TotalFinal / 100).ToString("0.00")
            Case 3
                TotalFinAbast = (TotalFinal / 1000).ToString("0.000")
            Case Else
                TotalFinAbast = TotalFinal.ToString("0.0")
        End Select

        Select Case PrecoPorLitroCasaDecimal
            Case 0
                PrecoAbast = PrecoPorLitro.ToString("0.0")
            Case 1
                PrecoAbast = (PrecoPorLitro / 10).ToString("0.0")
            Case 2
                PrecoAbast = (PrecoPorLitro / 100).ToString("0.00")
            Case 3
                PrecoAbast = (PrecoPorLitro / 1000).ToString("0.000")
            Case Else
                PrecoAbast = PrecoPorLitro.ToString("0.0")
        End Select

        DataAbast = Convert.ToString(Data)
        If DataAbast.Length < 6 Then
            DataAbast = "0" + DataAbast
        End If
        DataAbast = DataAbast.Substring(0, 2) + "/" + DataAbast.Substring(2, 2) + "/" + DataAbast.Substring(4, 2)

        HoraAbast = Convert.ToString(Hora)
        Select Case HoraAbast.Length
            Case 1
                HoraAbast = "00000" + HoraAbast
                HoraAbast = HoraAbast.Substring(0, 2) + ":" + HoraAbast.Substring(2, 2) + ":" + HoraAbast.Substring(4, 2)
            Case 2
                HoraAbast = "0000" + HoraAbast
                HoraAbast = HoraAbast.Substring(0, 2) + ":" + HoraAbast.Substring(2, 2) + ":" + HoraAbast.Substring(4, 2)
            Case 3
                HoraAbast = "000" + HoraAbast
                HoraAbast = HoraAbast.Substring(0, 2) + ":" + HoraAbast.Substring(2, 2) + ":" + HoraAbast.Substring(4, 2)
            Case 4
                HoraAbast = "00" + HoraAbast
                HoraAbast = HoraAbast.Substring(0, 2) + ":" + HoraAbast.Substring(2, 2) + ":" + HoraAbast.Substring(4, 2)
            Case 5
                HoraAbast = "0" + HoraAbast
                HoraAbast = HoraAbast.Substring(0, 2) + ":" + HoraAbast.Substring(2, 2) + ":" + HoraAbast.Substring(4, 2)
            Case Else
                HoraAbast = HoraAbast.Substring(0, 2) + ":" + HoraAbast.Substring(2, 2) + ":" + HoraAbast.Substring(4, 2)
        End Select

        Imprime("Total Inicia: " + TotalIniAbast)
        Imprime("Total Final: " + TotalFinAbast)
        Imprime("Volume: " + VolumeAbast)
        Imprime("Preço Por Litro: " + PrecoAbast)
        Imprime("Data: " + DataAbast)
        Imprime("Hora: " + HoraAbast)
        Imprime("Tag Frentista: " + TagFrentista)
        Imprime("Tag Cliente: " + TagCliente)
        Imprime("Número do Abastecimento: " + Convert.ToString(NumeroAbastecimento))

        If FlagAbastecimento = 0 Then
            Imprime("Abastecimento: On-line")
        Else
            Imprime("Abastecimento: Off-line")
        End If

    End Sub

End Class


