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.
Related
I have a USB mass storage device that I encrypt with TrueCrypt. When I connect it to Windows, it asks to format. Using TrueCrypt reveals its contents, as expected.
How can I read the first 100 bytes of that device?
I know the bytes will not make sense because they're encrypted but I want to read them in order to create a checksum.
Did this on the top of my head. But is should work.
public static long getBytes(string letter)
{
ManagementObject disk = new ManagementObject(String.Format("win32_logicaldisk.deviceid=\"{0}:\"", letter));
disk.Get();
return long.Parse(disk["Size"].ToString());
}
EDIT: Tested it and changed int to long. It works.
What solutions have you considered so far? Does your application figure out when the USB device is plugged in or unplugged?
As far as I know, there's no native support in .Net for directly accessing USB devices. I had to use libraries such as LibUsbDotNet (http://sourceforge.net/projects/libusbdotnet/) or SharpUSBLib (http://www.icsharpcode.net/OpenSource/SharpUSBLib/) There were pros and cons to both in terms of samples, documentation etc. I am sure you will be able to find what suits you best.
In one case I was able to connect to the device using WMDC, once the connection was established I used OpenNETCF RAPI library to read from / write to the device.
Here's another excellent resource that I had found useful when I wrote an application that needed to interact with a USB device (a barcode scanner).
http://www.developerfusion.com/article/84338/making-usb-c-friendly/
There was a good resourceful discussion to a similar question here on Stackoverflow : Working with USB devices in .NET
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.
Could anyone please give me any idea as to where to start my coding in order to get data from OPOS(Datalogic Magellan device) weighting and barcode scanning in C#?? For example, what library and what function I should be using for this case. I am clueless as I have already spent numerous of hours searching for an answer online. Not even came close online.
I don't know any api that I can use to get the weight and barcode for the usb device into my C# program.
I am currently using Datalogic scale. I tried the build-in windows reader but it didn't read in any data from the device.
First off, I used the Microsoft.PointOfService library which can directly create connection to most of the opos base machine. And make sure you have your Logical Device Name right! Very Very important. This is NOT any normal name you found in your regedit, it MUST be define manually by yourself inside the opos adk program that you installed along with the opos machine.
Then you can pass in the name as usual in your C# program.
For example: you set USB_Scale as your logical device name inside OPOS program
in C#
this.myDevice = explore.GetDevice("Scale", "USB_Scale");
Note: Make sure you set claim to 1000; It might not work if you didn't do so.
Also : this.myScale = ((Scale)explore.CreateInstance(myDevice)); <- this might help~
The rest is just straight forward.
I'm creating a postscript printer for windows 7 which will accept print jobs and forward them to real printers. It will be shared in the LAN and can receive print jobs from LAN computers. I want to find out from which computer a print job came from before forwarding them to a printer. How can I do this? Is the details available in the print job itself?
Thanks
Take a look at the GetJob and EnumJobs spooler api functions. They both return one of two structures, JOB_INFO_1 or JOB_INFO_2. Each structure contains a pMachineName field, which is the name of the machine that created the print job. You may find the following links from pinvoke.net useful.
http://www.pinvoke.net/default.aspx/Structures.JOB_INFO_1
http://www.pinvoke.net/default.aspx/winspool/EnumJobs.html
Alternatively, you may also want to look into using WMI and the Win32_PrintJob class. Specifically the HostPrintQueue property.
We are assigned to develop an application using C# that can transfer print jobs between printers. I have looked on the Windows API, and System.Printing namespace but I can't find a class or function that can do this. Is there a free library out there that is suitable for this? How will you do this using .Net or the Win32 API?
If nothing exists in the Win32 API, then there will be nothing in .NET.
Unless the printer drivers are identical then you may have problems because the printer jobs go through some processing by the driver before entering the queue.
Have you considered a single queue with multiple printers associated with it (this giving more capacity and redundancy in case of printer failure)?
Isn't this a problem of load-balancing/routing a particular job to the least busy printer?
I'm pretty sure you can just CopyFile a SPL file to a new printer port if it's the same driver. If you print in EMF, you may be able to go across different drivers.
The port names might be a bit tricky depending on how the printer(s) are attached. WinObj and the rules of dev naming will be handy for tracking it down.