Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Problem opening serial port with printer driver attached
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Contrôles ActiveX en VFP
Divers
Thread ID:
01197511
Message ID:
01197758
Vues:
14
I don't think it is the driver. For example, with the driver assigned to COM1, I can still send text out that port from the command line (for example, DIR > COM1). I tweaked my code a little bit:
*
* Open the rs232 port
* Load mscomm
*
MCOMMOBJ = CREATEOBJECT("MsCOMMLib.Mscomm")
MCOMMOBJ.COMMPORT = 1
MCOMMOBJ.SETTINGS = "9600,N,8,1"
MCOMMOBJ.PORTOPEN = "TRUE"

DO WHILE .T.

  MCOMMOBJ.output = CHR(29) + CHR(114) + CHR(2)

  INPUTSTRING = ""
  FOR I = 1 TO 10000
    MCOMMOBJ.inputlen = 1
    lnchar = MCOMMOBJ.input
    INPUTSTRING = INPUTSTRING + LNCHAR
    IF (VAL(lnchar) = 13)              && Last char sent by the weight scale is a CR return
      EXIT
    ENDIF
  ENDFOR

  INPUTSTRING = ALLTRIM(INPUTSTRING)
  ? ASC(INPUTSTRING)
    
ENDDO

MCOMMOBJ.PortOpen = .F.
release MCOMMOBJ
RETURN
This will hold the port open, polling the printer for it's cash drawer open status. It will not run at all unless I assign the print driver to another port. If I do that, and then try to run 2 instances of the program, the second gives an OLE exception "the port is already open". If I run one instance of this and then try to redirect text to the port form the command prompt, I get ACCESS DENIED. I think it is MSCOMM.OCX that requires exclusive access to the port.

>The problem is the driver - it opens the port I assume with a CreateFile API call with ShareMode set to 0, effectively locking the port for it's exclusive use.
>
Paul R. Moon
Business Software Solutions
paul@businessoftware.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform