BlueTooth Connect Insecure

ItWorks

Member
Licensed User
Longtime User
Hi Guys/Gals,

I'm hoping someone can give me a pointer here about BlueTooth Connect Insecure. I have used Erels Serial/BlueTooth tutorial (thanks for that Erel - most informative) and got BlueTooth printing setup just fine. I wrote a general printer driver with suitable escape codes and I can print with no issues from my Android device, but when my app goes into the big wide world the users are going to want to connect printers I have never heard of and they will also want to use Insecure Pairings, as not everyone knows the PIN code for their printer. So I have been working on making my code as universal as I can.

Now I don't have any problem finding new printers (using BT Admin) and adding them to my list of available printers, but I do have a problem with ConnectInsecure, each time I try to use this command it STILL asks me for a PIN number, I thought that ConnectInsecure was just that and a PIN number was not needed, can someone explain to me why Android (3.2.1 in my case) is still asking for a pairing code.

Has anybody got a short few lines of code they are willing to share to show me how to use Connect Insecure to a printer without a pairing request from Android. I know for a phone or computer device connection you would want it paired but for printers it is not really required and Insecure will be adequate.

Thanks in advance for any help.

ItWorks
 

ItWorks

Member
Licensed User
Longtime User
Hi Guys,

Not to worry I have sorted it out.

I was getting confused with BlueTooth Admin and Pairing versus Serial Ports. (Need to oil my old brain with some more Red Wine !).

ConnectInsecure really has nothing to do with BlueTooth Admin, (Apart from using it to get the MAC address of the BlueTooth Device), once you have that you can forget about BT Admin and just use ConnectInsecure to open a Serial Port to the Device. I now have three different BT printers connected and I can choose between them at will as to which one is used for my printout.

Regards
ItWorks
 
Upvote 0

Pablo Torres

Active Member
Licensed User
Longtime User
Hi, I want to print some plain text on a printer, but I don't know how to do this, can you help me a little? Perhaps a few lines of your code that make it works? Thanks
 
Upvote 0

metzeller_2013

Member
Licensed User
Longtime User
Hi there ItWorks,
can you please share if you don't mind, your code on your general printer driver. I am currently having difficulties on my project regarding its printing capabilities. Hope you can help me. tnx
 
Upvote 0

Pablo Torres

Active Member
Licensed User
Longtime User
Sub ImprimirPedido

Dim EsteArticulo As ArtPedido

DateTime.DateFormat = "dd/MM/yy"
'Documento y Fecha
If cmbTipoVenta.SelectedIndex=0 Then
PrintBuffer= " " & Chr(13) & Chr(10) & " " & Chr(13) & Chr(10) &" " & Forma(1, 5, CStr(DateTime.Date(DateTime.Now)))&" "& Forma(1, 15, "CONTADO "& strSerie & CStr(intContadoActual)) & " " & Forma(1, 5, CStr(DateTime.Date(DateTime.Now)))&" "& Forma(1, 15, "CONTADO "& strSerie & CStr(intContadoActual))
Else
PrintBuffer= " " & Chr(13) & Chr(10) & " " & Chr(13) & Chr(10) &" " & Forma(1, 5, CStr(DateTime.Date(DateTime.Now)))&" "& Forma(1, 15, "CREDITO "& strSerie & CStr(intContadoActual)) & " " & Forma(1, 5, CStr(DateTime.Date(DateTime.Now)))&" "& Forma(1, 15, "CREDITO "& strSerie & CStr(intContadoActual))
End If
'RUT
PrintBuffer=PrintBuffer & Chr(13)&Chr(10)& " "
If ClienteActual.ObtenerRUTCliente.Length > 2 Then
PrintBuffer=PrintBuffer & Chr(13)&Chr(10)& " " & Forma(1,29,ClienteActual.ObtenerRUTCliente) & " " & ClienteActual.ObtenerRUTCliente
Else
PrintBuffer=PrintBuffer & Chr(13)&Chr(10)& " X X"
End If
'Cliente
PrintBuffer=PrintBuffer & Chr(13)&Chr(10)& "CLIENTE: " & Forma(1, 26, "(" & CStr(ClienteActual.ObtenerIdClienteCliente ) & ")" & " " & ClienteActual.ObtenerNombreCliente ) & " CLIENTE: " & Forma(1, 26, "(" & CStr(ClienteActual.ObtenerIdClienteCliente ) & ")" & " " & ClienteActual.ObtenerNombreCliente)
'Direccion
PrintBuffer=PrintBuffer & Chr(13)&Chr(10)& "DIRECCION: " & Forma(1, 25, CStr(ClienteActual.ObtenerDireccionCliente )) & " "& "DIRECCION: " & Forma(1, 25, CStr(ClienteActual.ObtenerDireccionCliente ))

PrintBuffer=PrintBuffer & Chr(13)&Chr(10)& " "

'Articulos
For I=1 To ArticulosPedido.Size
EsteArticulo = ArticulosPedido.Get(I-1)
'Cantidad, Detalle, Precio y Subtotal
PrintBuffer=PrintBuffer & Chr(13)&Chr(10)& Forma(2, 5, redondeo2(EsteArticulo_ObtenerCantidad,1)) & " " & Forma(1, 18, EsteArticulo_ObtenerDetalle ) & " " & Forma(2, 6, SinImpuestos(EsteArticulo_ObtenerPrecio , EsteArticulo_Obteneriva )) & Forma(2, 7, SinImpuestos(EsteArticulo_ObtenerCantidad*EsteArticulo_ObtenerPrecio , EsteArticulo_Obteneriva )) &" "&Forma(2, 5, redondeo2(EsteArticulo_ObtenerCantidad,1)) & " " & Forma(1, 18, EsteArticulo_ObtenerDetalle ) & " " & Forma(2, 6, SinImpuestos(EsteArticulo_ObtenerPrecio , EsteArticulo_Obteneriva )) & Forma(2, 7, SinImpuestos(EsteArticulo_ObtenerCantidad*EsteArticulo_ObtenerPrecio , EsteArticulo_ObtenerIVA ))
Next

For j = ArticulosPedido.Size To 12
PrintBuffer=PrintBuffer & Chr(13)&Chr(10)& " "
Next

'IVA BÁSICO
PrintBuffer=PrintBuffer & Chr(13)&Chr(10)& Forma(1, 2, CStr(IvaBasico)) & "% " & Forma(2, 9, "$" & CStr(Round2(ObtenerSubtotalBasico,1))) & " " & Forma(2, 8, "$" & CStr(Round2(ObtenerIvaBas,1))) & " " & Forma(2, 7, "$" & CStr(Round2(ObtenerSubtotalBasico + ObtenerSubtotalMinimo + ObtenerSubtotalExento,1))) & " " & Forma(1, 2, CStr(IvaBasico)) & "% " & Forma(2, 8, "$" & CStr(Round2(ObtenerSubtotalBasico,1))) & " " & Forma(2, 8, "$" & CStr(Round2(ObtenerIvaBas,1))) & " " & Forma(2, 9, "$" & CStr(Round2(ObtenerSubtotalBasico + ObtenerSubtotalMinimo + ObtenerSubtotalExento,1)))
'IVA Mínimo
PrintBuffer=PrintBuffer & Chr(13)&Chr(10)& Forma(1, 2, CStr(IvaMinimo)) & "% " & Forma(2, 9, "$" & CStr(Round2(ObtenerSubtotalMinimo,1))) & " " & Forma(2, 8, "$" & CStr(Round2(ObtenerIvaMin,1))) & " " & Forma(2, 7, "$" & CStr(Round2(ObtenerIvaMin + ObtenerIvaBas,1))) & " " & Forma(1, 2, CStr(IvaMinimo)) & "% " & Forma(2, 8, "$" & CStr(Round2(ObtenerSubtotalMinimo,1))) & " " & Forma(2, 8, "$" & CStr(Round2(ObtenerIvaMin,1))) & " " & Forma(2, 9, "$" & CStr(Round2(ObtenerIvaMin + ObtenerIvaBas,1)))
'IVA EXENTO
PrintBuffer=PrintBuffer & Chr(13)&Chr(10)& " 0% " & Forma(2, 9, "$" & ObtenerSubtotalExento) & " $0 " & Forma(2, 9, "$" & CStr(Round(ObtenerValorVenta))) & " 0% " & Forma(2, 9, "$" & ObtenerSubtotalExento) & " $0 " & Forma(2, 9, "$" & CStr(Round(ObtenerValorVenta)))

StartPrinter
End Sub


Sub Printer_Connected (Success As Boolean)
If Success Then
printer.Initialize(cmp20.OutputStream)
printer.Write(PrintBuffer)
printer.Flush
printer.Write (" ")
printer.WriteLine (" ")
PrintBuffer=""
Msgbox("Proceso de Impresión realizado","")
printer.Close
cmp20.Disconnect
Else
If Msgbox2("", "Error de Impresión","Reintentar","Cancelar","",Null) = DialogResponse.POSITIVE Then
StartPrinter
End If
End If
End Sub

Sub StartPrinter
Dim PairedDevices As Map

PairedDevices.Initialize

Try
PairedDevices = cmp20.GetPairedDevices
Catch
Msgbox("Imposible conectar Bluetooth","Error de Impresión")
printer.Close
cmp20.Disconnect
End Try

If PairedDevices.Size = 0 Then
Return
Else
cmp20.Connect(DirMac)
End If

End Sub
 
Upvote 0
Top