Problem with serial port (Bluetooth)

uskomp

Member
Licensed User
Longtime User
1) How to send text to printer by using Bluetooth?
I connected with method Serial1.Connect3(BtAdr, 1) only.
Another COMMs 0,2,3,4,5,6,7 and Serial1.Connect(BtAdr) => "BT - not ready" .
Sub Serial1_Connected (Success As Boolean)
Dim tw2 As TextWriter
If Success Then :ToastMessageShow("Bluetooth OK",false)
tw2.Initialize(Serial1.OutputStream)
tw2.Write("Line first" & Chr(13) & Chr(10))
tw2.Flush :tw2.close
serial1.Disconnect
Else :ToastMessageShow("BT - not ready",false)
End If
End Sub
I see info "Bluetooth OK" on display but printer doesn't print.
On Windows Mobile during paring BT device I have to mark in "advanced options" a checkbox "serial port".
My application works fine at WM.
At the android during paring BT device there are not "advanced options" but it has "FTP service" which doesn't work with printers.
I have tested "Bluetooth File Transfer" application from Android Market but it still hasn't helped (no transfer to printer).

2) How to send array of bytes to serial port (Bluetoth)?
Dim mybuff() as Byte
str = File.ReadString(MyDir, "print.txt")
mybuff= str.GetBytes("windows-1250")
I can write it to file as RandomAccesFile.WriteBytes but RAF doesn't have method like raf.Initialize4(Serial1.OutputStream). On b4ppc I used
method Serial1.Output2(mybuff())

Phones:
- HTC Desire HD A9191 with Android 2.3.3
- Samsung Omnia II with Windows Mobile 6.5 (no problems)
Versions of library: B4android: 1.60, Serial: 1.20
 

uskomp

Member
Licensed User
Longtime User
First problem is solved. Thanks Erel :)
If Success Then
tw2.Initialize(Serial1.OutputStream)
b=true
Do While b
tw2.WriteLine("text ...") :tw2.Flush
b=Not( Msgbox2("Print OK?","", "Yes","","No", Null )=DialogResponse.POSITIVE )
Loop
tw2.Close :Serial1.Disconnect
Else :ToastMessageShow("BT - not ready")
End If

Second problem: I have already read about OutputStream but I can't associate with array of Byte. I have MyBuffer() as Byte. I can write it to File (RandomAccessFile.WriteBytes) but how to send it to printer via Serial1.OutputStream. I can't use ByteConverter.StringFromBytes because it converts some bytes to wrong chars (I don't use UTF-8). I must send array of bytes (or binary file) directly to printer via serial port (Bluetooth) without any conversion. How to achieve it?
 

uskomp

Member
Licensed User
Longtime User
Problems solved :)

It was easier than :sign0013:
Thanks
Sub Serial1_Connected (Success As Boolean)
If Success Then :Info2("Bluetooth OK")
Dim os1 As OutputStream
os1=Serial1.OutputStream
os1.WriteBytes(mybufx, 0, mybufx.Length)
os1.Flush
If YesNo("Print OK?") Then Serial1.Disconnect Else Serial1_Connected(True)
Else :Info("BT - not ready")
End If
End Sub
 
Top