View previous topic :: View next topic |
Author |
Message |
oyhan
Joined: 03 Jun 2005 Posts: 21 Location: TURKEY
|
Printing from Pc serial port to parallel port printer |
Posted: Sun Nov 30, 2008 7:50 am |
|
|
Hi
I want to write some character from pc serial port to parallel printer. Mini Thermal Printer has 24 colon and parallel port.
While printer is writing I saw some problem. Printer is not write some data specially after 48th character.
I use hardware flow control that is rs232 DSR pin. While printer buffer is full I want to stop Pc data transmit after printer buffer is emptied.
What is my problem ? Would you help me please for that.
Best Regards...
Code: |
#include <18F452.h>
//#device adc=10
#fuses HS, NOWDT, NOPROTECT, NOCPD, NOBROWNOUT, NOWRTD, PUT, NOLVP
#use delay(clock=20000000)
#use rs232 (baud=9600, xmit=pin_C6, rcv=pin_C7, parity=N, bits=8, ERRORS)
#byte PORTA = 0x0F80
#byte PORTB = 0x0F81
#byte PORTC = 0x0F82
#byte PORTD = 0x0F83
#byte PORTE = 0x0F84
#bit STROBE = PORTA.0 //for paralelle port printer busy_pin output
#bit BUSY = PORTA.1 //for paralelle port printer busy_pin input
#bit DSR = PORTC.2 //for rs232 hardware flow control
#byte RCREG = 0x0FAE
#byte RCSTA = 0x0FAB
#bit RCIF = RCREG.5
#bit OERR = RCSTA.1
#bit CREN = RCSTA.4
#define LF ('\n')
#define CR (0xD)
char b;
int1 rcvd_uart = 0;
#int_RDA
void RDA_isr(void)
{
DSR=1; // Data Set Ready is passive
b=RCREG;
rcvd_uart = 1;
}
void main()
{ setup_adc_ports(NO_ANALOGS); setup_adc(ADC_OFF);
setup_spi(FALSE); setup_psp(PSP_DISABLED); setup_wdt(WDT_OFF);
setup_timer_0(RTCC_OFF); setup_oscillator(False);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
SET_TRIS_A( 0b10000010 ); SET_TRIS_D( 0x00 ); SET_TRIS_C( 0b10001011 ); SET_TRIS_E( 0b11111 );
PORTD=0x00;
STROBE=1;
DSR=0; // Data Set Ready is active
putc(LF); putc(CR);
Delay_Ms(1000);
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
while(true)
{
if(rcvd_uart)
{ rcvd_uart = 0;
PORTD = b ;
while (BUSY);
STROBE=0;
delay_us(1);
STROBE=1;
DSR=0; // Data Set Ready is active
}
}
} |
|
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Sun Nov 30, 2008 10:28 am |
|
|
With PC RS232 hardware handshake, CTS rather than DSR is the signal to be used to signal peripheral busy/ready state. |
|
|
oyhan
Joined: 03 Jun 2005 Posts: 21 Location: TURKEY
|
|
Posted: Sun Nov 30, 2008 3:47 pm |
|
|
Hi again..
I checked CTS RTS signal but they are same. No difference.
My code lose some characters. What is my code problem? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Nov 30, 2008 3:56 pm |
|
|
Post the manufacturer and part number of your printer. |
|
|
oyhan
Joined: 03 Jun 2005 Posts: 21 Location: TURKEY
|
|
Posted: Sun Nov 30, 2008 4:14 pm |
|
|
For example If I Send some characters with a file from pc lpt1 port I do not see any problem.
"c:\>copy lpt1 test.txt" this printer is write easily and true.
My printer information:
CARD STAR
Thermodrucker
Artikel-Nr.:0810
celectronic |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Nov 30, 2008 4:23 pm |
|
|
Post a link to the webpage that has a data sheet or manual for the printer. |
|
|
oyhan
Joined: 03 Jun 2005 Posts: 21 Location: TURKEY
|
|
Posted: Mon Dec 01, 2008 3:24 pm |
|
|
How can I do that? For my problem.. |
|
|
Ttelmah Guest
|
|
Posted: Mon Dec 01, 2008 3:40 pm |
|
|
I'd suggest you try 'early stopping'.
CTS usually affects the daa being loaded to the transmission, rather than the UART directly. If you are running with a normal modern UART, a few characters actually 'in transmission', can still be sent after you say it is not 'clear to send'.
So, use an interrupt driven serial buffer, like EX_SISR. Have this using a buffer of (say) 64 characters, and signal it is not clear to send, when this gets to perhaps 3/4 full (48 characters). Only re-enable the comms, when the buffer empties.
This is the 'normal' strategy used in such handling, and should avoid loss of characters.
In your case, at the least, the character in the outgoing shift register, and possibly a couple in the incoming shift register and latch, could all arrive after the line activates. Possibly more.
Best Wishes |
|
|
|