We had solar electric installed (yay!). We are using the Aurora PVI 4.2kW inverter, which appears to be a very well recommended unit, but there were a couple of challenges with trying to plug into the USB connection to download live data. Just thought I'd note them down here to hopefully save someone else a bit of time.
There are two pieces of software you need:
1. USB driver - makes the Aurora appear under Windows as a COM port. (Texas Instruments 3410 USB driver). We used this one instead of the Aurora one. "TI WDF USBUART Single Driver" from the software section of this page.
2. Aurora communicator software - Communicates with the Inverter to download and chart data.
(Unfortunately the inverter doesn't actually collect historical data, you need to essentially leave the program running and poll for it). Communicator can be downloaded from here. (select 'UK' as the country, then select Software - because not all countries have any 'software' listed against them).
Issue 1: My laptop is running Windows 7 (x64). For better or worse, the 64 bit version of Windows doesn't run unsigned device drivers. The driver may look like it has installed - but it won't run. The work-around for now is to boot Windows in the special mode to allow unsigned drivers. (Press F8 while the computer is booting, and select "Disable Driver Signature Enforcement."). Or see here for other options.
Issue 2: The Inverter itself needed to be assigned an "address" before it would talk to anything. Go to the inverter itself and use the menu options to go into the settings and set an address. Any number will do. We used "2". Seems to be necessary and in our case wasn't already preconfigured.
Next task: ditch the 70W laptop and start using a Rasberry Pi instead.
4 January 2014
28 October 2013
Bank Security Madness
This has probably been said by countless people before, but banking security is just mind bogglingly dumb.
Yesterday I phoned the NAB bank. Along with the usual questions I was asked to name a recent transaction. I couldn't recall one so I asked my wife who was standing next to me. The phone operator proceeded to tell me that I wasn't allowed to ask her because I was the person who needed to know the answer! NAB, if you make me communicate with my wife using a pen and paper instead, then you're not going to gain any security, you're just going to annoy customers.
The next thing that struck me was that the transaction used for authentication could be a debit. Now, generally speaking you don't need to do any authentication to put money into an account. Anyone can deposit into your account as long as they have the account number; thereby rendering this authentication method (as it stands) useless at best.
Today I phoned the ANZ bank. Their system is straight forward enough. I just need to know my Customer Reference Number, my telecode, my security code, and my web password. And I'd better well be able to remember which is which before I run out of attempts.
Authentication is a hard problem to solve, but surely we can do a bit better than this.
Yesterday I phoned the NAB bank. Along with the usual questions I was asked to name a recent transaction. I couldn't recall one so I asked my wife who was standing next to me. The phone operator proceeded to tell me that I wasn't allowed to ask her because I was the person who needed to know the answer! NAB, if you make me communicate with my wife using a pen and paper instead, then you're not going to gain any security, you're just going to annoy customers.
The next thing that struck me was that the transaction used for authentication could be a debit. Now, generally speaking you don't need to do any authentication to put money into an account. Anyone can deposit into your account as long as they have the account number; thereby rendering this authentication method (as it stands) useless at best.
Today I phoned the ANZ bank. Their system is straight forward enough. I just need to know my Customer Reference Number, my telecode, my security code, and my web password. And I'd better well be able to remember which is which before I run out of attempts.
Authentication is a hard problem to solve, but surely we can do a bit better than this.
8 October 2013
Javascript dictionary using objects as keys
One thing that bugs me about Javascript is the inability to have a dictionary with objects as keys. Objects are dictionaries, but essentially toString gets called on anything you use as a key, which isn't always very helpful.
Typical solutions are to call stringify on each object, which is relatively slow and doesn't guarantee reference equality, or to have a custom hashing function, which feels like unnecessary effort. (The jshashtable library generally looks useful, but unless you provide the hashing function the performance drops considerably.
So my requirements are:
OK, it needs a whole lot more work, but you get the idea. We keep track of a global ID so that a key can be used in more than one dictionary simultaneously. If we want to have some way to enumerate over the values or get a count, then we'd also need to store keys/values in the Dictionary itself. I'd probably go with a doubly-linked-list, otherwise add/removes would get slow.
The main disadvantage is that we are adding an extra property to the key objects, which may be undesirable in some circumstances. But overall it solves the requirements without too much mess.
Typical solutions are to call stringify on each object, which is relatively slow and doesn't guarantee reference equality, or to have a custom hashing function, which feels like unnecessary effort. (The jshashtable library generally looks useful, but unless you provide the hashing function the performance drops considerably.
So my requirements are:
- A dictionary that takes objects as keys
- And will only resolve values using the same instance of the object (not just some string match)
- Is fast
- Without any custom hashing functions
function Dict() {
Dict.id = (Dict.id || 0) + 1;
this._prop = '_dict' + Dict.id;
}
Dict.prototype = {
add: function(key, value) {
key[this._prop] = value;
},
contains: function(key) {
return typeof key[this._prop] != 'undefined';
},
get: function(key) {
return key[this._prop];
},
remove: function(key) {
delete key[this._prop];
}
};
// Sample usage
var a = {};
var b = {};
var c = {};
var dict1 = new Dict();
dict1.add(a, 123);
dict1.add(b, 456);
var dict2 = new Dict();
dict2.add(c, 789);
alert(dict1.get(a)); // 123
alert(dict1.contains(c)); // false
alert(dict2.contains(c)); // true
dict2.remove(c);
alert(dict2.contains(c)); // false
OK, it needs a whole lot more work, but you get the idea. We keep track of a global ID so that a key can be used in more than one dictionary simultaneously. If we want to have some way to enumerate over the values or get a count, then we'd also need to store keys/values in the Dictionary itself. I'd probably go with a doubly-linked-list, otherwise add/removes would get slow.
The main disadvantage is that we are adding an extra property to the key objects, which may be undesirable in some circumstances. But overall it solves the requirements without too much mess.
23 September 2013
Using $q promises to run synchronous code asynchronously
The Q Javascript library provides a great way to handle the results of asynchronous tasks in a simple flexible manner. But the APIs required to actually generate and return promises for your own synchronous code are often a bit verbose, particularly if you want to catch and pass on exceptions as well.
Here's a convenient shortcut: Just call $q.when() with no arguments, then place all of your synchronous code (that you want to behave asynchronously) in a subsequent .then() call. This will automatically pick up any results, or exceptions, and pass them on as promises.
E.g.
Here's a convenient shortcut: Just call $q.when() with no arguments, then place all of your synchronous code (that you want to behave asynchronously) in a subsequent .then() call. This will automatically pick up any results, or exceptions, and pass them on as promises.
E.g.
function myAsyncSqrt(value) {
return $q.when()
.then(function() {
return Math.sqrt(value);
});
}
...
var promise = myAsyncSqrt(16);
promise.then(
function(res) { alert('answer:' + res); },
function(err) { alert('uh oh:' + err); });
30 August 2013
Allowing .Net unit tests to access internal members
Good code encapsulation requires that various members be marked as private, or at least internal. However this can make it difficult for unit test frameworks such as NUnit to access them.
You can grant an external (e.g. unit test) assembly access to internal members by doing the following:
You can grant an external (e.g. unit test) assembly access to internal members by doing the following:
- Give your test assembly a strong name (via Project Properties, Signing, Sign the assembly)
- Compile the assembly (eg. My.Test.dll)
- Open the Visual Studio command prompt
- Navigate to the folder where My.Test.dll got built
- Run: sn -Tp My.Test.dll
- This will display the full public key for the signed assembly. Copy it. (it'll be about 320 chars)
- Open the AssemblyInfo.cs file for the assembly containing the code with internals to be tested.
- Enter a line such as: [assembly: InternalsVisibleTo("My.Test, PublicKey=1234")] where 1234 is the full key generated in step 6.
19 August 2013
How to mock an Angular service for testing
To inject a fake version of myService, and intercept calls to myMethod, do something like this:
Or check out the cool video here.
var myMethodFake = function() { ... };
beforeEach(function () {
module(function ($provide) {
mockMyService = {
myMethod: jasmine.createSpy('myMethod').andCallFake(myMethodFake)
};
$provide.value('myService', mockMyService);
});
});
it('does stuff', inject(function(myService) {
myService.myMethod();
});
15 August 2013
Default IE XSLT for viewing XML
Being blogged just because it shouldn't have taken me nearly as long to figure this out as it did.
How to download the default XSLT template that IE uses for viewing XML. (The pretty looking one with collapsible/expandable elements):
How to download the default XSLT template that IE uses for viewing XML. (The pretty looking one with collapsible/expandable elements):
- Use Visual Studio
- Click File | Open | File
- Open C:\Windows\System32\msxml3.dll (because VS knows what to do with a DLL)
- Expand to: XML \ DEFAULTSS.XML
- Right-click and Export..
- Save it as an .xsl
All done.
Subscribe to:
Posts (Atom)