Pages: [1]   Go Down
Author Topic: Printing in landscape through ethernet shield on port 9100  (Read 462 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 11
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi everyone,

I'm using a Arduino mega with a modified ethernet shield to send data to a printer (actually through a Jetdirect module)...

It's working quite fine except i didn't find the way to setup the printer an print in landscape instead of portrait.

Is anyone had an idea about it ?

Thanks
« Last Edit: April 07, 2011, 03:08:28 am by MHDfo » Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 170
Posts: 12483
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


Interesting, can you post your code?

HP printers have escape codes to set attributes:  Landscape = 27 38 108 49 79 (decimal values

A complete (printer dependant) list can be found on: - http://www.dragon-it.co.uk/links/hp_pcl_codes.htm

Rob



Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

0
Offline Offline
Newbie
*
Karma: 0
Posts: 11
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

All the code is based the pachatube tutorial and on someone's else work found on the net  but i didn't note whom and where... sorry for that

I just post here the code for printing something over 9100 port. My full  program is useless for people I think.



/!\ you need  PCL 5E compatible printer or something like that ( Meaning printer which use proprietary protocol should not work)




/*****************************************************************************************/
/*              test                                                                     */
/*      mac de la carte    byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0xXX, 0xXX };          */
/* */
/* */
/*****************************************************************************************/


#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0xXX, 0xXX };
byte ip[] = { 192, 168, 1, XXX }; // IP of our arduino
byte server[] = { 192, 168, 1, YYY}; // IP of our printer

Client client(server, 9100);

long lastConnectionTime = 0;       
boolean lastConnected = false;     
const int postingInterval = 30000; 




void setup()
{
  Ethernet.begin(mac, ip);
  Serial.begin(9600);
  delay(1000);

 
 
 
 
void loop()
{
 
  // if there's incoming data from the net connection.
  // send it out the serial port.  This is for debugging
  // purposes only:
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }

  // if there's no net connection, but there was one last time
  // through the loop, then stop the client:
  if (!client.connected() && lastConnected) {
      client.stop();
  }
 
 
   // if you're not connected, and ten seconds have passed since
  // your last connection, then connect again and send data:
  if(!client.connected() && (millis() - lastConnectionTime > postingInterval)) {
    sendData();
  }
  // store the state of the connection for next time through
  // the loop:
  lastConnected = client.connected();
}




void sendData() {
    // if there's a successful connection:
    if (client.connect()) {
    Serial.println("connecting...");
    client.println("Hello Word");
    client.stop();
    // note the time that the connection was made:
    lastConnectionTime = millis();
  }
 
 
  else {
    // if you couldn't make a connection:
    Serial.println("connection failed");
    client.stop();
  }

}
« Last Edit: April 07, 2011, 05:10:48 am by MHDfo » Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 11
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have try different way with differents representation but my main problem is how to give parameters to printer.
The xxx.print() , xxx.println() and xxx.write() are just print like other text.

The printer didn't interpret the code, it just print it out.

Any clue for me ?
Logged

Ontario
Offline Offline
God Member
*****
Karma: 20
Posts: 835
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Maybe try this way....

Code:
    Serial.println("connecting...");
    client.print("\033&l10");    // [ESC] & l 1O to go to Landscape
    client.println("Hello Word");

I am actually used to controlling landscape/portrait via a job ticket that comes before the main print job.  This escape sequence is pretty old-school, but likely works.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 11
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for answering but unfortunately it doesn' t work. Anyway that the first time the printer don't print the code.

It prints : "ello Word"

with the write() or print()
println() just print "Hello Word" but still in portrait mode at least the printer seem to read something

I will try some other combinaison but other ideas are welcome
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 170
Posts: 12483
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You might test printing the escape sequences byte per byte: 27 38 108 49 79 (decimal values

printLandscape()
{
  print((char)27);
  print((char)38);
  print((char)108);
  print((char)49);
  print((char)79);
}

followed by print("hello");

get the idea?

What exact printertype is it?
Its interpreter might slightly differ.. or just not support landscape;    URL manual?
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Pages: [1]   Go Up
Jump to: