Zebra EM 220, Print Code 128 barcode using Android - java

I want to print a code 128 barcode using the Zebra's EM 220 SDK for Android.
I tried to print it using the PrintBarcode() method like this :
BxlService bxl = new BxlService();
bxl.Connect(macAddress);
String data = "123589647525";
bxl.PrintBarcode(data.getBytes(), data.length(), BxlService.BXL_BCS_Code128, 100, 3, 0, BxlService.BXL_BC_TEXT_NONE);
bxl.Disconnect();
but the printed code can't be scanned by Android scan applications, like ZXing.
After searching on the web, I understood data had to be formatted (even if I am a little surprised Zebra SDK doesn't do that...) and found the barcode4j library that help to encode data. However, even with the library, the printed barcode can't be scanned.
BxlService bxl = new BxlService();
bxl.Connect(macAdress);
DefaultCode128Encoder dce = new DefaultCode128Encoder();
String data = "123456679857";
int[] i = dce.encode(data);
String barcode = "";
for (int j : i) {
barcode += j;
}
bxl.PrintBarcode(barcode.getBytes(), barcode.length(), BxlService.BXL_BCS_Code128, 100, 3, 0, BxlService.BXL_BC_TEXT_NONE);
bxl.Disconnect();
So, my question is simple : how to print code 128 barcode using the Zebra's EM 220 SDK for Android ?

Finally, I have found a workaround.
I use ZXing to encode my data, create a Bitmap with the barcode, save the Bitmap as a file before printing it with the printImage() method.
It works, but if someone knows how to use the printBarcode() method, I'd appreciate he tells me how to do.

Related

Rendering big Post Script file with Ghost4J in Java

i made a Java application whose purpose is to offer a Print Preview for PS files.
My program uses Ghostscript and Ghost4J to load the Post Script file and produces a list of Images (one for each page) using the SimpleRenderer.render method. Then using a simple JList i show only the image corresponding to the page the user selected in JList.
This worked fine until a really big PS file occurred, causing an OutOfMemoryError when executing the code
PSDocument pdocument = new PSDocument(new File(filename));
I know that is possibile to read a file a little at a time using InputStreams, the problem is that i can't think of a way to connect the bytes that i read with the actual pages of the document.
Example, i tried to read from PS file 100 MB at a time
int buffer_size = 100000000;
byte[] buffer = new byte[buffer_size];
FileInputStream partial = new FileInputStream(filename);
partial.read(buffer, 0, buffer_size);
document.load(new ByteArrayInputStream(buffer));
SimpleRenderer renderer = new SimpleRenderer();
//how many pages do i have to read?
List<Image> images = renderer.render(document, firstpage ??, lastpage ??);
Am i missing some Ghost4J functionality to read partially a file?
Or has someone other suggestions / approaches about how to solve this problem in different ways?
I am really struggling
I found out I can use Ghost4J Core API to retrieve from a Post Script file a reduced set of pages as Images.
Ghostscript gs = Ghostscript.getInstance();
String[] gsArgs = new String[9];
gsArgs[0] = "-dQUIET";
gsArgs[1] = "-dNOPAUSE";
gsArgs[2] = "-dBATCH";
gsArgs[3] = "-dSAFER";
gsArgs[4] = "-sDEVICE=display";
gsArgs[5] = "-sDisplayHandle=0";
gsArgs[6] = "-dDisplayFormat=16#804";
gsArgs[7] = "-sPageList="+firstPage+"-"+lastPage;
gsArgs[8] = "-f"+filename;
//create display callback (capture display output pages as images)
ImageWriterDisplayCallback displayCallback = new ImageWriterDisplayCallback();
//set display callback
gs.setDisplayCallback(displayCallback);
//run PostScript (also works with PDF) and exit interpreter
try {
gs.initialize(gsArgs);
gs.exit();
Ghostscript.deleteInstance();
} catch (GhostscriptException e) {
System.out.println("ERROR: " + e.getMessage());
e.printStackTrace();
}
return displayCallback.getImages(); //return List<Images>
This solve the problem of rendering page as images in the preview.
However, i could not find a way to use Ghost4J to know total number of pages of PS file (in case the file is too big for opening it with Document.load()).
So, i am still here needing some help

Table formatting in java itextpdf [duplicate]

i'm trying to create a pdf looks like this
but when i try string padding, it looks like this in pdf file
here is the part of the c# code i tried. myExcelData is filled from excel file.
for (int i = 0; i < 15; i++)
{
Chunk cSira = new Chunk((i + 1).ToString().PadRight(10), icerikFont);
Chunk cHizmet = new Chunk(myExcelData.Tables[0].Rows[i][6].ToString().PadRight(80), icerikFont);
Chunk cAdet = new Chunk(myExcelData.Tables[0].Rows[i][1].ToString().PadRight(10), icerikFont);
Chunk cBirimFiyat = new Chunk(myExcelData.Tables[0].Rows[i][2].ToString().PadRight(20), icerikFont);
Chunk cTutar = new Chunk(myExcelData.Tables[0].Rows[i][3].ToString().PadRight(20), icerikFont);
d.Add(cSira);
d.Add(cHizmet);
d.Add(cAdet);
d.Add(cBirimFiyat);
d.Add(cTutar);
d.Add(Chunk.NEWLINE);
}
There are two ways to do this:
use a monospaced font (e.g. Courier). Currently you're using a font of which the width of the different characters is different.
download chapter 2 of my book and learn how to use TAB CHUNKS (look for that title on page 48).
Use a PdfPTable as mkl indicates in his comment (maybe you were overlooking the obvious)
If you need a code snippet for option 2, take a look at the DirectorOverview3 example. The result looks like this. If you don't understand Java, read the C# example.

Create OBD2 MUT scanner by using Java FTDI lib - jd2xx - openport1.3 usb cable

I am trying to create a Java obd2 scanner app for my mitsubishi lancer mx 1997 which use MUTII protocol over OBD2. Can anybody help me to read MUT request codes using jd2xx library.
I have tried the below program, but it didn read engine RPM.
package lancerscan;
import jd2xx.JD2XX;
public class Test2 {
public static void main(String[] args) throws Exception {
JD2XX jd = new JD2XX();
jd.open(0);
jd.setBaudRate(38400);
jd.setDataCharacteristics(
8, JD2XX.STOP_BITS_1, JD2XX.PARITY_NONE);
jd.setFlowControl(
JD2XX.FLOW_NONE, 0, 0);
jd.setTimeouts(1000, 1000);
String msg = "21";
int ret = jd.write(msg.getBytes());
System.out.println(ret + " bytes sent.");
int rd = jd.read();
System.out.println(">>>" + rd);
int status = jd.getQueueStatus();
byte[] data = new byte[(int) status];
long lngBytesReturned = jd.read(data, 0, data.length);
System.out.println("======= " + lngBytesReturned);
}
}
MUT request code for Engine RPM is 0x21
more MUT request codes can be found here
similar C programs which works fine is here; main prjct files are here
Thanks,
harsha
First your using a different baud rate to that in the example. The example uses 15625 baud but you are using 38400 baud.
Secondly you are missing some of the setup commands. I am not sure if this will make a difference but its something that is different between your code and the example.
Mitsubishi require you to set the car ECU into diagnostic mode by sending 0x00 at a rate of 5 baud on one of the pins. On the OpenPort 1.3D cable this translates to setting the break to on for 1800 ms and then turning it off. You can see this is done with the ftdimut_init() command from the libftdimut.c file.
printf("Sending 0x00 at 5 baud\n");
printf("Break on......\n");
ftStatus = FT_SetBreakOn(ftdimut_ftHandle);
if(ftStatus != FT_OK) return ftStatus;
ftdimut_msleep(1800);
printf("Break off......\n");
ftStatus = FT_SetBreakOff(ftdimut_ftHandle);
if(ftStatus != FT_OK) return ftStatus;
The car ECU will then send you 4 bytes containing the ECU ID. This can then be used to check the ECU correctly entered diagnostic mode. You can see this in libftdimut.c.
ftStatus = FT_Read(ftdimut_ftHandle, buf, 4, &bytesRead);
if(ftStatus != FT_OK) return ftStatus;
if(bytesRead == 4) {
return FT_OK;
}
Now assuming that you got the 4 bytes back you can start to send the diagnostic codes such as 0x17 or 0x21.
I just saw your post on my blog, niallm answer is correct, you need to do a 5 baud init first which involves driving the KLine, you can use something like the 5 baud init posted in that answer, more info about the protocol:
http://evoecu.logic.net/wiki/MUT_Protocol
After getting a 4 byte response you can start sending requests at 15625 baud (I'm communicating with a 94 3000GT so the CEL light stops blinking), also in my case I send the converted values (0x21 = 33 decimal) as a byte array.

making and storing a barcode image from a barcode URL (Barcode4J)

I'm not very familiar with barcodes or barcode4j. I have a URL of the barcode and need to connect to that URL, stream it in order to make an image from it, then store that image somewhere on the file system.
does anyone have experience doing this with Barcode4J?
below i make the url...
private BarcodeRequestBean barCodeProcess(ResponseWithBarCode barCode)throws Exception
{
//hard coding bar code encoding and font size time being
String barCodeNum = ((ResponseWithBarCode)barCode).getBarCodeNumber();
logger.info("Please check below barcode generating parameters if generation failed:");
logger.info("BarCode Number = " + barCodeNum);
if (StringUtils.isEmpty(barCodeNum)||(barCodeNum==null))
{
throw new Exception("ResponseWithBarCode returned invalid barCodeNumber value!");
}
BarcodeRequestBean barbean = new BarcodeRequestBean();
//set bar code number
barbean.setMsg(barCodeNum); //reference number
//set default value
barbean.setType(config.getString("barcode.encoding")); //ex:code128
barbean.setHumanReadableSize(config.getString("barcode.font.size")); //ex:3pt
barbean.setWideFactor(config.getString("barcode.wide.factor")); //wide factor: 2
barbean.setFormat(config.getString("barcode.file.format")); //file format: png
barbean.setHeight(config.getString("barcode.height")); //heigh:1cm
barbean.setModuleWidth(config.getString("barcode.module.width")); //Module width: 0.15mm
return barbean;
}
I have a string of the url as such:
String genbc = barCodeProcess(barCode).toURL();
Perhaps you should learn to think more clear about your work.
Solving this issue, from what I understand, has nothing to do with bar codes. You have an image, that is available through an URL, and you must download it. That problem has been viewed many times on stack overflow and you would have found it if you did the search: "java downloading an image". It was the first result that came up for me in google.

Cannot deserialize featureset using DigitalPersona Sdk java edition

am trying to create a soap webservice method to match fingerprints using digitalpersona one touch for windows sdk java edition. I capture the featureset from an applet at the client side and compare it with my template on the server side. But I need to deserialize it and create the feature set again so that i can compare it with the template.
I dont know how to recreate the feature set so that i can use it for verification:
//This is for template retrieval: (no problem here)
String dbTemplate = result.getString("template");
byte[] byteArray = new byte[1];
byteArray = hexStringToByteArray(dbTemplate);
DPFPTemplate template = DPFPGlobal.getTemplateFactory().createTemplate();
template.deserialize(byteArray);
byte[] fsArray = new byte[1];
fsArray = hexStringToByteArray(ftSet);
//the problem is here, I've already converted it back into bytearray[] but i need to deserialize it and create the feature set again.
featureSet.deserialise(fsArray);
DPFPFeatureSet features = extractFeatures(sample, DPFPDataPurpose.DATA_PURPOSE_VERIFICATION);
//This is for matching features and template
DPFPVerification matcher = DPFPGlobal.getVerificationFactory().createVerification();
DPFPVerificationResult result1 = matcher.verify(features, template);
if (result1.isVerified()) {
return "The fingerprint was VERIFIED.";
} else {
return "The fingerprint was NOT VERIFIED.";
}
Please help me.
the best thing you can do here is not to convert the bytearray into string. if you are saving it in a database, you can automatically save it as byte array (since the blob can accept a bytearray).
you can insert it like this (just an example)
PreparedStatement st=con.prepareStatement("INSERT INTO EMPLOYEE(employee_id,template)"+"values(?,?)");
st.setInt(1,23);
st.setBytes(2, enroller.getTemplate().serialize());
Statement st = con.createStatement();
ResultSet rec = st.executeQuery("SELECT * FROM EMPLOYEE WHERE EMPLOYEE_ID=3");
Then when accessing the template, deserialize it (just follow the sdk, i think it's around page 37) Onetouch java sdk ==== link
a sample will be available below.
while(rec.next()){
blob = rec.getBlob("template");
int blobLength = (int)blob.length();
blobAsBytes = blob.getBytes(1, blobLength);
}
templater.deserialize(blobAsBytes);
verificator.setFARRequested(DPFPVerification.MEDIUM_SECURITY_FAR);
DPFPVerificationResult result = verificator.verify(fs, templater);
if (result.isVerified())
System.out.print("The fingerprint was VERIFIED.");

Categories