Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

Sending Raw Printer Commands to thermal Printer


This topic is 5100 days old. Please don't post here. Open a new topic instead.

Recommended Posts

I have almost completed a solution to use FedEx Web Services, at the end I get a response from their API with Raw commands that need to be sent to a thermal Printer (Zebra LP2348) to print the shipping label.

I have successfully sent the received raw commands to the printer from the driver command line, but now I need a way to do it directly and automatically from Filemaker to the printer.

Any ideas?

Thanks

Edited by Guest
Link to comment
Share on other sites

I'm not clear what is meant by 'command line'; do you mean DOS command line?

You ought to be able to send the commands by saving the field containing them to a file, then issuing the DOS COPY command to either the virtual COMx: or LPTy: port which maps to the printer. i.e. COPY filename COM1: or COPY filename LPT1:

You may also need to issue a MODE command to set the COM port baud rate, parity, and stop bits. This thread, while discussing ftp, covers building a batch file dynamically and issuing DOS commands.

Link

360Works ScriptMaster may also be worth investigating, because it can run a command line and return the results from standard output and error. Also, with it, you could easily import javax.comm, and thereby, send data directly to the port from Filemaker. I haven't tried this but it would be very simple to send or receive serial data using it.

Years ago I used Troi's serial plugin for this purpose, but the above alternatives are free.

Link to comment
Share on other sites

Thank you so much for your response. I need to digest all the info you gave me including the link to your previous posting to see if I can make it work.

When I said command line I was referring to a utility window which is part of a printer driver app that allows you to enter Raw Printer Instructions to be sent directly to the thermal printer.

Here is an example of the Raw data I was referring to (If you send this to a thermal printer it will print a FedEx Shipping label)

N

OD10

q812

Q1370,24

D15

ZT

LO0,309,800,4

LO0,563,800,4

LO0,898,800,4

A35,171,0,2,1,1,N,"From:"

A35,190,0,2,1,1,N,""

A35,210,0,2,1,1,N,"Sender Company"

A35,230,0,2,1,1,N,"777 W. LAKE MEAD PKWY"

A35,251,0,2,1,1,N,""

A35,291,0,2,1,1,N,"(888) 899-7770"

A490,231,0,2,1,1,N,"CAD: 100021847/WSXI2450"

A43,345,0,4,1,1,N,"Bogus Recipient"

A43,375,0,4,1,1,N,""

A43,405,0,4,1,1,N,"2400 N. Rancho Drive"

A43,435,0,4,1,1,N,"**TEST LABEL - DO NOT SHIP**"

A35,271,0,2,1,1,N,"Henderson, NV 89015"

A490,190,0,2,1,1,N,"Ship Date: 02OCT10"

A490,210,0,2,1,1,N,"ActWgt: 2.0 LB"

A43,315,0,4,1,1,N,"David Las Vegas"

A615,315,0,2,1,1,N,"(702) 631-7000"

A43,468,0,3,1,2,N,"Las Vegas, NV 89130"

A530,468,0,2,2,2,N,"(US)"

A400,166,0,5,2,3,N,"H"

LO388,165,4,142

A650,375,0,2,1,1,N,"Home Delivery"

LO670,400,105,10

LO670,410,10,112

LO765,410,10,112

LO670,522,105,10

LO476,165,4,145

A650,335,0,3,2,2,N,"FedEx"

A690,418,0,5,2,2,N,"G"

B80,933,0,1E,4,2,290,N,"9612804000000000000000"

A135,1247,0,4,1,1,N,"(9612804) 0000000 00000000"

A783,550,3,1,1,1,N,"J10301008092125"

A10,320,0,3,1,1,N,"TO"

A25,1270,0,3,1,1,N,"HOME"

A25,1295,0,3,1,1,N,""

A300,1275,0,3,1,1,N,""

A300,1297,0,3,1,1,N,""

b50,590,P,800,800,s5,f0,x2,y10,r80,o0,l12,"[)>010289130840804000000000000000FDEB00000002751/12.0LBN2400 N. Rancho DriveLas VegasNVDavid Las Vegas0610ZGH00411ZBogus Recipient12Z702631700014Z**TEST LABEL - DO NOT SHIP**23ZY22ZN20Z026Z142e"

A250,125,0,3,1,1,N,"TRCK: 000000000000000"

A150,105,0,3,1,1,N,"Svcs: HOME PPD"

A16,520,0,1,1,1,N,"Ref: "

A16,535,0,1,1,1,N,"INV: "

A16,550,0,1,1,1,N,"PO: "

A406,550,0,1,1,1,N,"Dept: "

A625,650,0,2,1,2,N,"1"

A640,690,0,2,1,2,N,"of"

A625,730,0,2,1,2,N,"1"

P1

N

PS. I had already tried the TROI Serial plug In, but I cannot get the plug in to recognize the printer port I have the Thermal Printer connected to, only the serial ports.

I believe ScriptMaster could be a good alternative, in fact is ScriptMaster what I am using to submit the XML calls to the API.

Are you referring to any specific function that allows to send data to the printer port? or to a new function that should be custom programmed

Thanks

Edited by Guest
Link to comment
Share on other sites

Your response clarified this quite a bit.

Below Java example would output 'Hello world' to LPT1. I can't try this, but I believe you use LPT1 with no colon after it. This will work well since you already are using ScriptMaster -- I'd prefer this over the DOS method. I did test it with COM4 which I do have, and it threw no errors.

Be aware that double quotes must be escaped in Java, and your printer commands have copious double quotes. e.g. use " for "

Also note you may need newlines/linefeeds/carriage returns between successive lines. i.e. you may need n, r, or both in succession at the end of each command line. Link

When you get this working, can you post the script?

You may want to output to a disc file first to make sure the output is correct (i.e. open it in Notepad), then when you have it right, output it to LPT1 (saves paper!)

You'd probably want to alter this to take the text (command linst) to print as an input parameter.

If you can't get this working, or the escape characters are too problematic, just build the printer commands in a global field, export it to a file (e.g. use ScriptMaster 'Write to file' example that does that and comes with SM), then execute shell command the COPY filename LPT1: to issue the commands. Use the latest version of SM for shell commands, older versions had some issues.

Also, one other question: Why can't you just print through the printer driver?

try {

FileOutputStream os = new FileOutputStream("LPT1");

PrintStream ps = new PrintStream(os);

ps.println("Hello world!");

// use f for form feed -- may be needed at end of text block

ps.print("f");

ps.close();

return "no errors";

}

catch (Exception e)

{

return e;

}

Edited by Guest
Link to comment
Share on other sites

Frank,

Thanks so much for your help.

I finally got to make it work and I could Print a FedEx Label by entering the raw data as a variable in the Script Master fuction you gave me.

I didn't even have to escape the special characters.

So this is what I did:

I created a new ScriptMaster record:

Demo::script

FileOutputStream os = new FileOutputStream("LPT1");

PrintStream ps = new PrintStream(os);

ps.println(rawData);

InputVariables::key = rawData

In this case I entered the raw data from before in the InputVariables::value field

I executed the script, it created the print job in the printer spooler, and the only thing is that it wouldn't print until I closed the Filemaker Application.

I have tried several times and it always does the same thing, the print job is created but until I close Filemaker the printer doesn't print.

This is weird, can you think of a reason?

PS1. When you ask me what can't I just print through the printer driver I am not sure of what you are referring to or how to do it. could you elaborate?

Another question, if I wanted to send this same command from a network printer, instead of the one that is physically connected to the LPT1 what should I use for value in the FileOutputStream?

Thanks.

Edited by Guest
Link to comment
Share on other sites

There will be a command you need to send other than form feed, to cause label to print immediately. Similarly, you will need to include a command to print text, rather than 'hello world'; this was meant as an example of sending data to the port. In your case, you'd substitute the commands from your previous message, assuming they are correct. The commands are all described in the relevant ZPL document Link

It may be easier, if this is just to print a fedex label, to use the PNG image provided by FedEX ship label extension functions. This way, it's reduced to one Java call. Per Link

Alternately, can't you just render the label in a Filemaker layout? Then standard filemaker printing, can be used to print it. This way, the solution will work with any make/model printer. Either get the entire label back as a PNG, or use the Barcode4J library to generate a Postnet barcode as a PNG file and add that element to the layout.

By print through driver, I mean, print through Filemaker File|Print, whereby, the driver rasterizes the fonts, handles page breaks, label gap detection, etc for you so that custom programming isn't required -- i.e. you have a layout with the address & bar codes on it.

If the printer is networked, you'd just use its IP address/share, e.g. MyServerMyPrinter -- note the extra 's since must be escaped.

Edited by Guest
Link to comment
Share on other sites

The raw data I sent to the printer printed correctly, instead of "Hello World" I used a variable to contain all the printer raw data commands and it has worked perfectly, once it prints the label comes out perfectly with all the bar codes, etc.

If I understand you correctly what you are saying is that if the print job is not processed immediately is because I should add some printer command in the raw data?

But if that is the case why when I use exactly that same raw data through other means (not Filemakers' Script Master) it prints right away, and then how come that when I close the Filemaker application the queued jobs print right away? Could it be that I would need to add some Java code to the scriptMaster fucntion so it sends the print instruction in a different way?

If that was the case could you think of anything I could do in the java to force the printer to print (I don't know anything about Java)

In regards to downloading an png or pdf image of the label, I did that originally I just had to decode the image sent by FedEx API and then I could manipulate that container in Filemaker and place it in a Layout, it was straightforward and I would love if I could go from there.

Unfortunately we want to be able to use the Label Thermal Printer instead of printing to a regular laser printer so we need to deal with this annoying issue or the Raw Printer commands.

Once again thank you so much for all your help.

David

Link to comment
Share on other sites

After a few private messages back and forth with fseipel, finally got the code to work using ScriptMaster

This is the final result:

ScriptMaster Java code

FileOutputStream os = new FileOutputStream(printerPort);

PrintStream ps = new PrintStream(os);

ps.println(rawData);

ps.close();

Variables

rawData= Here I enter my raw data (no escape characters necessary)

printerPort= in my case LPT1 (still working on entering a network printer location)

Thanks to fseipel for his invaluable help

Edited by Guest
Link to comment
Share on other sites

This topic is 5100 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.