Bluetooth Printing from XDAIIi (Broadcom device)

S

stunicoll

Hi,

I am trying to send data to a Bluetooth Printer, which I have paired to
a XDA IIi (Pocket PC 2003 SE) using Bluetooth Manager. Currently, I am
using C# and I am able to start up the Connection between the two using
SerialPort.Open (baud rate = 4800, parity bit = None, Com Port =
"COM6") and this apparently works (the connection goes green in
Bluetooth Manager).

But - I am then attempting to send the data using SerialPort.Write with
the data in a byte array or a string. The code appears to work and no
exception is thrown, but the printer device shows an error indication
rather than accepting the data and printing. From using the sample exe
which came with the printer, i do know that it is working and can print
from that device.

Does anyone have any experience with this sort of stuff and can suggest
what may be going wrong? Is it because the SerialPort is using the
Microsoft stack rather than Broadcom??? I just presumed that if i were
to write the data to that port which was already connected then that
would work - but obviously not! At least the printer is indicating
that it is receiving something though by showing the error!

Any help would be great.

Thanks!
 
P

Peter Foot [MVP]

The SerialPort class is not dependent on the Bluetooth stack used, it will
work with either once a virtual COM port has been configured.
Are you sure that the data you are sending to the printer is in a format it
understands?

Peter
 
S

stunicoll

Thanks Peter - at the moment I am send a simple "hello world" phrase in
a byte array (also tried this with a string) using the SerialPort.Write
command.

I am not 100% sure whether its in the correct format as we have no
documentation about the printer on this - its a Brother MPrint
MW-140BT.

What I have done so far though is pasted below - could you confirm that
I've not totally misunderstood what is going on (the printer is
definitely connected to COM6 outbound, as the SerialPort.open
definitely connects the bluetooth device which is confirmed by opening
Bluetooth manager once that line of code has been run). I've combined
the three sections (open, write, close) below, but there are actual
delays between each section in the test app i am using.

System.IO.Ports.SerialPort thisSerial;

// Params: COMPort, Baud Rate, Parity Bit, Data bits, Stop bits
thisSerial = new System.IO.Ports.SerialPort("COM6", 4800,
System.IO.Ports.Parity.None, 8, System.IO.Ports.StopBits.One);


thisSerial.WriteTimeout = SerialPort.InfiniteTimeout;

try
{
// This opens the connection
thisSerial.Open();
}
catch (System.IO.IOException ex)
{
throw ex;
}


try
{
// Test output to print
string text = "Test String - HELLO EVERYBODY";

// Convert to a byte array
byte[] buffer = new byte[text.Length+1];
buffer = (new UnicodeEncoding()).GetBytes(text);

// Send to printer
thisSerial.Write(buffer, 0, buffer.Length);
}
catch (System.IO.IOException ex)
{
throw ex;
}

// Disconnect from device
thisSerial.Close();



Thankyou!!!
 
G

Ginny Caughey [MVP]

There are a couple of tricks to try. One is writing a single byte at a time
with a small delay (maybe 100 ms) between. Another thing to try keeping
sleeping maybe a second after sending the last byte before closing the port.
Once you find what does work, then you can tweak it, although it's always
nice to have the docs from the manufacturer. I'm not familiar with your
particular printer, but all the serial printers I have worked with are a bit
flakey like that.

--
Ginny Caughey
Device Application Development MVP


Thanks Peter - at the moment I am send a simple "hello world" phrase in
a byte array (also tried this with a string) using the SerialPort.Write
command.

I am not 100% sure whether its in the correct format as we have no
documentation about the printer on this - its a Brother MPrint
MW-140BT.

What I have done so far though is pasted below - could you confirm that
I've not totally misunderstood what is going on (the printer is
definitely connected to COM6 outbound, as the SerialPort.open
definitely connects the bluetooth device which is confirmed by opening
Bluetooth manager once that line of code has been run). I've combined
the three sections (open, write, close) below, but there are actual
delays between each section in the test app i am using.

System.IO.Ports.SerialPort thisSerial;

// Params: COMPort, Baud Rate, Parity Bit, Data bits, Stop bits
thisSerial = new System.IO.Ports.SerialPort("COM6", 4800,
System.IO.Ports.Parity.None, 8, System.IO.Ports.StopBits.One);


thisSerial.WriteTimeout = SerialPort.InfiniteTimeout;

try
{
// This opens the connection
thisSerial.Open();
}
catch (System.IO.IOException ex)
{
throw ex;
}


try
{
// Test output to print
string text = "Test String - HELLO EVERYBODY";

// Convert to a byte array
byte[] buffer = new byte[text.Length+1];
buffer = (new UnicodeEncoding()).GetBytes(text);

// Send to printer
thisSerial.Write(buffer, 0, buffer.Length);
}
catch (System.IO.IOException ex)
{
throw ex;
}

// Disconnect from device
thisSerial.Close();



Thankyou!!!


The SerialPort class is not dependent on the Bluetooth stack used, it
will
work with either once a virtual COM port has been configured.
Are you sure that the data you are sending to the printer is in a format
it
understands?

Peter
 
D

Dick Grier

Hi,

More advice.

Terminate your data with a Formfeed character. Many printers buffer data
for printing until a formfeed has been received (0x0C).

Do not close the port UNTIL you are finished. Your close may execute
BEFORE all of the data have been sent. Wait some time, or (better, IMO)
close only when you are exiting the app.

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.
 
S

stunicoll

Thanks for both those suggestions - still nothing though. There is
definitely communication between the PDA and device, as the error light
is flashing on the printer - but I just can't get the right format up
to now.

Tried splitting it up so that I only send one byte at a time, with
delays, and also tried adding the form feed but still getting the same
thing. I'm going to see if i can capture their software sending, and
find out what the text it - also waiting to hear back from Brother so
hopefully they can shed some light on what it is expecting.

Thanks again!!!
 
S

stunicoll

Thanks for both those suggestions - still nothing though. There is
definitely communication between the PDA and device, as the error light
is flashing on the printer - but I just can't get the right format up
to now.

Tried splitting it up so that I only send one byte at a time, with
delays, and also tried adding the form feed but still getting the same
thing. I'm going to see if i can capture their software sending, and
find out what the text it - also waiting to hear back from Brother so
hopefully they can shed some light on what it is expecting.

Thanks again!!!
 

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