CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Sending control codes to a thermal printer....

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
John Morley



Joined: 09 Aug 2004
Posts: 97

View user's profile Send private message

Sending control codes to a thermal printer....
PostPosted: Tue Jan 10, 2012 11:18 am     Reply with quote

Hi All,

I'm having some trouble sending control codes to a thermal printer. The documentation says I need to send the following:

ASCII: ESC 7 N1 N2 N3

or

Decimal: 27 55 N1 N2 N3


I tried using this code:

Code:

     fputc(27, Printer);
   fputc(55, Printer);
     fputc(7, Printer);
        fputc(HeatTime, Printer);       //Default 80 or 800us
   fputc(HeatInterval, Printer);   //Default 2 or 20us


but that didn't work, it just caused the print to output some garbage.

I also tried:

Code:

   fprintf(Printer, "%u", 27);
   fprintf(Printer, "%u", 55);
   fprintf(Printer, "%u", 7);
   fprintf(Printer, "%u", HeatTime);
   fprintf(Printer, "%u", HeatInterval);


with the same result.

So, what is the proper method to send these types of control codes?

Thanks,

John
_________________
John Morley
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Jan 10, 2012 1:17 pm     Reply with quote

I would check the baud rate and other aspects of the RS-232.
If you need more help, post a link to the website for the printer.
John Morley



Joined: 09 Aug 2004
Posts: 97

View user's profile Send private message

PostPosted: Tue Jan 10, 2012 1:43 pm     Reply with quote

Hi,

It's not a connection or baud rate issue as I'm able to successfully print text data to the printer. There are several configuration settings, however, such as the amount of time the print head heater is active that I don't seem to be able to change.

Here is a link to the printer manual on the SparkFun website: http://www.sparkfun.com/datasheets/Components/General/A2-user%20manual-1.pdf

The command I am trying to use, 'Control Parameter Command', is found in section 5.2.9 of the manual.

Thanks!

John
_________________
John Morley
RF_Developer



Joined: 07 Feb 2011
Posts: 839

View user's profile Send private message

PostPosted: Wed Jan 11, 2012 3:06 am     Reply with quote

fputc() should have worked. Its the normal way to send out arbitary codes/characters to a named serial stream. Your first code *should* have worked, unless there is some other problem. What is your #use rs232 line?

RF Developer.
Ttelmah



Joined: 11 Mar 2010
Posts: 19341

View user's profile Send private message

PostPosted: Wed Jan 11, 2012 4:05 am     Reply with quote

Your data is wrong.
Page 10 of the manual gives the command to set the times, as:
Code:

ESC 7 n1 n2
Set printing para. Heat & break time, max heat dot

The code for this is:
Code:
   
   fputc(27, Printer);
   fputc('7, Printer);
   fputc(HeatTime, Printer);       //Default 80 or 800us
   fputc(HeatInterval, Printer);   //Default 2 or 20us


or
Code:

   fprintf(Printer,"\x1B7%c%c%c",HeatTime,HeatInterval);

Note the '%c', not %u. The former sends the single ASCII character, the latter the sequence of characters representing the number in decimal (not what is needed).

You are currently sending ASCII '7', and also the character 7, which is why it doesn't work....

Best Wishes
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group