Jump to content

How can I copy text file to printer port?


Recommended Posts

QUOTE(Mikkel @ Apr 5 2007, 10:59 AM)

I wrote that command line but it doesn't print. I wrote Cmd/C"copy C:\plot.pxt >lpt2:" It prints just "1file(s)copied. DO you any advise? I need help please..

QUOTE(filozofff @ Apr 5 2007, 11:10 AM)

I wrote that command line but it doesn't print. I wrote Cmd/C"copy C:\plot.pxt >lpt2:" It prints just "1file(s)copied. DO you have any advise? I need help please..

Yeah .I wrote ni.forum my problem. Do u think different solution from there?:)

Link to comment

QUOTE(James N @ Apr 6 2007, 07:15 AM)

Never did it this way, nice to see an example.

Are you sure you need the call to 'VISA Configure Serial Port.vi'?

Doesn't it work if you exclude this call?

-Mikkel :)

Link to comment

I don't know if it will work without the config VI. Good possibility though.

I'll give it a shot in the next couple days as I bring up the next tester.. I take that back.. all the new stuff is equiped with USB only. A coworker wrote an VI for networked printers also, btw.

-James

Link to comment

STOR <SP> <pathname> <CRLF>

This command causes the FTP server to accept the data transferred via the data connection and to store the data as a file at the FTP server. If the file specified in
<pathname>
exists at the server site, then its contents shall be replaced by the data being transferred. A new file is created at the FTP server if the file specified in
<pathname>
does not already exist.

Notes:

<SP> = Space ASCII Character

<pathname> = NotAPath - As you can see from the code JamesN posted, the <pathname> is set to <NotAPath>, so the raw text is tranferred instead.

<CRLF> = CarriageReturn + LineFeed ASCII Characters

Link to comment

Link to comment

Another way is this. It is however Windows only and uses the Windows GDI to print the text to any installed Windows printer.

Strictly taken it is not sending the text to the printer at all, but instead renders the text through Windows GDI and sends the resulting image to the printer.

It's a first attempt for some application I did recently where the Report Toolkit installation was no option. So I'm sure there are a few rough edges and optimizations which could still be improved.

Rolf Kalbermatter

Link to comment

QUOTE(rolfk @ Apr 12 2007, 09:02 AM)

Another way is this. It is however Windows only and uses the Windows GDI to print the text to any installed Windows printer.

Strictly taken it is not sending the text to the printer at all, but instead renders the text through Windows GDI and sends the resulting image to the printer.

The most efficient solution I found (no handle leaks or memory leaks, unlike VISA in LabVIEW 6.1) is to open a reference to the "lpt1" "file" and write to it. This is only used for raw text as far as I am aware, and it's definitely a Windows-only solution, but it works fantastically.

No silly CMD stuff is necessary when the Windows API is everything you need.

The attached file is written in LabVIEW 6.1 but it will work in all versions.

Windows APIs used (pseudocode):

Kernel32.dll:

handle = CreateFileA("lpt1", GENERIC_WRITE=0x40000000, 0, NULL=0, OPEN_EXISTING=3, FILE_ATTRIBUTE_NORMAL=0x80, NULL=0)

Error_if_zero = WriteFile(handle, string_buffer, string_length(string_buffer), &number_of_bytes_written, NULL=0)

Error_if_zero = CloseHandle(handle)

Link to comment

QUOTE(AdamRofer @ Apr 12 2007, 12:14 PM)

The most efficient solution I found (no handle leaks or memory leaks, unlike VISA in LabVIEW 6.1) is to open a reference to the "lpt1" "file" and write to it. This is only used for raw text as far as I am aware, and it's definitely a Windows-only solution, but it works fantastically.

No silly CMD stuff is necessary when the Windows API is everything you need.

The attached file is written in LabVIEW 6.1 but it will work in all versions.

Windows APIs used (pseudocode):

Kernel32.dll:

handle = CreateFileA("lpt1", GENERIC_WRITE=0x40000000, 0, NULL=0, OPEN_EXISTING=3, FILE_ATTRIBUTE_NORMAL=0x80, NULL=0)

Error_if_zero = WriteFile(handle, string_buffer, string_length(string_buffer), &number_of_bytes_written, NULL=0)

Error_if_zero = CloseHandle(handle)

Well it's a great way. And using the VI's from the large_file OpenG library would be also possible. Basically by wrapping the returned handle from CreateFile into a LabVIEW bytestream file refnum you could use the standard WriteFile primitive and CloseFile primitive.

Of course this has a subtle chance of breaking in future LabVIEW versions but it is using all documented External Code Reference functions and should therefore remain working for quite some time. My prior approach does have one advantage of being able to print text to any Windows printer that can represent a bitmap device (that would exclude plotters for instance but I'm not sure Win32 still supports them at all. Win3.1 GDI did however.)

It is to bad that FMOpen() seems to test the first path element to be only one character, otherwise no DLL call would be probably necessary at all under Windows.

Rolf Kalbermatter

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.