I'm now trying to write a simple program in C# that sends command to the printer to print a plain text but don't know how to. There are 2 main problems that I'm facing now:
1. How to communicate with the printer?
After doing some google search but not getting a satisfying result I went to Brothers' main page and found there a so-called b-PAC3 SDK.
After having downloaded and installed it, in the directory where it's installed, I found a folder named "Samples"- there are sample codes written in some different language (VB, VS, VSC, ...) I hoped that these sample codes would work since this SDK and the printer come from the same company. But they didn't. Let me show you one of these samples here: (code in C#)
/*************************************************************************
b-PAC 3.0 Component Sample (RfidRW)
(C)Copyright Brother Industries, Ltd. 2009
*************************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleSampleCSharp
{
class Program
{
private const int NOERROR = 0;
private const string ANTENNA_READER_WRITER = "Reader/Writer side";
static void Main(string[] args)
{
// Create Rfid Instance
bpac.RfidClass rfid = new bpac.RfidClass(); // Rfid Instance
string selectedDevice; // selected device
/* GetInstalledDevices */
Console.WriteLine("==GetInstalledDevices()==");
object[] arrDevices = (object[])rfid.GetInstalledDevices();
if (rfid.ErrorCode == NOERROR)
{
Console.WriteLine("Succeed to GetInstalledDevices()");
int index = 0;
foreach (string device in arrDevices)
{
Console.WriteLine(String.Format("[{0}] {1}", index, device));
index++;
}
// select device
Console.WriteLine("Please Select Device");
int selectedDeviceIndex = int.Parse(Console.ReadLine());
selectedDevice = arrDevices[selectedDeviceIndex].ToString();
}
else
{
Console.WriteLine("Failed to GetInstalledDevices()");
goto CleanUp;
}
// ....
}
}
}
When I run this code, the first problem comes out: (it displayed exactly as in quote bellow, sorry, I can't post image due to low reputation):
==GetInstalledDevices()==
Succeed to GetInstalledDevices()
Please Select Device
There wasn't any error but seems like program can't find my device, I don't have any idea why this happens.
2. How to write a QL-style command?
I know that each kind of printer has its own command language so after searching on Brother's site I found a reference:
Brother QL Series Command Reference (QL-500/550/560/570/580N/ 650TD/700/1050/1060N)
I myself have no experience in working with thermal printer and unfortunately there isn't any sample in this command reference which makes it really difficult for me to figure out how the command should be written.
Has anyone worked with Brother QL serie printers before?
P.S: The printer that I'm using is Brother QL 560.
To communicate with the printer, you need a few things:
Using the information provided in chapter 7 of the command reference and the samples that come with libusb, make a small routine that will detect and open a communication channel with the printer via USB.
Then, using the rest of the information available in the manual, send a series of ESC commands to the printer to either configure it or print labels.
PS: If you need to improve your background on USB communication, I recommend an excellent reference called "USB in a Nutshell", available at beyondlogic dot org (I can't post more than two links).