Archive for October, 2010

Microsoft POS Library for .NET

Thursday, October 14th, 2010

I’ve been writing a specialised point of sale system for a local business and had to use the POS printer on their till.  Fortunately, Microsoft have a nice library available for .NET that is freely downloadable that deals with most of the hard work of communicating with POS devices.

I was interested in the POSPrinter class.  They do provide a simulator so that you can test things out using the simulated printer, but it doesn’t support anything other than basic plain text, whereas I needed to use formatted text.

POS printers usually use a control language called ESC/POS.  This was developed by Epson originally for their POS printers, but it has become a standard.  Basically, it is mostly a matter of sending plain text, but you can also send certain escape sequences to change settings on the printer.

Fortunately, Microsoft document a lot of this on MSDN, so you don’t need to work it all out from scratch.  There are things like knowing that the main escape sequence is &H1B or 27 (known as ESC) and then a pipe character followed by optional numbers, small letters or symbols followed by a capital letter.  Eg. ESC|#P cuts the paper, ESC|bC is the code to turn on bold etc.

However, you may find it useful to have some sample code…


Imports Microsoft.PointOfService

Public Class POSPrinter

    Public Const ESC = Chr(&H1B) & "|"
    Public Const SetBold = ESC & "bC"
    Public Const SetUnderline = ESC & "uC"
    Public Const SetItalic = ESC & "iC"
    Public Const SetCentre = ESC & "cA"
    Public Const SetRight = ESC & "rA"
    Public Const ResetFormatting = ESC & "N"

    Public Shared Function SetSize(ByVal Size As Integer) As String
        Return ESC & Size & "C"
    End Function

    Public Shared Function GetAndInitPosPrinter() As Microsoft.PointOfService.PosPrinter
        Dim pe As New PosExplorer()
        Dim ppdi = pe.GetDevice(DeviceType.PosPrinter, My.Settings.PrinterName)
        Dim pp As Microsoft.PointOfService.PosPrinter = pe.CreateInstance(ppdi)
        pp.Open()

        pp.Claim(250)

        pp.DeviceEnabled = True

        Return pp
    End Function

    Public Shared Sub ReleaseAndClosePosPrinter(ByVal pp As Microsoft.PointOfService.PosPrinter)

        pp.Release()

        pp.Close()
    End Sub

    Public Shared Sub PrintTest()

    Dim pp As Microsoft.PointOfService.PosPrinter = Nothing

    pp = GetAndInitPosPrinter()

    Dim msg As String = "This is a test" & vbCrLf & SetBold & SetSize(3) & SetCentre & "it works" & SetSize(1) & " pretty well" & vbCrLf & "OK"

    pp.PrintNormal(PrinterStation.Receipt, msg)

    ReleaseAndClosePosPrinter(pp)

    End Sub


One other thing to watch out for is that if you are running any other POS software on the till, such as Microsoft Dynamics POS, then you might need to go into the settings and tell it to share the printer nicely with the other children applications as some POS software tends to be pretty possessive

Also, always make sure that you release and close any POS devices when you are done with them. For some reason when you start using them you need to open them, claim them and then enable them which seems ridiculous overkill to me, but what do I know?

Electricity Monitoring Part 2

Wednesday, October 13th, 2010
This entry is part of a series, Electricity Monitoring»

I previously mentioned that I have an electricity monitor and that I wrote a program for collecting the data and uploading it to a central database.  Actually, since then, Google have launched Google PowerMeter.  Fortunately, their API is freely available and so I have uploaded my data into their system (fortunately this was a fairly straightforward XML upload job) and switched to using the Current Cost software for uploading to PowerMeter.

PowerMeter is fairly good, although it does have some annoyances.  However, between that and the other software that I used to use of my own, I have managed to reduce our daily elecricity consumption from about 23kWh to around 11-14kWh.  We pay 7.57p/kWh, so that translates to an annual saving of roughly £275.  We’ve done this without making any major changes to our lifestyle or habits and it doesn’t involve driving yourself mad over little things.  We’ve also done it without switching to compact fluorescent bulbs which I particularly dislike.

Without doubt, the most significant cost savings came from switching off a second freezer which we had running in our shed and from replacing our faulty fridge with one that works correctly.  However, there were were other things that we’ve done that add up to a fairly large amount of electricity saved over time.

The most useful thing that I did was spent a couple of hours one morning doing an electricity audit – working my way around the house working out how much electricity different things use in different states.  Basically, I did this by unplugging everything until the monitor showed zero constantly and then plugged things back in one at a time.  Be careful when you do this if you decide to – make sure no one else is in otherwise you’ll drive them mad and also don’t take too long over it if you have a fridge and freezer otherwise your food will go off!

I found some interesting things, some of which fit in with what other people say and some are surprisingly not mentioned by anyone.  I went as far as measuring different states for several devices – on, standby and off.  That’s one interesting thing – people don’t mention that a lot of devices do use power and in some cases a significant amount of power when they are off, even if they are not in standby.  I’ll write more about this in future posts.

Entries in this series:
  1. Electricity Monitoring Part 1
  2. Electricity Monitoring Part 2
Powered by Hackadelic Sliding Notes 1.6.5

Companies House Electronic Filing Problems – recent annoyances

Wednesday, October 6th, 2010
This entry is part of a series, companies house problems»

As I mentioned in my previous post, I’ve been doing quite a bit of work for a limited company formation agent over the years and have had to deal with some annoying problems.  Please excuse these rants…

Recently Companies House introduced the ability to do company name changes electronically.  This is a very useful feature, except that the XML schemata that they released for them are wrong – the one for submission contains (or at least contained) a field that shouldn’t have been there and isn’t used for anything, and the one for retrieving responses had no way of getting the updated certificate of incorporation, although this information was actually returned in the response.  I’m not quite sure why they bother publishing specifications if they don’t stick to them!

Entries in this series:
  1. Companies House Electronic Filing Problems Part 1 - Introduction
  2. Companies House Electronic Filing Problems - recent annoyances
Powered by Hackadelic Sliding Notes 1.6.5