pikopong

it's all about knowledge

Printing to Zebra S4M Using Java and ZPL II

with 17 comments

Apparently there’re some codes scattered on the net telling people that you can print to a Zebra printer by sending ZPL II codes using PrintService. But the problem is, it’s not working, I don’t know why, maybe because of a different version of printer or model but I’m pretty sure the thing that came out from the printer is just ordinary text not barcode which is what the code was supposed to output.

New Version

Thanks to Oleg for pointing out on how to print using Zebra S4M connected either via USB or network.

The solution is pretty simple, all you have to do is do not install Zebra S4M as a Zebra S4M (sounds weird, I know), instead, just install it as a local raw printer (Linux) or generic text printer (Windows).

For CUPS user in Linux, this is the example for the correct configurations:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#/etc/cups/printers.conf
<Printer Zebra>
Info
Location
DeviceURI socket://10.1.1.5:9100
State Idle
StateTime 1223445299
Accepting Yes
Shared Yes
JobSheets none none
QuotaPeriod 0
PageLimit 0
KLimit 0
OpPolicy default
ErrorPolicy stop-printer
Option orientation-requested 3
</Printer>

You can always add the printer using the web interface, just make sure you choose the RAW as the Make/Manufacturer and Model/Driver.

For Windows user, please take a look at Oleg comment.

Test this Java code, it should print out a barcode:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import javax.print.Doc;
import javax.print.DocFlavor;
import javax.print.DocPrintJob;
import javax.print.PrintException;
import javax.print.PrintService;
import javax.print.PrintServiceLookup;
import javax.print.SimpleDoc;
import javax.print.attribute.PrintServiceAttribute;
import javax.print.attribute.standard.PrinterName;
 
public class SimplePrint {
 
   public static void main(String[] args) {
 
       try {
 
           PrintService psZebra = null;
           String sPrinterName = null;
           PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null);
 
           for (int i = 0; i < services.length; i++) {
 
               PrintServiceAttribute attr = services[i].getAttribute(PrinterName.class);
               sPrinterName = ((PrinterName) attr).getValue();
 
               if (sPrinterName.toLowerCase().indexOf("zebra") >= 0) {
                   psZebra = services[i];
                   break;
               }
           }
 
           if (psZebra == null) {
               System.out.println("Zebra printer is not found.");
               return;
           }
           DocPrintJob job = psZebra.createPrintJob();
 
           String s = "^XA^FO100,40^BY3^B3,,30^FD123ABC^XZ";
 
           byte[] by = s.getBytes();
           DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE;
           Doc doc = new SimpleDoc(by, flavor, null);
           job.print(doc, null);
 
       } catch (PrintException e) {
           e.printStackTrace();
       }      
   }
}

Old Version

So, I started looking around for other methods. I even tried posting on java’s forum and offered 10 duke points, but no one seems to answer my question. After googling around, I found out that I could upload a file containing the ZPL II to the printer, so, I tried and it did work. But another problem arise, Two people cannot ftp simultaneously due to the limited access set by the printer.

Printing using FTP (I’m using Apache Commons Net library)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import java.io.FileInputStream;
import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient;
 
public class FtpPrint {
 
   public static void main(String[] args) {
 
       try {
 
           FTPClient f = new FTPClient();            
 
           f.connect("10.1.127.3");
           f.login("anonymous", "");
           f.setFileType(FTP.ASCII_FILE_TYPE);                            
 
           FileInputStream in = new FileInputStream("/path/to/file");
           if (f.storeFile("filename", in)) {
               System.out.println("Upload ok");
           }                
 
           f.logout();
           f.disconnect();
 
       } catch (Exception e) {
           e.printStackTrace();
       }
   }
}

In the end I had to find another solution. After 3 days of searching the internet up and down, I found out that Zebra’s website offered a piece of code in Java to print using ZPL II using socket programming which automatically solve all of my problems, I was like, what the.. Note to myself, always search for the manufacturer site before googling around. However, a few modifications needed for the given code such as the printer port and the language sent. You can get the codes below:

Printing using socket (Got it from Zebra website)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import java.io.DataOutputStream;
import java.net.Socket;
 
public class SocketPrint {
 
   public static void main(String argv[]) throws Exception {
 
       for (int i = 0; i &lt; 10; i++) {
           Socket clientSocket = new Socket("10.1.127.3", 9100);
           DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream());
           outToServer.writeBytes("^XA^FO100,40^BY3^B3,,30^FD123ABC^XZ");
           clientSocket.close();
       }
   }
}

Download guide to ZPL II

Written by amree

May 11th, 2008 at 9:44 am

Posted in programming

Tagged with ,

List of TV Series You Must Watch

with 11 comments

Since I got nothing to do on this boring weekend, I decided to share with you people my favorite TV Series. So here goes the list with some information about it, oh, by the way, it may contain a little bit spoiler for those who haven’t watch it, but I’ll try my best to keep it to the minimum so that it won’t ruin your experience if you decided to watch it.

CSI: Las Vegas

You may ask, why not CSI Miami or CSI New York ? Simply because it’s the first and the leader, Gil Grissom. is actually a scientist (in the show, not in real life) which to me is so freaking cool. Compared to other CSIs, others are not scientist. But don’t get me wrong, I do like CSI Miami (due to the coolness of Lt. Horatio Caine), it’s just that I like Las Vegas more. Cases presented are much more mysterious, weird, and complicated than the others. Remember last season criminal, the Miniature Killer ? The one who killed people and then send a miniature model of the crime scene to the CSI team, totally wicked.

Desperate Housewives

I still remember the first time I heard about this TV Series, I was like, the only reason I would watch a TV Series displaying old housewives together is because Teri Hatcher is in it. I became one of her fan due to her act in Lois & Clark: The New Adventures of Superman. So, I decided to watch the first episode and then, I’m totally hooked to the TV Series not just because of Teri Hatcher anymore, but also because of Eva Longoria and of course, the storyline which is also interesting. Who would have guessed, a beautiful neighborhood got so many secrets hidden inside their houses and that’s what make Desperate Housewives so interesting.

Gossip Girl

I didn’t pay much attention at all when this TV Series was launched. I did read about its review on how Kristen Bell from Veronica Mars narrates the show as the “Gossip Girl” herself, the story which is somehow almost similar to The O.C (my favorite too). One day, my friend recommended me to watch it, so, I thought since I don’t have any teen drama to watch at that moment, I decided to give it a try, of course, I got hooked up to this one too. The first thing I noticed is one of the actor, the beautiful Leighton Meester which appeared before in House as one of her patient that fall in love with House just because she got disease that can fool her emotion. She definitely act very well for her character as a classy, beautiful, manipulative and rich. But, it’s not just about her, others act very well too.

Heroes

I don’t think I need to introduce this one, one of the most popular TV Series at the moment. Even though, it’s more like The 4400, only it’s so much better. This show got everything, flying, mind reading, bending space and time, invisible, fast healing, nuclear bomb, you just name it. My favorite character is definitely Peter Petrelli, the one who can absorb any abilities, that ability is just so freaking cool.

House M.D

I never like E.R much, House is the only medical show that interests me specifically because it deals with weird deseases and solve it like it’s a puzzle. Even though my friends from medical departments said that House is a stupid show since it shows how the doctor do all the work, from MRI, to X-Ray, to Lab Testing and others which is totally a lie since no doctors can do all that stuff alone. But, who cares ? I’m so glad I’m not in the medical field, coz, if I do, I won’t be able to enjoy this show. The most interesting part of this show is not about the medical itself, it’s about Dr House himself. The way he talks is just way too cool. I definitely like the way he being sarcastic to others around him. I also learned about a few weird deseases after watching this one.

Jericho

The storyline is indeed interesting. Some people said the show became worse at the end of Season 1. But seriously, you people just hold on and watch till the end of this TV Series. The ending is so well done that I felt I don’t care anymore if this show discontinued, simply because it has been ended very well. This is one of the show when it was cancelled, people got angry and started to send tons of nuts to the tv station just to show how many people are supporting this show.

Kyle XY

This is only show for people who likes to science fiction series. But of course, if you watch this series just because of the ‘cute’ main actor, Kyle himself, or maybe the heroin, the beautiful Amanda, I won’t blame you. The story got better when Kyle’s secret being exposed one by one. This is more like Heroes except there’s only one Hero where he can perform multiple extraordinary capabilities due to his powerful mind.

Lost

I seriously don’t understand why people would watch a TV Series displaying a bunch of people living on a remote island. I mean, what story could they possibly make ? So, I tried the first episode, oh my, I was so wrong about this one. The mystery about the island itself is enough to get me hooked. But if you don’t like waiting for the answer of everything happening on that island, you should just skip this one. It’s a very torturing moment waiting for the answer :(

Prison Break

The first season of this show is definitely the best. I was so addicted to this show, just to know what will happen in the next episode. Of course this is an interesting show, put a genius in a prison and watch him escape, that’s just so insanely cool. But it got worse in the second season, however, the third season became better, but still can’t beat the first season. By the way, every time I recommend Prison Break to anyone I know, they all seems can’t get enough of it, so, maybe you should try it if you just heard about this one for the first time :)

Smallville

Who don’t like Superman ? If you like Superman, you’ll definitely like this one, at least for a while. Getting a little boring from time to time due to the storyline. The only reason I’m still watching this one is because the current season likes to talks about the Superman’s secret. Thank god the heroin is in the coma right now (in the show), if not, this one will suck more.

Supernatural

Put ghosts, funny and cool guys, hot girls crying for help and black magic into a story, you got a good TV Series. Supernatural is more like a Ghostbusters except that it’s better and most of the ghosts are based on the real one from around the world. It’s always cool to watch Dean and Sam do some hocus pocus to destroy the ghosts, which usually boils to the same thing, either cremated the dead body or recite some weird words.

I guess that’s all, so, what about you, tell me a little bit your favorite show in the comment section, thanks !

Written by amree

May 8th, 2008 at 12:08 am

Posted in vids

Tagged with

Automatically Sign JARs using Ant and Bash

with 2 comments

This guide is more towards Netbeans project, but it can be used as a reference for you to customize the script to suit your needs.

The signer bash file:

1
2
3
4
#!/bin/bash
find . -name "*.jar" -exec jarsigner -keystore /path/to/your/key -storepass yourpassword '{}' yourkeystorename \;
echo 'JARs signed';
exit 0

This script will actually search all files ending with .jar from the current directory recursively and then sign it. This means, it can be used separately without ant script. Just make it executeable and run it.

Put this in the last line of your build.xml but it must before the closing tag of the “project” (build.xml can be found in your main project directory)

1
2
3
4
5
6
7
8
<project>
    .
    .
    .
    <target name="-post-jar">
        <exec dir="${dist.dir}" executable="/path/to/your/signer" os="Linux" />
    </target>
</project>

This script will basically sign the jars after all the jars has been build. Please note that it’s better if you set all the path using absolute type of path.

After this, you just have to use Clean and Build to automatically generate the JARs and also automatically sign it. This script will also sign all of your libraries. Good luck :)

Written by amree

April 14th, 2008 at 8:48 am

Posted in programming

Tagged with , , , ,

Top 11 Youtube Memes

with 4 comments

Maybe you’ve seen these videos, maybe not, but these videos are ranked as the most popular at the moment based on their total views. I didn’t check every video, but most of them are viewed at least 1 million times. They are so popular that they became the Internet meme.

  • Rick Roll
  • Chocolate Rain
  • Samwell – “What What (In the Butt)”
  • Tron Guy
  • Numa Numa
  • Star Wars Kid
  • Sneezing Panda
  • Chris Cocker
  • Laughing Baby
  • Afro Ninja

Rick Roll

YouTube Preview Image

Chocolate Rain

YouTube Preview Image

Samwell – “What What (In the Butt)”

YouTube Preview Image

Tron Guy

YouTube Preview Image

Numa Numa

YouTube Preview Image

Star Wars Kid

YouTube Preview Image

Sneezing Panda

YouTube Preview Image

Dramatic Gopher

YouTube Preview Image

Chris Cocker

YouTube Preview Image

Laughing Baby

YouTube Preview Image

Afro Ninja

YouTube Preview Image

South Park making fun to these meme except for Rick Roll

Credits to Valleywag.

Written by amree

April 4th, 2008 at 10:33 pm

Posted in vids

Tagged with ,

Kung Fu Dunk

with 9 comments

Kung Fu Dunk Movie Poster

So, last time we got Shaolin people playing soccer, this time we got Kungfu people playing basketball. Written by Takehiko Inoue (my favorite Slam Dunk manga author), Kung Fu Dunk is about Jay Chou playing basketball using Kungfu. That’s pretty much the summary of the movie. Expect it to be released February 2008. Untill then, enjoy these videos :)

Trailer

YouTube Preview Image

Leaked Video ?

YouTube Preview Image

Written by amree

January 26th, 2008 at 3:50 pm

Posted in vids

Tagged with ,