LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Function fopen:(return value == 0(0x0)) EINVAL Invalid argument

handle = fopen("LPT1", "wb"); works just fine in Win98 but I get an EINVAL Invalid argument when I run it in Win2000. I am using CVI 5.0.1. What am I doing wrong?
0 Kudos
Message 1 of 6
(6,960 Views)
Ed,

My first advice in this case would be to move to the low-level IO functions that CVI offers. The reason for this is that fopening a port may not be fully supported in modern operating systems where the IO is protected and needs to be addressed in kernel mode. Here is an example of this:
Reading and Writing to the Parallel Port Using Low-Level LabWindows/CVI outp and inp Functions


To open the port properly in Windows NT/XP/2000 you need to use the port's full "proper" name: \\.\LPT1
Since you need to double back-slash in C the string name should be something like "\\\\.\\LPT1"

Again I suggest that you us
e the CVI functions here I'm attaching a piece of code that allows you to read that port's address dynamically to ensure portability.

I hope this helps.

Regards,
Juan Carlos
N.I.
0 Kudos
Message 2 of 6
(6,959 Views)
Dear colleagues Shawn B and Juan Carlos,
thanks for helping to solve binary writing (using PCL data) to LPT1 from CVI7.0 application.
I was trying to use fopen("\\\\.\\LPT1", "wb") as was adviced. It not helped. Low level functions woere not applicable in my case so I spent some time to find the way how to proceed and succeeded.
Today I want to share with you how I solved binary writing to LPT1 problem.
In place of fopen(....) I applied two functions of CVI:

fp = OpenFile ("LPT1", VAL_WRITE_ONLY, VAL_OPEN_AS_IS, VAL_BINARY);
lprn = fdopen(fp, "wb");
...... PCL function....
fclose(lprn);
These two functions - first from Formatting and I/O Library, second from ANSI C Input/Output Library
works reliably - no more problem in my applications in Windows XP environment for binary printing.
Regards
Kazi Kundrotas
0 Kudos
Message 3 of 6
(6,903 Views)
Thanks for following up on this.

Apprently LPT1 is one of the system reserved files names left over from DOS days and apparently you can still use it in XP. This link here gives a list of all the other names you could use.

They are
CON, AUX, COM1, COM2, COM3, COM4, LPT1, LPT2, LPT3, PRN, NUL
Bilal Durrani
NI
0 Kudos
Message 4 of 6
(6,885 Views)

Hi, I am getting an "Function fopen:(return value == 0(0x0)) EINVAL Invalid argument" error when I am using fopen function.

I am using windows7 Os and Lab-windows/CVI-8.5. Can anyone please help me out in solving this issue. Thank you and kudos in advance.

0 Kudos
Message 5 of 6
(5,132 Views)

Hi,

 

according to this page Windows 7 is not supported for CVI 8.5 - you would need to upgrade to CVI 2009 or later

0 Kudos
Message 6 of 6
(5,128 Views)