Page 1 of 2
					
				Serial Port connection check
				Posted: Wed Jul 06, 2016 4:07 am
				by ampandya
				Hi 
Is there any way to keep checking if the serial printer is on and connected, as the program we have here freezes if the printer is off or not connected and then the program needs to be end tasked?
Also, Can you help me to set up the USB thermal printer for the receipt?
Many Thanks for your help in advance.
Ankit
			 
			
					
				Re: Serial Port connection check
				Posted: Thu Jul 07, 2016 6:46 am
				by rdonnay
				Why are you using a serial printer?
To use a USB printer:
oPrinter := XbpPrinter():new()
oPrinter:create(<Printer Name>)
SET PRINTER TO oPrinter
			 
			
					
				Re: Serial Port connection check
				Posted: Thu Jul 07, 2016 9:19 am
				by ampandya
				Thanks Roger,
It is a POS system and POS thermal printer that is why i have to use serial printer.
Can we check if the printer is connected before it prints or opening cash drawer?
Thanks
			 
			
					
				Re: Serial Port connection check
				Posted: Thu Jul 07, 2016 10:12 am
				by Wolfgang Ciriack
				Perhaps you can use the COM_ functions of the XBase Tools, f.e.
COM_OPEN and COM_LSR for the Line Status Register.
			 
			
					
				Re: Serial Port connection check
				Posted: Thu Jul 07, 2016 11:28 am
				by rdonnay
				Try using IsPrinter().  This is from the Xbase++ documentation:
Syntax 
IsPrinter( [<cLPT>] ) --> lReady 
Parameters 
<cLPT>
<cLPT> is a character string specifying the print channel whose readiness is determined. By default LPT1 is tested. 
Return 
The return value of IsPrinter() is .T. (true) if the printer (the device) on the specified print channel is ready, otherwise .F. (false) is returned. 
Description 
The environment function IsPrinter() tests the readiness of an output device connected to a print or output channel. The function tests LPT1 to LPT<n> or COM1 to COM<n>. When no argument is specified, the readiness of LPT1 is tested. 
Caution 
When print output occurs using the spooler or print queue, IsPrinter() reports the readiness of the spooler and not of the physical printer. In this situation the function generally returns the value .T. (true). If the actual output device is not ready, the condition is reported by the operating system. 
Example 
// IsPrinter() 
// In the example, a text file is output to the 
// printer. Using IsPrinter(), the readiness of the printer 
// is tested during the print output. If it is not ready, 
// a message is output using Alert() and the user 
// decides how to continue. 
// 
 
   PROCEDURE Main 
      LOCAL nLineLen := 55 
      LOCAL nPageLen := 65 
      LOCAL nPageNum := 1 
      LOCAL nPos 
 
      cString = MemoRead("TEXTFILE.TXT") 
      SET MARGIN TO 8 
 
      DO WHILE Len( cString ) > 0 
         SET PRINTER OFF 
         SET CONSOLE ON 
 
         DO WHILE .NOT. IsPrinter() 
            IF Alert( "Printer is not ready", ; 
                      {"Retry","Cancel"} ) == 2 
               cString := "" 
               EXIT 
            ENDIF 
         ENDDO 
 
         IF .NOT. Empty( cString ) 
            @ 0,0 SAY "Print page number:" 
            ?? nPageNum 
 
            SET PRINTER ON 
            SET CONSOLE OFF 
            ? PadL( "Page: "+Str(nPageNum,8), nLineLen ) 
            ? PadL( "Date: "+DtoC(Date())   , nLineLen ) 
            ? PadL( "Time: "+Time()         , nLineLen ) 
 
            nPos := MlPos( cString, nLineLen, nPageLen ) 
 
            ? SubStr( cString, 1, nPos - 1 ) 
            cString := SubStr( cString, nPos ) 
 
            nPageNum ++ 
            EJECT 
         ELSE 
            EXIT 
         ENDIF 
      ENDDO 
 
      SET MARGIN TO 
      SET PRINTER OFF 
      SET CONSOLE ON 
 
   RETURN
			 
			
					
				Re: Serial Port connection check
				Posted: Mon Jul 11, 2016 4:50 am
				by ampandya
				Thanks Roger,
the isprinter() only check the printer status when the program is starting,
once the program is on and the printer is offline it doesnt check the COM port status? any suggestion?
Thanks
			 
			
					
				Re: Serial Port connection check
				Posted: Mon Jul 11, 2016 5:25 am
				by rdonnay
				I don't understand.
Are you saying that you want to continuously test the printer status, even when not in a print job?
You can start a thread to do this.
Code: Select all
oThread := Thread():new()
oThread:start({||TestPrinter()})
FUNCTION TestPrinter()
DO WHILE .t.
  If !IsPrinter('COM1')
    Msgbox('Printer is offline')
  ENDIF
  Sleep(100)
ENDDO
RETURN nil
 
			
					
				Re: Serial Port connection check
				Posted: Mon Jul 11, 2016 7:36 am
				by ampandya
				Roger,
Thread works for the first form(screen), when i click on any button and it open another page it says "Printer is offline".
once the error starts about the printer then it keeps coming even after the printer is on and working.
The printer is connected to COM1 on my pc and when we use the software on the till it can be COM3 or COM4.
The program knows the port using the P_PORT_RECEIPT which is stored in the dbf.
There is a Drawer connected to this thermal printer, what happens at the moment is when the printer is offline the program freezes, either when opening the drawer or when printing a receipt for the customer.
that is the reason we need to keep checking the printer status!
Thank you
			 
			
					
				Re: Serial Port connection check
				Posted: Tue Jul 12, 2016 9:07 am
				by ampandya
				Hi Roger,
regarding the query:
I have come to know that the previous developer has used WSC4XB and the text to the printer using
nCode = xsioPuts(nPort,@combuf,len(combuf)) 
Thanks
			 
			
					
				Re: Serial Port connection check
				Posted: Wed Jul 13, 2016 12:01 am
				by c-tec
				Hello, 
your sampel shows direct serial printing via RS232 and not with a installed printer driver that eXpress++ use. This is a big difference, here you send text and control characters directly. 
If you want to print this way you should look as Wolfgang wrote to the COM funktinons in the tools. I can help you if needed to convert from MarshallSoft to XBTOOLS.
regards
Rudolf