problem with printing via bluetooth printer adapter

M

Milsnips

Hi there,

i've got a BlueTake BT200 bluetooth printer adapter thats hooked up to an
EPSON LX300 dot matrix printer, and an app that creates a text file, then
sends the stream of the text file to the bluetooth port.

It prints out good, however something is making it print very very slow with
pauses in between.

my file size is 2kb, bluetooth adapter buffer is 32kb and printer i think is
4 or 8kb so it shouldnt be a buffer issue but i cant figure out why it
prints so slow.

If i print via BTfrom a desktop text file, the performance is fine and it
prints fast.

Here is the code i use to pass the data to the bluetooth port:

Sub SendToSerial(ByVal outputDestination As printType, ByVal filename As
String)
Dim pC As New CFPrinting.CommDevice
Dim fs As IO.FileStream
Try
pC.Port = "COM7:"
Try
pC.Init()
fs = IO.File.Open(filename, System.IO.FileMode.Open)
Dim ctr As Integer = 0
For j As Integer = 0 To CInt(fs.Length - 1)
If ctr = 1024 Then
Threading.Thread.Sleep(1000)
ctr = 0
End If
pC.Send(Convert.ToByte(fs.ReadByte()))
ctr += 1
Next
fs.Close()
Catch ex As Exception
MsgBox(ex.Message)
Finally
fs = Nothing
pC.ClosePort()
pC.Dispose()
End Try
Catch ex As Exception
'error occured here...
End Try
pC = Nothing
fs = Nothing
End Sub



Any help apprecieated to why the bluetooth print adapter prints slower from
a PDA (Imate JAMIN) than when its from the desktop pc.

thanks.

Paul
 
D

Dick Grier

Hi,

You appear to be sending your data 1 byte at a time, with a 1-second pause
between each byte. I suspect this may be not quite what you intended?

Dick

--
Richard Grier, MVP
Hard & Software
Author of Visual Basic Programmer's Guide to Serial Communications, Fourth
Edition,
ISBN 1-890422-28-2 (391 pages, includes CD-ROM). July 2004, Revised March
2006.
See www.hardandsoftware.net for details and contact information.
 
M

Milsnips

hi there,

actually no, if you look closely, i loop through and send 1024bytes, then
pause 1 second, unless i'm wrong here..

actually i think i tried removing that section of code that sleeps for
1000ms, and it still didnt make a difference, this is just a caution bit of
code for old printers that have a small buffer - eg. 4kb like the Epson
LX300

regards,
Paul
 
G

Guest

And you chose to not send the data in packets larger than 1 byte at a time
because...? This is really inefficient.
 
M

Milsnips

hi Chris,

yeh it was some older function i was using that sent byte by byte, however
i've now upgraded the code to use the system.io.ports.serialport class and
send a line at a time, so hope it should sort the problem.

thanks,
Paul
 
M

Milsnips

Ok i've rewritten it using the .net 2.0 serial class, here is my code
below, when i get to the p.WriteLine, it just hangs here, and i dont know
why?

------code start-------
Sub SendToSerial(ByVal outputDestination As printType, ByVal filename As
String)
Dim p As System.IO.Ports.SerialPort
Dim fs As IO.StreamReader
Dim sendValue As String = ""

Try
p = New System.IO.Ports.SerialPort("COM1:")

Try
p.Open()
fs = New IO.StreamReader(filename)
Do Until fs.EndOfStream
sendValue = fs.ReadLine
p.WriteLine(sendValue)
Loop
fs.Close()
Catch ex As Exception
MsgBox(ex.Message)
Finally
fs = Nothing
If p.IsOpen Then p.Close()
p.Dispose()
p = Nothing
End Try

Catch ex As Exception
'error occured
End Try

p = Nothing
End Sub

------code end -------
The code opens the text file, gets the first line, and when it tries sending
it to the serial port "p.WriteLine(sendValue)", it just hangs here.
I'm doing this on an emulator and in my previous function it worked okay
without hanging. I also tried the device emulator configuration settings to
output COM1 data to the text console window but it never pops up.

any help appreciated,
thanks,
Paul
 
G

Guest

Is that the entire code? You never set up the COM port anywhere (speed,
parity, etc. etc)
 
M

Milsnips

Hi Chris,

yeh thats all the code, as far as i know, considering this is my first
project using serial communication, when i create the instance and open the
port, if i dont put in any other values, it defaults to the following (seen
in Watch window):

BaudRate: 9600
DataBits:8
Parity: None
StopBits:1

I dont know much about serial settings, is there anything i can set these
to, to optimize the performance?

thanks,
Paul
 
G

Guest

First, never trust defaults. Second, what settings does the target device
require? There is no "optimization" you simply must match what the target
expects.
 
D

Dick Grier

Here is a snip from a code example in my book. I choose to treat all data a
binary (this simplifies things; if the file actually is text, this is a
non-issue):

If Filename <> "" Then

Dim fs As New System.IO.FileStream(Filename, IO.FileMode.Open,
IO.FileAccess.Read)

'declaring a FileStream to open the file with access mode of reading

logReader = New System.IO.BinaryReader(fs)

'creating a new StreamReader and passing the filestream object fs as
argument

logReader.BaseStream.Seek(0, IO.SeekOrigin.Begin)

Dim FileLength = logReader.BaseStream.Length

Dim BytesRemaining As Integer = FileLength

With SerialPort

Do Until BytesRemaining < SerialPort.WriteBufferSize

Try

Dim buffer(.WriteBufferSize - 1) As Byte

buffer = logReader.ReadBytes(.WriteBufferSize)

..Write(buffer, 0, .WriteBufferSize)

BytesRemaining -= .WriteBufferSize

Catch ex As Exception

Exit Do

End Try

Loop

If BytesRemaining > 0 Then

Try

Dim buffer(BytesRemaining - 1) As Byte

buffer = logReader.ReadBytes(BytesRemaining)

..Write(buffer, 0, BytesRemaining)

Catch ex As Exception

End Try

End If

Note, this code allows for "chunks" of data up to, but not exceeding, the
SerialPort WriteBuffeSize. If this still hangs at "write" something else is
going on.

Dick
--
Richard Grier, MVP
Hard & Software
Author of Visual Basic Programmer's Guide to Serial Communications, Fourth
Edition,
ISBN 1-890422-28-2 (391 pages, includes CD-ROM). July 2004, Revised March
2006.
See www.hardandsoftware.net for details and contact information.
 
M

Milsnips

Hi Dick,

thanks for your reply and the code example. After some more testing i found
that its only hanging on the emulator, but when i deploy to a device, it
seems to send to the serial port okay without hanging.

I assume that i wont need the check for thw write buffer size, as my text
files are a maximum of about 3-5kb, the bluetooth print adapter is 32kb
buffer, and the epson lx300 printer i think has either 4kb or 8kb.

regards,
Paul
 
M

Milsnips

Hi Chris,

I'm not sure exactly what settings the target device requires, its a
BlueTake BT200 bluetooth printer adapter which is connected to an Epson
LX300 dot matrix.

When i connect direct via cable (PDA --> printer) the speed prints out okay,
only when im trying through bluetooth, it prints out part of the text, then
pauses for a second or so, then prints a little more, then pauses again, and
so on, until the end of the stream.

regards,
Paul
 
D

Dick Grier

Hi,

The WriteBufferSize is a funtion of the SerialPort object, not the device
driver. This buffering is what is done by Windows PRIOR to calling the
driver. The reason that I use WriteBufferSize to apportion "chunks" is to
avoid a Tx buffer overflow (in Windows, not in the virtual UART).

Your code certainly can send data faster than it might be accepted. Unless
you use flow control, you may need to add some sort of delay in the loop to
allow the printer to "catch up." Of course, if your files always are as
small as 3K, then there shouldn't be any problem. If your file exceeds the
printer buffer size, then there may or may not be an issue.

Dick

--
Richard Grier, MVP
Hard & Software
Author of Visual Basic Programmer's Guide to Serial Communications, Fourth
Edition,
ISBN 1-890422-28-2 (391 pages, includes CD-ROM). July 2004, Revised March
2006.
See www.hardandsoftware.net for details and contact information.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top