Just code - Tamir Khasonhttp://blogs.microsoft.co.il/tamir
Take care of the sense, and the sounds will take care of themselves.Sun, 29 Dec 2013 10:02:25 +0000he-ILhourly1http://wordpress.org/?v=4.1.1New year – new blog or how to migrate Community Server to any other engine, supports XML-RPChttp://blogs.microsoft.co.il/tamir/2009/01/01/new-year-new-blog-or-how-to-migrate-community-server-to-any-other-engine-supports-xml-rpc/
http://blogs.microsoft.co.il/tamir/2009/01/01/new-year-new-blog-or-how-to-migrate-community-server-to-any-other-engine-supports-xml-rpc/#commentsThu, 01 Jan 2009 21:33:04 +0000http://blogs.microsoft.co.il/?p=205248Please update your bookmarks, because the new url of this blog is http://khason.net/ (you have not update RSS feeds, it will be done automatically). Why I did it? Why I decided to go to “stand-alone”… Well. there are some reasons. Generally, I do not want to explain all those here, but trust me, there are some. The main reason is, that there is no responsible person in charge for this blog platform in Microsoft Israel. This why, if your blog is popular and you have a respect to your blog visitors, you cannot host it here… Take a look into new comments notifications in my inbox. Would you answer your readers with such “small amount” of SPAM and capcha, that cannot be fixed already for three years in this platform? This how my inbox looks like for last three years. So now, you should not ask me, why I not answered your email or comments. Aren’t you?

Currently, all comments in this blog are disabled, so if you want to comment, please use new url of posts (this will appear shortly in the beginning of each post). Also, this post will not be syndicated in RSS.

So, this post is the last. I loved this platform, and loved people started it. But, unfortunately, it seemed, that bloggers community is not important enough for new platform managers.

Have a great year and, as always, be good people. This post marked with all possible tags automatically. Sorry.

]]>http://blogs.microsoft.co.il/tamir/2009/01/01/new-year-new-blog-or-how-to-migrate-community-server-to-any-other-engine-supports-xml-rpc/feed/0Read and use FM radio (or any other USB HID device) from C#http://blogs.microsoft.co.il/tamir/2008/12/30/read-and-use-fm-radio-or-any-other-usb-hid-device-from-c/
http://blogs.microsoft.co.il/tamir/2008/12/30/read-and-use-fm-radio-or-any-other-usb-hid-device-from-c/#commentsTue, 30 Dec 2008 20:42:18 +0000http://blogs.microsoft.co.il/?p=204291[This blog was migrated. You will not be able to comment here.The new URL of this post is http://khason.net/blog/read-and-use-fm-radio-or-any-other-usb-hid-device-from-c/]

First, if you want to do it, go and buy such device. The are not a lot of alternatives, but if you’ll seek, you’ll find it very quickly.

So, let’s start. First of all, we’ll use platform invoke to get and set the information. Also, we have to preserve handle of the device from being collected by GC. After we’ll finish using the device, we’ll have to dispose it. Thus it makes sense to inherit from SafeHandle and IDisposable.

]]>http://blogs.microsoft.co.il/tamir/2008/12/30/read-and-use-fm-radio-or-any-other-usb-hid-device-from-c/feed/0Capturing and streaming sound by using DirectSound with C#http://blogs.microsoft.co.il/tamir/2008/12/25/capturing-and-streaming-sound-by-using-directsound-with-c/
http://blogs.microsoft.co.il/tamir/2008/12/25/capturing-and-streaming-sound-by-using-directsound-with-c/#commentsThu, 25 Dec 2008 18:48:20 +0000http://blogs.microsoft.co.il/?p=201052[This blog was migrated. You will not be able to comment here.The new URL of this post is http://khason.net/blog/capturing-and-streaming-sound-by-using-directsound-with-c/]

I already wrote a little about managed way to use DirectX DirectSound. Today we’ll speak about how to get sound from your microphone or any other DirectSound capturing device (such as FM receiver) and stream it out to your PC speakers and any other DirectSound Output device. So, let’s start creating our first echo service by using managed DirectX.

First of all we should decide what Wave format we want to use for capturing and recording. So, let’s choose anything reasonable

Next step is to set the size of two buffers – one for input and other for output. Generally those buffers are circular, and capturing one should be twice bigger, then output. Why? Because we choose two channels to use. Also, we should decide about chunk size of the buffer, we want to signal when filled.

Then we’ll create output device and buffer. To simplify program, we will use default speakers to output, however, you can choose output device the same way we did for capturing. Also, because DirectSound uses any window as it’s message pump, we have to use SetCooperativeLevel method. In my case (windowless application), I’ll use desktop window as message broker. This why you will have to add Windows.Forms as reference for your project, even if it console application. Also, do not forget to set GlobalFocus value to True, if you want to play echo, even if desktop window is not focused.

That’s it. Compile and run. Now if you’ll speak, you can hear your echo from PC speakers.

Merry Christmas for whom concerns and be good people – do not scare your co-workers with strange sounds – be polite and make the volume lower

]]>http://blogs.microsoft.co.il/tamir/2008/12/25/capturing-and-streaming-sound-by-using-directsound-with-c/feed/0Quick Silverlight (and WPF) tip: How to write program without XAMLhttp://blogs.microsoft.co.il/tamir/2008/12/23/quick-silverlight-and-wpf-tip-how-to-write-program-without-xaml/
http://blogs.microsoft.co.il/tamir/2008/12/23/quick-silverlight-and-wpf-tip-how-to-write-program-without-xaml/#commentsTue, 23 Dec 2008 18:51:00 +0000http://blogs.microsoft.co.il/?p=199696[This blog was migrated. You will not be able to comment here.The new URL of this post is http://khason.net/blog/quick-silverlight-and-wpf-tip-how-to-write-program-without-xaml/]

From the moment, 10K MIX09 contest was launched, I got more, then 20 people, asking the same question: Is it possible to have Silverlight program up and running without XAML at all?

The answer is “YES, IT IS”. Here is how:

All you need for run WPF or Silverlight application is

Class inherited from System.Windows.Application

Class inherited from System.Windows.Controls.UserControl

So, Let’s create new WPF or Silverlight application and delete all files from the project directory. Then add one file, named App.cs (or Foo.cs or Whatever.cs – the length of the file name is not included ) and write there :

We done. F5, be happy. You just wrote first officially smallest Silverlight functional application. Good luck with Mix09 contest.

]]>http://blogs.microsoft.co.il/tamir/2008/12/23/quick-silverlight-and-wpf-tip-how-to-write-program-without-xaml/feed/0What boots faster – Netbook, powered Windows XP or Nokia E71 mobile phone?http://blogs.microsoft.co.il/tamir/2008/12/18/what-boots-faster-netbook-powered-windows-xp-or-nokia-e71-mobile-phone/
http://blogs.microsoft.co.il/tamir/2008/12/18/what-boots-faster-netbook-powered-windows-xp-or-nokia-e71-mobile-phone/#commentsThu, 18 Dec 2008 14:08:42 +0000http://blogs.microsoft.co.il/?p=194876[This blog was migrated. You will not be able to comment here.The new URL of this post is http://khason.net/blog/what-boots-faster-%e2%80%93-netbook-powered-windows-xp-or-nokia-e71-mobile-phone/]

Some days ago, somebody from Microsoft was shocked, when I told him, that I’m planning to run Windows XP (and later Windows 7) as operation system for mission critical automotive device. He even checked with Windows XP embedded team boot times for XP. They told him, that the minimum can be achieved is about 40 seconds cold boot and 30 seconds from hibernate state. I was upset and decided to tweak my system for smallest possible boot time. Here the result video. This is not the limit. I believe, that I’ll be able to decrease Windows XP boot time to less, then 10 seconds with a bit more efforts.

Note: This is absolutely authentic and non-touched video, recorded today by me, comparing boot time of Windows XP on unbranded weak netbook (Atom 1.6, 128MB and 8G SSD) and my Nokia E71 mobile phone. 15 seconds boot time of Windows XP achieved by tweaking only well known registry values and OS configuration values without special profundity of system settings.

Now the question: with todays’ devices, why we are not running XP for mobile and automotive mission critical devices?

]]>http://blogs.microsoft.co.il/tamir/2008/12/18/what-boots-faster-netbook-powered-windows-xp-or-nokia-e71-mobile-phone/feed/6Reading and decoding RDS (Radio Data System) in C#http://blogs.microsoft.co.il/tamir/2008/12/12/reading-and-decoding-rds-radio-data-system-in-c/
http://blogs.microsoft.co.il/tamir/2008/12/12/reading-and-decoding-rds-radio-data-system-in-c/#commentsFri, 12 Dec 2008 13:44:24 +0000http://blogs.microsoft.co.il/?p=191019[This blog was migrated. You will not be able to comment here.The new URL of this post is http://khason.net/blog/reading-and-decoding-rds-radio-data-system-in-c/]

RDS or Radio Data System is very common in US and many European countries. It is communication protocol used to send small amount of digital information using regular FM radio broadcast. This protocol is used to "tell" your receiver about alternative frequencies, time, program notifications, program types, traffic information and regular text (such as singer name or genre). Unfortunately in Israel RDS is not very common and there is very limited number of radio stations broadcasts RDS information.

How RDS works?

As mentioned earlier, it uses FM subcarrier to broadcast digital information. It was designed to support 10 and 18 characters numeric and 80 characters alphanumeric displays. RDS operates at 1187.5 bps and based on 26-bit word consisting of 16 data and 10 error detection bits. Due to the fact, that FM carrier is not very reliable, error code allows correct information to be received even if an error of 3-5 bits exists within 26 bit block. Each four data blocks interpreted as 104-bit signal and named "group". Depending of the type of information, contained within the group, as different group type code is defined and transmitted within the group as upper five bits code. Even if more, then 104 bits required to completely send the information, there is no requirement that the next segment of the transmission be sent in the next group. There are 32 known groups types, defined by RFC:

Not all groups are in use all the time. However, there are some commitments, defined by the protocol. For example, 1A have to be transmitted at least once a second. This group contains special information, required for receivers to be synchronized and locked into the transmitting channel.

Within the error correction information we also receive the direction to treat them.

Also, each message type has it own limits. For example RT (Radio Text – 64 character text to display on your receiver) and PS (Programme Service – eight character station identification) message are limited to 2 groups, when PI (Programme Identification – unique code of the station) and PTY (Programme Type – one of 31 predefined program types – e.g. News, Drama, Music) are limited to 4.

In addition to those constraints, block types are also different. But in this case, there are only 4 kinds

private enum blockType : byte { A = 6, B = 4, C = 2, D = 0}

So, what we're waiting for? Let's start working.

Handling errors

First of all we should take care on errors and fix them if possible. For this purpose, we should first count them and detect the way of fixing

When we done with those two groups, we can start handling another. Today, we'll handle only 0B, 2A and 2B types (I have a good reason for it, due to the fact, that only those are supported in Israel by now ) So,

In PS, we have high and low probability bits. So, if new bit in sequence matches the high probability bite and we have recieved enough bytes to max out the counter, we'll push it into the low probability array.

When the new byte matches with low probability byte, we'll swap them as well and reset counters to update text in transition flag. However in this case, our counter will go higher, then the validation limit. So we'll have to remove it down later.

We done. Now we can handle RDS digital messages, but what to do with analog data we get? Don't you already know? I blogged about it here.

Have a nice day and be good people, because you know how to write client, knows to get and parse radio data in managed code.

]]>http://blogs.microsoft.co.il/tamir/2008/12/12/reading-and-decoding-rds-radio-data-system-in-c/feed/0Creating transparent buttons, panels and other control with Compact Framework and putting one into otherhttp://blogs.microsoft.co.il/tamir/2008/11/21/creating-transparent-buttons-panels-and-other-control-with-compact-framework-and-putting-one-into-other/
http://blogs.microsoft.co.il/tamir/2008/11/21/creating-transparent-buttons-panels-and-other-control-with-compact-framework-and-putting-one-into-other/#commentsFri, 21 Nov 2008 13:09:29 +0000http://blogs.microsoft.co.il/?p=172845[This blog was migrated. You will not be able to comment here.The new URL of this post is http://khason.net/blog/creating-transparent-buttons-panels-and-other-control-with-compact-framework-and-putting-one-into-other/]

In WPF/Silverlight world it's very simple to make transparent controls and put anything inside anything. However, that's not the situation in WinForms, and even worth in the world of compact devices with CF. Within this worlds, there is only one way to make controls transparent – to use color masks. Today, we'll create transparent controls with Compact Framework and put it into panel, which has image background.

So let's start. First of all, we need create our own control. For this purpose, we have to inherit from Control and override couple of things. More precise: OnPaint and OnPaintBackground. We do not want to paint background for transparent control, so let's prevent it.

Next, we have to get graphics, delivered by OnPain event argument and draw our image over it. However, BitBlt (which is used by core graphics system) is not very fast method, so it's better for us to draw everything first and then copy final image to the device.

To make images transparent, we have to use (as mentioned earlier) transparency color key (to tell windows what color it should not draw. We can code or provide this value to detect it by hitting any pixel on the image. Just like this:

Compile and run to see no problem, when our transparent button lies on solid color control, however, we want to put it into panel with background – just like this one. In this case, you can use real transparent PNG and GIF images, also you can replace transparent color with well known Magenta (or any other color).

When we'll put it onto anything, that has no background color, we'll see that our "fake transparency" disappears. Why this happen? To provide transparency Windows uses color masks, also while confederating facts, clipping algorithm within GDI is not very trustful, thus the only thing can be taken into account is color. But what to do if we have an image? We should clip it manually. We cannot just get the handle to parent device surface (see above about trustful GDI), so the only way to do it is by providing something, that we know for sure. For example interface, telling us, that parent has image, which drawn on the screen.

internal interface IHaveImage { Bitmap Image { get; set; } }

When we know it, all we have to do is to clip the region of this image (not device context) and draw it as part of our really transparent control.

P.S. Do not even try to inherit your custom Button control from framework Button class, dev team "forgot" to expose it's event for override. So, OnPaint, OnPaintBackground, OnKeyUp, OnKeydown, OnMouseUp and OnMouseDown aside with most of other base events will not work for you, also BaseButton class has no default constructor, so the only class you can inherit from is Control.

Have a nice day and be good people.

]]>http://blogs.microsoft.co.il/tamir/2008/11/21/creating-transparent-buttons-panels-and-other-control-with-compact-framework-and-putting-one-into-other/feed/0How to P/Invoke VarArgs (variable arguments) in C#? … or hidden junk in CLRhttp://blogs.microsoft.co.il/tamir/2008/11/19/how-to-pinvoke-varargs-variable-arguments-in-c-or-hidden-junk-in-clr/
http://blogs.microsoft.co.il/tamir/2008/11/19/how-to-pinvoke-varargs-variable-arguments-in-c-or-hidden-junk-in-clr/#commentsWed, 19 Nov 2008 06:44:10 +0000http://blogs.microsoft.co.il/?p=170664[This blog was migrated. You will not be able to comment here.The new URL of this post is http://khason.net/blog/how-to-pinvoke-varargs-variable-arguments-in-c-or-hidden-junk-in-clr/]

Recently I wrote a cheat sheet for pinvoking in .NET. Shortly after I got a question in comments about how to deal with variable arguments, when it's more, then one parameter. Also what to do if those arguments are heterogeneous?

So what to do? The official answer is – you have nothing to do, rather then override all possibilities. This is very bad and absolutely not flexible. So, there is small class in C#, named ArgIterator. This one is similar to params object[], but knows to marshal into varargs. The problem is, that you have no way to add things inside. It's "kind-of-read-only".

Let's look into reflected version of ArgIterator. We'll see there something, named __arglist and __refvalue. OMG, isn't it good old stuff similar to "__declspec(dllexport) int _stdcall" etc.? It is! But can we use it in C#? We can! Just sign your method as Cdecl and you have working signature for "…"

Yes, looks strange, and absolutely not CLR compliant. However, this is the only way to expose varargs to CLR via P/Invoke. How to use it? Simple:

c = VarSum(2, __arglist(5, 10));

Have a nice day and be good people. Also, my question to Microsoft is why this stuff is not in MSDN and we, as developers, have no way to get rid of it.

Is not it very good practices to use non-compliant methods? Give us another way to do it!Is not it very good practices to use variable arguments in unmanaged method signatures? So why you want dynamic types in C# 4?

]]>http://blogs.microsoft.co.il/tamir/2008/11/19/how-to-pinvoke-varargs-variable-arguments-in-c-or-hidden-junk-in-clr/feed/0Asus R50A UMPC reviewhttp://blogs.microsoft.co.il/tamir/2008/11/13/asus-r50a-umpc-review/
http://blogs.microsoft.co.il/tamir/2008/11/13/asus-r50a-umpc-review/#commentsThu, 13 Nov 2008 13:26:00 +0000http://blogs.microsoft.co.il/?p=165513[This blog was migrated. You will not be able to comment here.The new URL of this post is http://khason.net/blog/asus-r50a-umpc-review/]

What in the box? Power adapter (110/220V), compact keyboard, bunch of cables, extra stilus and handling strap.

What else this machine has? Microcard reader, three mini-usb sockets, one regular USB and camera. Looks like pretty fine machine, but not for €1K+ price tag. But who cares when we buy real good gadget? However, my euphoria disappears during 6 minutes startup (this was not first startup – first took more, then 15 minutes).

It was preinstalled with Windows Vista SP1 Ultimate (for this tiny machine) aside with huge amount of Asus junkware, so it was was even unable even to calculate Vista experience score

Also it has no drivers for strange device, named "Mini Card" (with factory branded Asus OS installation)

Well, it's probably because I'm still not connected to internet… Let's connect office WiFi… Err… It has some troubles with wireless network discovery – 2 bars for 12 feet distance from access point (my W500 has all 5) and no other networks (with 4 and less bars on another machine). Let's connect it. Hm, "unable to connect"… Weird. Leave it by now. This is multimedia device, so, probably, video will play better? Well, it failed also with playback of Windows sample movie. So maybe it has great battery life? Not really. Without doing anything new 2 cells, 2600mAh battery enough for less, then two hours (with vista battery saver it extended to 3, while this device does not support aero interface).

But the final accord was this one (one again – this is branded Asus installation):

Bottom line: 0/5. I paid $360 for my wife's pink Acer Aspire One and got much better computer (it even has camera).

The only thing remains enigma for me is why, the hell, this piece of crap costs more, then €1,000?

Have a nice day and be good people – do not buy this machine!

]]>http://blogs.microsoft.co.il/tamir/2008/11/13/asus-r50a-umpc-review/feed/2Consultants for charityhttp://blogs.microsoft.co.il/tamir/2008/11/12/consultants-for-charity/
http://blogs.microsoft.co.il/tamir/2008/11/12/consultants-for-charity/#commentsWed, 12 Nov 2008 16:50:38 +0000http://blogs.microsoft.co.il/?p=165049[This blog was migrated. You will not be able to comment here.The new URL of this post is http://khason.net/blog/consultants-for-charity/]

As you, probably, know, I left consulting field. However, it does not mean, that I quit helping developers community with client application development. Also, every day I'm getting between 50 and 300 emails with questions (I'm trying to answer all of those) and sometimes proposals for consulting. Currently I'm refusing all those, because I do not want to engage to it. However, there are too much people, who really need professional developers help and there are very few good development consultants in our area. Thus I decided to keep consulting, but this time only for charity.

How does it work?

I tell you what charity organization to transfer all amount, you should pay (except TBL, if there are).

You transfer it.

We made the world a bit better!

To clarify things:

It's not charity foundation – you will transfer the money directly to organization, that need it

I'm not doing it for free – I feel, that finally I'm able to do something really big for those, who need it

So, if you are one of those, who want me to consult, contactme via this form or Twitter.

If you're good consultant and want to join me, contactme via this form or Twitterand we'll make the world better together.

I still had no chance to speak with my ex-engagement manager, however I believe, that he will not have a problem with this kind of payment to me. If so (and you have open PO in Microsoft Israel with him), you'll be able to use it.

Spear the world with this news! Post in your blogs, twitters, facebook, any other community stuff or just join me