Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Problem opening serial port with printer driver attached
Message
General information
Forum:
Visual FoxPro
Category:
ActiveX controls in VFP
Miscellaneous
Thread ID:
01197511
Message ID:
01197769
Views:
18
Hi Paul,

>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).

Agreed, from the command line - but not with the MSCOMM control. In this case the driver is doing exactly what it should - printing.

>
>
>*
>* 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.
>

I agree with all the above, except the MSCOMM.OCX does not require exclusive access - it will take it once it opens the port, just as the generic driver. That Portmon that I pointed out to Bill plays nicely, as it allows another app to join in. Moving the printer driver to another port just opens things up for the control. First one in wins.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform