I did a lot of search and it comes with nothing.Such as below:
c# check printer status
how do i check if a printer is installed and ready using C#?
I tried all the code I found in here but none of them can tell the status of a printer's power is on or off.
The printer is always plugged in and sometimes it's powered off, so I need to make sure it's powered on and then do the print job.
Real need some help here!
question update
the windows still send the print job to print spool when my printer is off, I don't need this, because my client sometimes will deliberately turn off the printer to avoid print something that he don't need. but windows still send it to spool, when my client turn on the printer again, it prints the thing that exactly he want to avoid.
The legacy code uses kernel32.dll's CreateFile function to open LPT1 as a file and directly write string to it to accomplish then printing function. It got no way to know the status of the printer, it just write string to the parallel port. so when the printer is off, the write function got no return, hence the following code after that will never get executed.
hopefully u can understand what I am trying to do here. I want to avoid the situation to print when the printer is off.
Related
Have been struggling with finding a way to stream audio, from a file or web, to a specific output device, not just the default one. Tried using mciSendString and while the open command does accept a device id/filename I haven't found a way to make use of it, am not even sure if this is what I am looking for or not, but considering it says ... or the filename of the device driver am guessing yes(?), but correct me if I am wrong, and this isn't a specify your output device type parameter.
If it is the correct thing then how do you enumerate the installed device drivers, have looked into the IMMDevice interface because it seamed like it could have the file names stored in the registry, but non of the output device registry keys had a driver filename type value entry, or at least I haven't found one.
So my question is, how would you go about streaming audio to a specific output device, it doesn't have to be done through mciSendString, that's just something I looked into as it's one of the most talked about function when it comes to playing audio.
Note: please do not recommend me 3rd party libraries like NAudio, the reason I am asking this question is not get recommendations for libraries, otherwise I would have already used one and would have never written this, have just seen a lot of answers be like: Use {LibName}, it has what you want or something along those lines.
In case what's written is odd or incorrectly worded in places, basically this is what the end goal should be:
Installed Output Devices:
- Output1
- Output2
- Output3
Method For Playing:
//will play x.mp3 through output device 1
PlayAudio(output: "Output1", mp3File: "x.mp3");
//will play x.mp3 through output device 2
PlayAudio(output: "Output2", mp3File: "x.mp3");
//will play x.mp3 through output device 3
PlayAudio(output: "Output3", mp3File: "x.mp3");
You seem to be looking for this API:mciSendCommand()
To set the WaveAudio device (soundcard) used by the Multimedia
Control, you must use the mciSendCommand API. The Multimedia Control
does not directly provide a method to let you set the device used for
playing or recording.
Call mciSendCommand() with MCI_SET & MCI_WAVE_SET_PARMS
setting wOutput to the desired playback device's ID.
Then get IDDevice for mciSendCommand() via
mciGetDeviceID("waveaudio")
Its not 100% clear what wOutput wants, its probably the same ID as returned by waveOutGetDevCaps()
I am just a porter.
Please refer:
https://stackoverflow.com/a/13320137/11128312
https://stackoverflow.com/a/10968887/11128312
I am writing an application in which users needs to make sure that the printer is online/working before they print the invoice.
Most of solutions on the internet point to WMI class to query for printers and their properties including PrinterStatus, PrinterState.. etc.
However that method suffers from the problem of returning Idle status all the time (check the thread here).
So is a way to use WMI to detect if printer is working or not? Or should I use another approach if any exists?
Note:
An alternative way might be using PrintQueue class, but I am not sure if I can detect the exact print jobs sent by PrintDocument class whcih I am using to print.
I like lots of people need to print text ONLY to a dot matrix printer.
I have run the example found here.
And It seems to work but only XP it does not seem to work on Wnidows 7.
I have tested using a generic/Text only printo to file driver as I won't have acces to my printer for a couple of dyas.
On XP it asks me for a file name and then creates a file successfully.
On windows 7 the file gets stuck in the print queue which when you view it just says print-error.
I know the generic printer driver works on win7 beacuse I can print to it from my text editor.
The short term solution is to use a direct connection to the LPT port,Ive not tested this yet, but the final project will running on a machine that has no LPT port. In fact we are shortly going to evaluate a new epson that will connect using USB, so LPT is out of the question.
Before anyone sugessts using graphics, they should know that this is an event logging application that needs to print immediatley one line at a time. It cannot wait for a page of text to be ready before printing.
I've been presented with a task where I'm unfamiliar with concepts.
Task - read printer data stream from a POS system.
Terms mentioned
ESC/P
I have to read values coming from a POS system. My first question is how can you determine the start and end of a print job?
I guess I'm looking for control characters of a printer maybe?
Also, is there a way to simulate this without interrupting the POS?
Anyone know good examples or references they are familiar with themselves?
Learn about Printdocument class
It has BeginPrint, and EndPrint event. You can subscribe to them with an eventhandler.
I'm not familiar with POS system, but i hope it's helpful for your first question.
You first need to know how is the POS system connected to your computer. It could be LPT port, COM port, or USB port. Then you can figure out how to read the data.
But under Windows, LPT may be held by printer spooler. You may need to disable spooler before talking to LPT1 directly.
Normally, it's easier to do these kind of stuff using C++, directly using Win32 API.
I hope someone can point me in the correct direction regarding the
printing problem I am having below:
Setup:
Win CE 5.0
Trying to print from a custom application.
I have written a very simple printing class in my application that
uses the pcl driver and prints to a HP USB printer. The printing
aspect is fine under normal circumstances, but I cannot see an obvious
way to handle error conditions such as no paper in printer etc.
I am doing something like this (general error checking and other
details removed for clarity):
// Get a DC to the printer. If printer isn't powered this will fail -
can print error stating "printer not found" or similar
hdcPrinter = CreateDC(#"pcl.dll", #"PCL Inkjet", #"LPT2:", ref mode);
// Signal the start of a document
StartDoc(hdcPrinter, &docInfo)
// Signal the start of a page
StartPage(hdcPrinter)
// Prepare the page to print/formatting etc
// Finished preparing the page
EndPage(hdcPrinter)
// This is the only page we are printing this time
EndDoc(hdcPrinter)
// Return the printer DC to the system as we are finished with it now.
DeleteDC(hdcPrinter);
Thanks for any help you can provide,
Shilpa
Are you sure get DC succeeds even if the printer is out of paper, jammed, or otherwise not ready?
Once you start the print job, it isn't your problem if the printer runs into a problem. At that point, the OS is supposed to interact with the user and let them know that there is a problem, restart the job if necessary, etc...