Android Question How can I get the Mac address from the Pairdevices

Discussion in 'Android Questions' started by davepamn, May 21, 2015.

  1. davepamn

    davepamn Active Member Licensed User

    Code:
    sub Process_Globals
    private printer_serial1 as serial
    end sub

    Sub Globals

        
    Private printer_foundDevices As List
        
    Private printer_admin As BluetoothAdmin
        
    Private printer_Writer As TextWriter
    end sub

        printer_admin.Initialize(
    "PrinterAdmin")

        printer_foundDevices.Clear

        
    If printer_serial1.IsInitialized=False Then
                printer_serial1.Initialize(
    "PrinterSerial")

         
    End If

            PairedDevices=printer_serial1.GetPairedDevices

            
    If PairedDevices.size=0 Then

                
    If printer_admin.StartDiscovery    = False Then

                    
    ToastMessageShow("Error starting discovery process."True)

                
    Else

                    
    ProgressDialogShow("Searching for devices...")

                
    End If

            
    Else

                    
    Dim oPDList As List
                    oPDList.Initialize
                    
    Dim nm As NameAndMac

                    
    If nm.IsInitialized=False Then
                     nm.Initialize
                   
    End If

                    
    For i =0 To PairedDevices.Size-1
                       oPDList.Add(PairedDevices.GetKeyAt(i))
                   
    Next

                
    For i =0 To oPDList.size-1

                    nm=oPDList.Get(i) 
    '//why doesn't this assignment give me the name and mac address

                    
    'If nm.Name="GD200P" Then

                        printer_serial1.Connect(PairedDevices.Get(oPDList.get(
    0)))

                        SendTextToPrinter

                    
    'End If

                
    Next

            
    End If
    Sub SendTextToPrinter

    Try

        printer_Writer.Initialize(printer_serial1.OutputStream) 
    '//Crashes with a null pointer

        printer_Writer.WriteLine(
    "Hello World")

        printer_Writer.Flush

        printer_Writer.Close

        printer_serial1.Disconnect

    Catch

        oError.ShowLastException(
    "Error : SendTextToPrinter")

    EndTry



    End Sub
    I want to find a Printer by Name and connect its mac address. The NameAndMac assignment is not working correctly.
     
    Last edited: May 21, 2015
  2. davepamn

    davepamn Active Member Licensed User

    the printer_serial1 is showing a Mac address in the watch. Why does the text write not properly initialize using the output stream?
     
  3. davepamn

    davepamn Active Member Licensed User

    Code:
    If printer_AStream.IsInitialized = False Then

            printer_AStream.InitializePrefix(printer_serial1.InputStream, 
    True, printer_serial1.OutputStream, "PrinterAStream")

        EndIf

        
    Dim buffer() As Byte

        buffer=
    "Hello World".GetBytes("UTF8")

        printer_AStream.Write(buffer)

        
    Log("Send data to printer")
    I converted the TextWriter Code to asychronous stream as recommended in other posts. The code did not crash.
     
  4. davepamn

    davepamn Active Member Licensed User

    Code:
    printer_AStream.InitializePrefix(printer_serial1.InputStream, True, printer_serial1.OutputStream, "PrinterAStream")
    I get an Null Pointer exception on this line of code.
     
  5. Erel

    Erel Administrator Staff Member Licensed User

    Please start a new thread for a new question.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice