Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Writing data to lpt port using CreateFile(), is it possi
Message
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Miscellaneous
Thread ID:
00092263
Message ID:
00092299
Views:
24
>I want to write data to lpt1 port to control PCU customer display.
>The only way to do using vfp native commands is "run copy fn lpt1"
>but this is too low for disply control.
>
>So the only possibility is to use API.
>
>I tried the following command:
>
>declare short CreateFile in win32api ;
> string @lpFileName, ; && address of name of the file
> integer dwDesiredAccess, ; && access (read-write) mode
> integer dwShareMode, ; && share mode peab 0
> string @lpSecurityAttributes,; && address of security descriptor
> integer dwCreationDistribution, ; && how to create OPEN_EXISTING
> integer dwFlagsAndAttributes, ; && file attributes
> short htemplfile && handle of file with attributes to copy
>
>declare integer GetLastError in win32api
>
>*typedef struct _SECURITY_ATTRIBUTES {
>* DWORD nLength
>* LPVOID lpSecurityDescriptor
>* BOOL bInheritHandle
>*} SECURITY_ATTRIBUTES
>
>secattr = chr(12) + repl( chr(0), 11 )
>lcPORT = 'COM1'+chr(0)
>
>I= createfile( @lcport, 0 , 0, @secattr, 3,0, 0 )
>J=GETLASTERRor()
>? i,j
>
>But createfile return -1 and getlasterror() returns
>87 ERROR_INVALID_PARAMETER!
>
>How to write data to lpt1 port?
>
>* Win32 api help says:
>*Under Win32, CreateFile() is used to create a handle to a communications
>* resource (for example, COM1). The fdwShareMode parameter must be 0
>*(exclusive access), the fdwCreate parameter must be OPEN_EXISTING, and the
>*hTemplate parameter must be NULL. Read, write, or read/write access can be
>*specified and the handle can be opened for overlapped I/O.
>*ReadFile() and WriteFile() are used for communciations I/O.


Andrus,

I'm a bit confused. You mention LPT1 (Parrelel Port), but the code in your example shows COM1 (Serial Port). I would guess that the low level file functions (FOPEN(), etc.) map directly to the Win API functions for these tasks. Because of this, I don't think that you can open the printer ports using CreateFile(), if FOPEN() fails.

Further, most of the information on this subject that I've read separates communications (modems, etc.) from printing. So my guess is that you can't do this with CreateFile().
George

Ubi caritas et amor, deus ibi est
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform