Reputation: 10247
How could it be that one barcode is being read, yet another one is printed?
My code reads the value scanned and puts it in a textbox; e.g., a value such as "76145513"
Yet, when I print a label for that barcode, it prints "57056548"
This last is a valid barcode, but why is that ("57056548") printed instead of the value scanned ("76145513")?
I am reading the barcodes from a shhet of paper that has many "outsized" barcodes on it. The sheet I'm using contains both the value being scanned AND the one being printed, but I even went so far as to cover up the rogue barcode when scanning to be certain that the laser beam wasn't wall-eyed and "seeing" the printed value, although its "cyclops beam" does light up the correct barcode only.
I put some debug/sanity check code in to make sure what was being sent to print was correct, and it is; I see, "Barcode in PrintUtils.ZebraQLn220Printer.PrintLabel is 76145513" in the first MessageBox.Show() and "barcode with checksum is 761455132" with the second one.
So how could it be that the correct value is being scanned, sent to the Print method, and yet a different (but valid!) code is being printed?
Here is the core print code:
private void PrepareAndPrintLabel()
{
. . .
string barcode = textBoxUPC.Text.Trim();
if (String.IsNullOrEmpty(barcode))
{
MessageBox.Show("Cannot print with no barcode provided");
return;
}
PrintUtils.IBeltPrinterFactory factory = new
PrintUtils.BeltPrinterFactory();
PrintUtils.IBeltPrinter printer = factory.NewBeltPrinter();
printer.PrintLabel(listPrice, description, barcode);
}
public void PrintLabel(string price, string description, string
barcode)
{
MessageBox.Show(String.Format("Barcode in
PrintUtils.ZebraQLn220Printer.PrintLabel is {0}", barcode));
try
{
ArrayList elementsToPrint = new ArrayList();
// Create one etp for each line to be printed on the label
. . .
ElementToPrint etp3 = new ElementToPrint
{
DisplayVal = barcode,
elementAlignment =
ElementToPrintAlignment.Center, elementType =
elementToPrintType.BarcodeText, RelativeFontSize =
FontSizeType.BarcodeTextMedium, XPos = 0
};
elementsToPrint.Add(etp3);
ElementToPrint etp4 = new ElementToPrint
{
DisplayVal = barcode,
elementAlignment =
ElementToPrintAlignment.Center, elementType = ElementToPrintType.Barcode,
RelativeFontSize = FontSizeType.Large, XPos = 0
};
elementsToPrint.Add(etp4);
ArrayList linesToSend =
ConvertElementsForZebraQLn220(elementsToPrint, 1.25);
using (SerialPort serialPort = new SerialPort())
{
serialPort.BaudRate = 19200;
serialPort.Handshake = Handshake.XOnXOff;
if (!(serialPort.IsOpen))
{
serialPort.Open();
}
Thread.Sleep(500);
foreach (string line in linesToSend)
{
serialPort.Write(line);
}
}
}
catch (Exception ex)
{
String msgInnerExAndStackTrace = String.Format("{0}; Inner
Ex: {1}; Stack Trace: {2}", ex.Message, ex.InnerException, ex.StackTrace)
ExceptionLoggingService.Instance.WriteLog(String.Format("From
ZebraQLn220Printer,PrintUtils.PrintLabel: {0}", msgInnerExAndStackTrace));
}
} // PrintLabel
public static ArrayList ConvertElementsForZebraQLn220(ArrayList
elementsToPrint, double labelHeight)
{
const int BARCODE_TEXT_DELTA = 5;
const int BARCODE_HEIGHT = 50;
ArrayList linesToSend = new ArrayList();
int _labelHeight = ConvertInchesToZebraQLn220DPI(labelHeight);
int YPos = 0;
ElementToPrintAlignment lastAlignmentSet =
ElementToPrintAlignment.Left;
// Always start with this line for label mode (as opposed to
line mode) CPCL:
linesToSend.Add(string.Format("! 0 200 200 {0} 1\r\n",
_labelHeight)); //at 1.25, labelHeight is 254; more accurately, it would b
241, as the labels are really 1.1875" in height, not 1.25
foreach (ElementToPrint etp in elementsToPrint)
{
// POSITION THE TEXT
. . .
// SIZE THE TEXT - These are based on the device-specific
parameters
if (etp.elementType.Equals(ElementToPrintType.BarcodeText))
{
linesToSend.Add(string.Format("BARCODE-TEXT {0} {1}
{2}\r\n", fontNum, fontSizeId, BARCODE_TEXT_DELTA));
YPos = YPos + GetHeightForFontNumAndSizeID(fontNum,
fontSizeId) + BARCODE_TEXT_DELTA;
}
else if (etp.elementType.Equals(ElementToPrintType.Barcode))
{
string displayValTrimmed = etp.DisplayVal.Trim();
string barcodeType = GetBarcodeType(displayValTrimmed);
string checkSum = GetBarcodeChecksum(displayValTrimmed);
string barcodeWithCheckSum = string.Format("{0}{1}",
displayValTrimmed, checkSum);
MessageBox.Show(string.Format("barcodeWithCheckSum is
{0}", barcodeWithCheckSum));
linesToSend.Add(string.Format("BARCODE {0} 1 1 {1} 0 {2}
{3}\r\n", barcodeType, BARCODE_HEIGHT, YPos, barcodeWithCheckSum));
YPos = YPos + BARCODE_HEIGHT;
}
else if (etp.elementType.Equals(ElementToPrintType.Text))
{
linesToSend.Add(string.Format("TEXT {0} {1} 0 {2}
{3}\r\n", fontNum, fontSizeId, YPos, etp.DisplayVal));
YPos = YPos + GetHeightForFontNumAndSizeID(fontNum,
fontSizeId);
}
}
This is what the log file shows (irrelevent entries elided):
. . .
Date: 2/3/2015 2:31:26 PM
Message: Reached frmVerify.InitReader
Date: 2/3/2015 2:31:26 PM
Message: Reached frmVerify.StartRead
Date: 2/3/2015 2:31:29 PM
Message: Reached frmVerify.BarcodeReader_ReadNotify
Date: 2/3/2015 2:31:29 PM
Message: Reached frmVerify.HandleData
Date: 2/3/2015 2:31:29 PM
Message: Reached frmVerify.textBoxUPC_LostFocus
. . .
Date: 2/3/2015 2:31:43 PM
Message: Reached frmVerify.buttonPrintLabel_Click
Date: 2/3/2015 2:31:43 PM
Message: Reached frmVerify.PrepareAndPrintLabel
Date: 2/3/2015 2:31:43 PM
Message: Reached PrintUtils.PrintLabel
Date: 2/3/2015 2:31:43 PM
Message: Reached PrintUtils.ConvertElementsForZebraQLn220
. . .
Date: 2/3/2015 2:31:43 PM
Message: Reached PrintUtils.GetBarcodeType
Date: 2/3/2015 2:31:43 PM
Message: Reached PrintUtils.GetBarcodeChecksum
BTW, "57056548" does not exist anywhere in the code (I thought maybe I had used it as a temporary test value and forgotten to remove it). It seems virtually impossible that this could be happening, yet it is.
Following user3025177's suggestion, I added a debug msg to my printing code:
foreach (string line in linesToSend)
{
MessageBox.Show(String.Format("About to be sent to th
serial port: {0}", line));
serialPort.Write(line);
}
Here is what I saw:
! 0 200 200 241 1
RIGHT
TEXT 4 3 0 0 24.77
LEFT
TEXT 5 0 0 90 No description found
CENTER
BARCODE-TEXT 0 2 5
BARCODE 128 1 1 50 0 137 761455132
FORM
PRINT
And what is printed on the label is:
0.00 [right-aligned]
ITEM NOT FOUND [left-aligned]
[the barcode zebra stripes, centered]
57056548 [centered]
So the correct barcode ("761455132") is being sent, but "57056548" is being printed on the label.
Bizarro!
Sour Mash Archie's comment is intriguing, though - that would make sense, as: (a) The printer I am using for testing is rusty and cobweb-infested (b) The "bogus/rogue" barcode being printed has been printed on that device in the past - so it must be "stuck in memory" or so...
Upvotes: 0
Views: 1979
Reputation: 21712
This is a long shot, but I remember a problem years ago with Zebra printers where they would get stuck on a barcode and always print the same one whenever you printed. This only happened if you used EPL/ZPL codes to print, not if you used Windows graphics commands, but it would persist if you switched the printer off then on again, or tried it on another machine.
We fixed it by doing a hardware reset on the printer; on the model we had you had to open the case and press a button on the circuit board.
Check on the Zebra web site for a firmware update for your printer model.
Upvotes: 2