filozofff Posted April 6, 2007 Report Share Posted April 6, 2007 How can I copy text file to printer port? Quote Link to comment
Mikkel Posted April 6, 2007 Report Share Posted April 6, 2007 The most simple way is probably to call the 'System Exec.vi' with 'command line' set to "copy c:\textfilename.txt lpt1:" (asuming you are using the Windows platform). -Mikkel Edit: How nice, a cross post from the NI forums :thumbdown: http://forums.ni.com/ni/board/message?boar...ssage.id=239093 Quote Link to comment
filozofff Posted April 6, 2007 Author Report Share Posted April 6, 2007 QUOTE(Mikkel @ Apr 5 2007, 10:59 AM) The most simple way is probably to call the 'System Exec.vi' with 'command line' set to "copy c:\textfilename.txt lpt1:" (asuming you are using the Windows platform).-Mikkel Edit: How nice, a cross post from the NI forums :thumbdown: http://forums.ni.com/ni/board/message?boar...ssage.id=239093 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? Quote Link to comment
Chris Davis Posted April 6, 2007 Report Share Posted April 6, 2007 If all you are trying to do is print a text file out, you could use notepad. Just call notepad with a /p option at the command line. notepad.exe /p "c:\logfile.txt" Quote Link to comment
crelf Posted April 6, 2007 Report Share Posted April 6, 2007 You can also just treat the parallel port as a port in VISA and write ASCII characters to it. Quote Link to comment
James N Posted April 7, 2007 Report Share Posted April 7, 2007 QUOTE(crelf @ Apr 5 2007, 10:36 AM) You can also just treat the parallel port as a port in VISA and write ASCII characters to it. Yeah, This is how I do it too. I use it for postscript files. I include a little more error hanlding but this is basically it. http://forums.lavag.org/index.php?act=attach&type=post&id=5420''>http://forums.lavag.org/index.php?act=attach&type=post&id=5420'>http://forums.lavag.org/index.php?act=attach&type=post&id=5420 I have a DLL that works via USB. -James Quote Link to comment
Mikkel Posted April 7, 2007 Report Share Posted April 7, 2007 QUOTE(James N @ Apr 6 2007, 07:15 AM) Yeah, This is how I do it too. I use it for postscript files.I include a little more error hanlding but this is basically it. http://forums.lavag.org/index.php?act=attach&type=post&id=5420''>http://forums.lavag.org/index.php?act=attach&type=post&id=5420'>http://forums.lavag.org/index.php?act=attach&type=post&id=5420 I have a DLL that works via USB. -James 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 Quote Link to comment
James N Posted April 7, 2007 Report Share Posted April 7, 2007 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 Quote Link to comment
crelf Posted April 9, 2007 Report Share Posted April 9, 2007 QUOTE(James N @ Apr 8 2007, 09:05 PM) FWIW, Here's what our guy wrote for network printers. "STOR" (show in the code above) is a raw FTP command, and as long as the printer knows what to do with it (including the "BUFF" for put-it-in-your-buffer-queue), then it just might work :thumbup: QUOTE STOR (STORE) 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 Quote Link to comment
filozofff Posted April 10, 2007 Author Report Share Posted April 10, 2007 QUOTE(crelf @ Apr 8 2007, 01:14 PM) "STOR" (show in the code above) is a raw FTP command, and as long as the printer knows what to do with it (including the "BUFF" for put-it-in-your-buffer-queue), then it just might work :thumbup: 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 Thanks men I didn't find ftp icon in labview 7.0 but I choose tcp icons.It prints. I can send data to printer when I enter prinet IP. Quote Link to comment
Chris Davis Posted April 10, 2007 Report Share Posted April 10, 2007 The FTP icons came from the internet toolkit, it is included with a Developer Suite, and can be purchased seperately. Quote Link to comment
crelf Posted April 13, 2007 Report Share Posted April 13, 2007 QUOTE(filozofff @ Apr 9 2007, 10:27 PM) Thanks men I didn't find ftp icon in labview 7.0 but I choose tcp icons.It prints. I can send data to printer when I enter prinet IP. Please post your code so we can all benefit from it. Quote Link to comment
Rolf Kalbermatter Posted April 13, 2007 Report Share Posted April 13, 2007 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 Quote Link to comment
AdamRofer Posted April 13, 2007 Report Share Posted April 13, 2007 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) Quote Link to comment
Rolf Kalbermatter Posted April 13, 2007 Report Share Posted April 13, 2007 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 Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.