HP un2430 and Windows 10 CTP: don’t hurry to install

CTP releases as is, don’t expect that everything will work perfectly. That would be a perfect Windows world. The preview system check is recommended to remove HP Protect Tools, and doesn’t complained any other things.

After the Windows 10 CTP (Build 9926) installation the HP un2430 card simply refused to work. Its recognized by the system, just can’t connect with it, because simply it can’t turn it on. Got disabled in the Airplane Mode.

Installing the device driver made things worst. After installation and reboot there were no more Mobile Broadband and GPS disappeared to. Uninstalling and restarting the system at least enabled the GPS, which is working perfectly fine.

Uninstalling and installing the device doesn’t help either. 

un2430 10 ctp

Be careful with the installation!


We –die hard Microsoft tech fans- already drunk about the Windows 10 Briefing event’s lots of cool stuff, could lead posts about the new stuffs and codes… These all made me think about my blog. Which kind of left half dead more than a year ago… running basically in zombie mode. Life and especially job can be demanding. Oh well, developers can run on coffee and pizza for a long period of time. Theory proven. Did my usual Microsoft Certification, and dealt with issues that life threw to me.

Although I not a huge fan of write a blog about things, which are written in thousand times, will try to fill my blog with relevant content about development and tech gadgets. Recently spending a good amount of time on Microsoft Virtual Academy. Obviously being a developer is equals lifelong learning, at least if someone wants to be up to date as possible.

So have my plans for this year, contains another few certification, and well more active blogging.

Reset (source: xkcd.com)


Don’t forget: Chuck Norris can compile syntax errors.

Windows 8.1 on HP8460p, aka “Highway to the Hell”

Aka when something is newer, it doesn’t mean it’s automatically better.

I hope sharing my story will save a big amount of hair and nerve and of course sanity for others.

My story dates back when I was brought the Windows 8 upgrade key. Some can remember the mess around that too. So at the beginning of time, after I brought the upgrade key, not so far later I upgraded my notebook too, installing an SSD instead of HDD, and I was able to perform a clean install, use the activate via phone options. I was happy back then. With the SSD I received a free copy of Windows 8 Pro as a gift. Not had an idea about it’s usefulness… for a while, it just collected the dust in my shelf.

“Few” weeks ago, Microsoft pushed it’s new Windows 8.1 out. It’s a free upgrade for the Windows 8 owner’s trough the store. At that point it’s clearly visible that is a bit insane way of upgrade, certainly in enterprise level. Firstly my tablet received it, almost without any problem, except the display driver is messed up, and it’s always crashing… I tried to install it to my notebook (HP 8460p) via the store. It downloaded, then kindly asked to remove HP Protect Tools and of its components. After I did what was asked for, the installation went fine. Later I found new versions of HP Protect Tools and a few new drivers for a few components. The Protect Tools is working fine, but after a little while the HP un2430 driver is messed up my WWAN connection, and finally it simply refused to connect. My WLAN connection did the same thing. Not mention the display drivers again. When my notebook was unplugged, de display started to flicking. Well known display driver problem.

I decided to do a clean install. I checked on the net, it stated its possible. Before that, I did some install to collect the proper divers and test their behavior on Windows 8.1. After I did all that, I did a big mistake, didn’t backed up my activation. Simply format my drive and reinstalled. Then I tried to activate it. Of course, it’s not worked. I tried via phone, but it not worked either. Okay, that’s bad…

Let’s try again: clean install of Windows 8, register it, upgrade it, backup the activation, do the clean install… It doesn’t worked either. Simply wasn’t able to activate the Windows 8, with the key what I did before. Probably, because it’s an upgrade key, and Microsoft won’t sell anymore upgrade according to the news.

So, I dusted of another Windows 8 version, installed, activated, upgraded to Windows 8.1 activated it. Took a big risk, did a clean install, and reactivated. I installed without a key, then after the installation I gave the key.  It worked, and now living kind of happily, and reinstalling, everything, a bunch of new driver a few old, since the new ones simply refuse to work.

Consequences: be careful if you trying to do a clean install with a Windows 8 upgrade key. Personally, I not recommend it. If your key is not an upgrade key, it should work.

HP’s softpack’s that’s working with Windows 8.1:

sp57879                HP Hotkey support.
sp52211                Good old LSI HDA Modem
sp63779                Synaptics TouchPad Driver
sp63565                Alcor Micro Smart Card Reader Driver
sp63637                JMicron Media Card Reader Driver
sp63221                Sierra Wireless driver for HP un2430
sp63661                Intel Management Engine
sp63453                Broadcom Bluetooth Driver for Microsoft Windows
sp63881                Intel 82579LM and 82579V Gigabit Ethernet Driver for Microsoft Windows
sp63219                HP Wireless Hotspot Software (still sometimes spin up unnecessarily the CPU)
sp63798                Validity Fingerprint Sensor Driver
sp63727               HP ProtectTools Security Manager (yes, its’s work with 8.1 😉 )
sp63709                Computrace for HP ProtectTools
sp63844                Device Access Manager for HP ProtectTools

I downloaded the Display, the RAID, and the Chipset driver from Intel Download center.

*Little upgrade, since some upgrade arrived to Calendar, it started behaving bit funky, means its messing up the colors and selections. Seems, MS made something wrong… additional to the always problematic display drivers. I have problem with it on my tablet to, its also running Win 8.1, but the display driver is regularly crashing.

C# and ABB OPC AC 800M OPC Server – Things, what I learned.

Recently I had to work with a ABB AC 800M OPC server. OPC servers has their own challenges, so I thought I will share, a few key points, what I learned.
First of all, there are few kind of OPC servers out there, and they support different ways to communicate them. Some of are supporting UA, some are only DA, AE and HDA.
The biggest mistake was, that I thought, they will work in the same way. In fact, they are not! They have the same basics of communication, even, the same code can work very well, but it leads to big
Because at the development time, I haven’t access the same OPC server with the same control logic on it, I needed something to test my code. I found a free OPC Server from Matrikon, which was able to set a few variables, and randomly changing items. The project required client-server architecture, so I used WCF to bridge it. At the start of the project the main goal was to read variables. But surprisingly the penultimate day, got news; that my program need to be able to give control commands either. Since that time, my service was finished and tested; I didn’t want to touch it. I made a separate service, to be responsible for commanding. Sadly, at that time I was able to test it only with Matrikon OPC server, not with the ABB, which one is the production. My test went fine, and I needed only one night to rewire my program, thanks for the design logic which I chosen at the beginning. After it, at the real life test was an epic fail. As I mentioned OPC servers can behave differently. My system was able to read the data’s, but want able to control the process. At the first sight, my control service hasn’t enough privileged to connect the OPC server, but that was easy to solve. Bigger surprise was after the connection the ABB OPC server refused to accept the variables that I give them, even if they was in the correct type. Figured out, with IIS hosted WCF service, I will not able to control the production process, neither matter which kind of type conversions I use nor from the access rights of the service. Went back to the core, and changed a few things, first of all, I trashed out the IIS hosted WCF services and changed them to Windows Service hosted WCF service, finally only one service was responsible to read and write the OPC tags. That’s worked well in my test environment and also the production environment.

Finally comes a few lines of code. I used OPC .net API. I used the DA mode, so codes are related to that.
For discovering OPC servers, there can be done via ServerEnumerator, with the help of OpcEnum service, so make sure it’s running, or you will get an exception.

Opc.IDiscovery discovery = new OpcCom.ServerEnumerator ();
Opc.Server[] localServers = discovery.GetAvailableServers (Opc.Specification.COM_DA_20);
foreach (Opc.Server found in localServers)
 txtServers.AppendText (string.Format ("\r\n{0}", found.Name));

For connecting to the server, use the Server class. It will require a Factory class, and the URL of the server. You can check the connection with the IsConnected property. In this example the URL came from the result of the discovery.

private void ConnectToServer (Opc.URL url)
 server = new Server (new OpcCom.Factory (), url);
 server.Connect ();

You can list the available items:

Opc.ItemIdentifier itemId = null;
BrowsePosition position;
BrowseFilters filters = new BrowseFilters () { BrowseFilter = browseFilter.all };
BrowseElement[] elements = server.Browse (itemId, filters, out position);
foreach (BrowseElement beItem in elements)
{ ... }

With giving a null as an initial ItemIdentifier, the server will give back its items, but be aware, it will list only the first level; items can have more child elements, check with the HasChildren property.

For change notification subscription, you need the tags, which you want to monitor.

Subscription groupRead;
SubscriptionState groupState = new SubscriptionState ();
groupState.Name = "Group1";
groupState.Active = true;
groupState.UpdateRate = updateRate;
groupState.Deadband = 0; // The minimum percentage change required to trigger a data update for an item.
groupRead = (Subscription) server.CreateSubscription (groupState);
groupRead.DataChanged += new DataChangedEventHandler (groupRead_DataChanged);

Item[] itemsYouWantToRead = new Item[n]; //n number of OPC tag
groupRead.AddItems (itemsYouWantToRead);

Although Subscription.AddItems expect an array, it’s still easier to start with a List fill the list with the items, new Item(){ ItemName = tag }; than convert it to an Array. Of course you can remove items from monitoring with the Subscription.RemoveItems, only one difference, which is waiting for an ItemResult array, but the principles are the same, you manage the items trough ItemName. When you add to the subscription, you also get an ItemResult collection, when you remove items you get an IdentifiedResult array, worth to check it.

Finally, to give work with controlled items, you need to change the related item’s value.

ItemValue testWrite = new ItemValue ();
testWrite.ItemName = itemOpcTag; 
testWrite.Value = changeValue;
List<ItemValue> itemsToWrite = new List<ItemValue> ();
itemsToWrite.Add (testWrite);
server.Write (itemsToWrite.ToArray ());

Item subscribtion or simple item read will return an ItemResult array. You can iterate through it. It’s worth check out the result. There are the Quality object, which will show “good” if the given value considered good, or will give some meaningful string, considered about the returned value. Also, worth check out the ResultId, which will start with an “E_” if there are some error happened, but usually the Quality which will provide more information. Even if you try to read a non existing tag, you will get an S_OK for ResultId, but the Quality will show, that item is not exist. It’s simple enough to use them on the ResultId.ToString() and Quality.ToString(). Although writing an item and removing from the subscription will result a different kind of array, you can still check the ResultId.
I don’t think, that I should mention here, like anywhere else, the importance of the log files! It can save you from trouble, like one case on this project. The production process was behaved irregularly, and the logs showed, that all of my commands and results was fine, just was some undocumented OPC tag, which I should give to the OPC server, but it wasn’t in the documentation, so saved our collective…

Search for duplicated files using C# and LINQ

Over the years I downloaded, copied, moved around my files, sometimes I made lot of copies, or put them in different directories. And now, there is a time, to clean up some duplicates. I took the easy way, quickly created a small application, which filtering my drive based on file name and length.
The solution is easy, first I create a FileInfo list, fill the list with FileInfo’s. I walk through the directory tree with recursion, and not bothering myself with permission violation. Than search for duplicates, than I create a file with possible duplicates.
Here is the basic code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Security;
using System.Security.Permissions;

namespace ConsoleApplication1
    public class DuplicateFileFinderClass
        public static List<FileInfo> files = new List<FileInfo> ();
        public static void ListDrive (string drive, bool enumerateFolders)
                DirectoryInfo di = new DirectoryInfo (drive);
                foreach (FileInfo fi in di.EnumerateFiles ())
                    files.Add (fi);

                if (enumerateFolders)
                    foreach (DirectoryInfo sdi in di.EnumerateDirectories ())
                        ListDrive (sdi.FullName, enumerateFolders);


            catch (UnauthorizedAccessException) { }

        public static void ListDuplicates ()
            var duplicatedFiles = files.GroupBy (x => new { x.Name, x.Length}).Where (t => t.Count () > 1).ToList ();

            Console.WriteLine ("Total items: {0}", files.Count);
            Console.WriteLine ("Probably duplicates {0}", duplicatedFiles.Count ());

            StreamWriter duplicatesFoundLog = new StreamWriter ("DuplicatedFileList.txt");

            foreach (var filter in duplicatedFiles)
                duplicatesFoundLog.WriteLine ("Probably duplicated item: Name: {0}, Length: {1}",

                var items = files.Where (x => x.Name == filter.Key.Name &&
                    x.Length == filter.Key.Length).ToList ();

                int c = 1;
                foreach (var suspected in items)
                    duplicatesFoundLog.WriteLine ("{3}, {0} - {1}, Creation date {2}",

                duplicatesFoundLog.WriteLine ();

            duplicatesFoundLog.Flush ();
            duplicatesFoundLog.Close ();

From the console application I first call the ListDrive method, than call ListDuplicates method. Well, I don’t say it’s the best and most elegant way, but quickly served my needs. The whole process took around 31 seconds, 6 for compile the list, 25 for create the log, in 500GB HDD, with over 6600 duplications. With less than 100 lines of code.

Self consuming WCF service

It’s easy to create a self consuming WCF service, also can simplify the architecture.

Start a new project with Windows Service project template.
Screenshot (92)
Add the installers to the service. It creates a serviceProcessInstaller1 and serviceIstaller1 objects. You can rename them, if you want. In serviceInstaller1 you can give some meaningful description and name for the service. At the serviceProcessInstaller1 you can set the Account for the service.
Screenshot (93)

Now, lest do the business…
Reference System.Runtime.Serialization.dll (you may need it) and System.ServiceModel.dll.
Add a new interface, in the example I use ILearn, and create the service contract. In basic example you need only

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.Runtime.Serialization;

namespace SelfConsumingWcf
    interface ILearn
        void Add (int incr);

        int GetValue ();

    public class ErrorInfo
        public string ErrorMessage { get; set; }

Add a new class, which inherits from the contract interface.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;

namespace SelfConsumingWcf
    [ServiceBehavior (InstanceContextMode = InstanceContextMode.Single)]
    class Learn : ILearn
        private int sum = 0;

        public void Add (int incr)
                sum += incr;
            catch (Exception ex)
                new FaultException (new ErrorInfo () { ErrorMessage = ex.Message });

        public int GetValue ()
            return sum;

Implement the service OnStart and OnStop methods. After it, finish implementing the service.  Maybe seems the example is bit dummy, but its working. Of course you can implement other kind of logic, which will consume the self hosted service via the created ServiceFactory channel. I used similar manner to subscribe to an OPC Server to monitor the controlled items.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.ServiceModel;
using System.Text;
using System.Timers;

namespace SelfConsumingWcf
    public partial class Service1 : ServiceBase
        public Service1 ()
            InitializeComponent ();

        private ILearn learnChannel;
        private ChannelFactory learnChFactory;

        private ServiceHost learnHost;
        private Timer timer;

        protected override void OnStart (string[] args)
            if (learnHost != null)
                learnHost.Close ();

            learnHost = new ServiceHost (typeof (Learn));
            learnHost.Open ();
            learnChFactory = new ChannelFactory (
            learnChannel = learnChFactory.CreateChannel ();

            timer = new Timer ();
            timer.Elapsed += timer_Elapsed;
            timer.Interval = 3000;
            timer.Start ();

        private Random rnd = new Random ();

        void timer_Elapsed (object sender, ElapsedEventArgs e)
            int direction = rnd.Next (0, 2);
            int num = rnd.Next (200);
            num = num * direction == 0 ? -1 : 1;
            learnChannel.Add (num);

        protected override void OnStop ()
            timer.Stop ();

            if (learnChFactory != null)
                learnChFactory.Close ();

            if (learnHost != null)
                learnHost.Close ();

Almost finally, need some configuration for the service. Well, that’s the part which can be a bit overwhelming. WCF configuration is a vast topic, and can be easily overlook something, or just a minor mistake, than the whole service will fail to work.

Add an Application configuration file and configure your service. You can do it manually or via Edit WCF configuration menu from Visual Studio, with right click on the app.config.

Configure the ABC:  Address, Binding, Contract

<?xml version="1.0" encoding="utf-8" ?>
      <service name="SelfConsumingWcf.Learn" behaviorConfiguration="LearnBehavior">
            <add baseAddress="http://localhost:8000/SelfConsumingWcf/service"/>
        <endpoint address="" binding="wsHttpBinding" contract="SelfConsumingWcf.ILearn"/>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <behavior name="LearnBehavior">
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true"/>

After finishing the code and configuration, you ready to go. Press F6 to build the project, than launch Visual Studio command promt or Command Promt with Administrative privileges. If you started VS command promt, than installutil is available for you, if you launched regular one, you need to go the corresponding Framework version folder, to install the service.
installutil –i [PathOfYourServiceExeFile]

Dependent from the install configurations you may ask the user name – password and maybe you need to start manually your service. If do, launch the services, to start the service. If everything is okay, you service will start, if not, you will receive a notification, you can check the details of the error in the Event Log, or the place where you store the error logs. If its work properly, you can check it in the browser.

Be a consumer.
Let the service running.  Launch WCF Test client or add a new project to the solution, reference the service, than test it.

Finally you can uninstall it, almost like as you installed:
installutil –u [PathOfYourServiceExeFile]

Hit testing WPF UserControl

Recently I work an application, which needs to display data from various kinds of controls. Most of them can be derived from seven base types. For the sheer amount of data that are available, I let the end user to decide which one of them wants to examine in the user interface. So basically the user can drag controls from a list to a WrapPanel, which will organize them, and start to show the current states or values. To provide ability to remove them, I use the WrapPanel’s ContextMenu Delete function. Inside Delete’s event I examine the HitTestResult to decide which control should I remove.
Hit testing proves itself a kind of beast. Usually it always returned the particular item, which is the top most at the hit location. No matter that I set the controls IsHitTestEnabled property to false. The MSDN Library suggested a solution: override the HitTestCore implementation, but that won’t work either. Finally, was able to figure out, how get the proper control, that need to be removed.
Simply I walk through the visual tree, and if I get something desirable, than I’m done…

 HitTestResult res = VisualTreeHelper.HitTest (wpControlHost, e.GetPosition (wpControlHost));
            UIElement removeItem = null;
            if (res != null)
                DependencyObject obj = VisualTreeHelper.GetParent (res.VisualHit);
                int toolId = -1;
                while (obj != null)
                    if (obj is UserControl)
                        toolId = (int)obj.GetType ().GetProperty ("ToolId").GetValue (obj, null);

                        // you can examine further the type of the usercontrol
                        if (obj is PressureControl)
                            System.Diagnostics.Debug.WriteLine ("is pressure control");

                        if (obj is CompressorControl)
                            System.Diagnostics.Debug.WriteLine ("is compressor control");

                        removeItem = obj as UIElement;
                        obj = null;
                        obj = VisualTreeHelper.GetParent (obj);

                if (removeItem != null)
                    wpControlHost.Children.Remove (removeItem);

A little update:
Sometimes the HitTest simply fall through the whole VisualTree, to avoid these issues, add a transparent background for the UserControl, that will help.