Should I be using VB.net 2010 PointOfService.POSPrinter class for simple job on POS printer?

StackOverflow https://stackoverflow.com/questions/8762465

  •  14-04-2021
  •  | 
  •  

Domanda

This is a big-picture question... but I also have details on the problem I am experiencing after attemping to use POS. I have been googling for a couple of days... and I must say, I am having a hard time sorting thsi out.

So, I need to print a simple receipt to my EPSON-TM-T88V thermal POS printer with VB.NET 2010 on XP (eventually to run on Windows embedded POSReady) via USB.

All I need to print is some text and a logo. I have my logo stored on the printer. So, I need to use Epson's ESC/POS commands.

So, does it make sense to use Microsoft.PointOfService? Seems like a lot to go through to send some escape sequences to a printer!

Apparently, the PointOfService system has not been updated to work seemlessly with VB.net 2010 (details below) That is why I wonder if I am taking the wrong path.

========================

IF this is the right path...here is what I did and where I am stuck.

For people trying to us the PointOfService classes in VB 2010: First you need to download and install the POS.net (Microsoft.PointOfService) - free download MS. Then you need to add references in your vb.net project. When you try to run it, you will probably get an error something like this:

{"This method explicitly uses CAS policy, which has been obsoleted by the .NET Framework. In order to enable CAS policy for compatibility reasons, please use the NetFx40_LegacySecurityPolicy configuration switch. Please see http://go.microsoft.com/fwlink/?LinkID=155570 for more information."} There are links all over on how to fix this... you need to fix your config files. Here is one of them: http://social.msdn.microsoft.com/Forums/en-US/posfordotnet/thread/9b3e6f34-de26-4a36-ab8e-13722f53b9e4/ For 2010, apparently you need to fix in QTagent32.exe.config and QTAgent.exe.config.

OK, so I did all this. BUT The CAS policy error came up again, with a different stack tace way after I applied the recommended fixes. on the first call into the system I get the CAS error....

at Microsoft.PointOfService.Management.Explorer.CreateExplorer()
   at Microsoft.PointOfService.PosExplorer.LoadExplorer()
   at Microsoft.PointOfService.PosExplorer.Initialize()
   at Microsoft.PointOfService.PosExplorer..ctor()

Any further ideas? Thank you :-)

È stato utile?

Soluzione

I do not need to use the whole POS package just to print to a POS printer. Instead, just write bytes directly to the printer. This worked for VB.net 4.0 with the Epson POS/ESC escape sequences.

Here are instructions: http://support.microsoft.com/kb/322090

Basically, I used the rawprinterhelper class. Then you can send the escape sequences directly.

I did get a PInvokeStackImbalance error. The rawprinterhelper needs this one change to work. The code needs to look like this (the pd parameter is integer instead of long):

<DllImport("winspool.Drv", EntryPoint:="OpenPrinterW", _
      SetLastError:=True, CharSet:=CharSet.Unicode, _
       ExactSpelling:=True, CallingConvention:=CallingConvention.StdCall)> _
   Public Shared Function OpenPrinter(ByVal src As String, ByRef hPrinter As  intPtr, ByVal pd As Integer) As Boolean
  End Function

http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/13fce4f7-e779-4ce1-b421-1de6007595fe/

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top