<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Gil&#039;s Development Journal</title>
	<atom:link href="http://gilzu.com/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://gilzu.com</link>
	<description></description>
	<lastBuildDate>Mon, 23 May 2011 09:27:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>Speed Challange: Solitaire &amp; FreeCell &#8211; Use Case</title>
		<link>http://gilzu.com/?p=38</link>
		<comments>http://gilzu.com/?p=38#comments</comments>
		<pubDate>Mon, 23 May 2011 09:26:40 +0000</pubDate>
		<dc:creator>Gil</dc:creator>
				<category><![CDATA[Speed Programming]]></category>
		<category><![CDATA[FreeCell]]></category>
		<category><![CDATA[Solitaire]]></category>
		<category><![CDATA[Use Case]]></category>

		<guid isPermaLink="false">http://gilzu.com/?p=38</guid>
		<description><![CDATA[Writing a more complex Use-Case document for not one, but two games were more problematic than I first thought. Even though the two had a well-defined/known game-play, I did find myself lost within the various Use-Cases. Instead of being more &#8230; <a href="http://gilzu.com/?p=38">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Writing a more complex Use-Case document for not one, but two games were more problematic than I first thought. Even though the two had a well-defined/known game-play, I did find myself lost within the various Use-Cases. Instead of being more organized and calculated, there were too many loose ends and ambiguous inconsistent references to game-play elements.</p>
<p><span id="more-38"></span><strong>The Importance Of Glossary</strong></p>
<p>Try to refer to the Solitaire&#8217;s deck of cards that appears in the top left corner. Now try to distinguish the cards that were not drawn, the cards that were drawn, the cards that were drawn but now are not visible due to the newly drawn cards. Now do it repeatedly over and over again for each of the Use-Cases that handle these elements. And that&#8217;s just one gameplay element.</p>
<p style="text-align: center;"><a href="http://gilzu.com/wp-content/uploads/2011/05/glossary.jpg" target="_blank"><img class="size-medium wp-image-39" title="Glossary" src="http://gilzu.com/wp-content/uploads/2011/05/glossary-300x206.jpg" alt="" width="300" height="206" /></a></p>
<p style="text-align: left;">I decided to create a new Glossary section where i&#8217;d first define each of the game elements, starting with their name and location. Since the game-element mechanics is known, it will be enough to distinguish one from another them. However, for future projects in which I would go for not so defined gameplay, the behavior and purpose of theses objects must also be written down.</p>
<p style="text-align: left;"><strong>Revisions Section</strong></p>
<p style="text-align: left;">I like to backup my work every hour or so. I also work on more than one folder and on several computers. This document took more than 2-3 sessions of writing since I can only dedicate 30 minutes or so everyday. Each session generated more text, but left some loose ends which I had to take care for the next sessions: more Use-Cases, undefined elements.</p>
<p style="text-align: left;">Instead of leaving a seperate Todo list and taking the time to remember what i&#8217;ve already done, I started a Revision section at the start of the document. For each session I wrote the changes I&#8217;ve done and the work needed to be done for the next session. For the next session, it took me less time to &#8220;recalibrate&#8221; myself on the work that&#8217;s needed.</p>
<p style="text-align: left;"><strong>Separating The Two Games</strong></p>
<p style="text-align: left;">The first draft contained the definition of both game&#8217;s mechanics. It was horrible since it kept jumping between the two game&#8217;s Use-Cases describing a Hybrid game. Also, the fine details that defined each of the games were left behind since most of my concentration went on focusing on two separate games &#8211; what belongs where. The common parts were the worst &#8211; each had tons of exceptions referring to each of the games.</p>
<p style="text-align: left;">I decided to separate the design process of the two, observing which of the parts are similar or even the same for later pre-coding design where I would be able to use the same code for both games.</p>
]]></content:encoded>
			<wfw:commentRss>http://gilzu.com/?feed=rss2&#038;p=38</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Speed Challange: Solitaire &amp; FreeCell (Double Trouble!)</title>
		<link>http://gilzu.com/?p=35</link>
		<comments>http://gilzu.com/?p=35#comments</comments>
		<pubDate>Sat, 21 May 2011 17:18:40 +0000</pubDate>
		<dc:creator>Gil</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://gilzu.com/?p=35</guid>
		<description><![CDATA[In this challange, I will deal with the task of writing two games at once. The games will share some of the design, modules and behavior but will act as a seperate project altogether. The shared components will have to &#8230; <a href="http://gilzu.com/?p=35">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In this challange, I will deal with the task of writing two games at once. The games will share some of the design, modules and behavior but will act as a seperate project altogether. The shared components will have to be general and reuseable and in the same time implement as much of the game-specific functionality as possible.</p>
<p>Both of these classic games are pretty much comprised of the same mechanics: a deck of shuffled cards which has to be re-organized into 4 stacks of ascending-same-suit cards. In the course of the games cards are needed to be arranged also in ascending order, however in a stack of alternatly-changing red/black order.</p>
<p><span id="more-35"></span>Learning from the <a title="Speed Challange: MineSweeper – Postmorterm" href="http://gilzu.com/?p=27" target="_blank">Minesweeper Speed Challange</a> I decided to start the design process with Use-Cases. There will be a single Use-Case document for both of the games defining the common Use-Cases in a joined section and the specific Use-Cases in a seperate section. This time, I plan to follow this stage with a Class-Diagram that will contain each of the processes defined in the Use-Case document and by the GUI.</p>
<p>The solution file will also consist out of three projects: Solitaire, FreeCell and the Common Assembly that will contain the features that are common to both games as defined in both the Use-Case and the Class Diagram. The common assembly is to be written so that it will be able to be re-used in a (possible) future project without any modification.</p>
]]></content:encoded>
			<wfw:commentRss>http://gilzu.com/?feed=rss2&#038;p=35</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Speed Challange: MineSweeper &#8211; Postmorterm</title>
		<link>http://gilzu.com/?p=27</link>
		<comments>http://gilzu.com/?p=27#comments</comments>
		<pubDate>Mon, 16 May 2011 20:40:14 +0000</pubDate>
		<dc:creator>Gil</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[MineSweeper]]></category>
		<category><![CDATA[Speed Programming]]></category>
		<category><![CDATA[Use Case]]></category>

		<guid isPermaLink="false">http://gilzu.com/?p=27</guid>
		<description><![CDATA[I first planned these speed challanges as a concentrated 3-4 hours of work in which I&#8217;d finish what I can. I started it a week ago and due to work/real life considerations, this was not possible. However, I did find &#8230; <a href="http://gilzu.com/?p=27">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I first planned these speed challanges as a concentrated 3-4 hours of work in which I&#8217;d finish what I can. I started it a week ago and due to work/real life considerations, this was not possible. However, I did find 30 minutes at the end of each day to finish this mini-project &#8211; and I think it was well worth the time.</p>
<div id="attachment_30" class="wp-caption alignnone" style="width: 246px"><a href="http://gilzu.com/wp-content/uploads/2011/05/minesweeper.jpg" target="_blank"><img class="size-medium wp-image-30 " title="Minesweeper Application" src="http://gilzu.com/wp-content/uploads/2011/05/minesweeper-236x300.jpg" alt="" width="236" height="300" /></a><p class="wp-caption-text">Minesweeper Application</p></div>
<p><span id="more-27"></span>Staying concentrated and task-oriented at the end of a work day wasn&#8217;t easy. However, since the entire design was well-written as Use-Cases. Each Use-Case was a function or a module and their contents was laid out as comments inside to follow each line or two with the code. However, the final touch-ups did not appear in the Use-Case as I thought. Highscores and Custom games were not mentioned and were programmed in a single session without pre-design or documentation.</p>
<p>Since these features were not documented, I did have to invest more time and be more alert writing slightly more complex code. Heck, it took about 10-15 minutes more &#8211; but considering the fact that this was a pilot for a large-scale project, I think it might work for the best to come back to the drawing board before adding / changing significant features.</p>
<p>Debugging took less time as well &#8211; most of the scenarios were well thought in the design stage of the Use-Case and covered about 80% of the bugs I usually end up fixing in this stage. It will be more interesting to re-program a more complex past project such as Checkers / Chess (with AI) to test whether time spent on Use-Cases takes less time than fixing the errors caused by not using them. In such small scale project, the time spent on either is insignificant but does give insight on the time it will take on larger projects.</p>
<p>I&#8217;ve attached the application here for impression: <a href="../wp-content/uploads/2011/05/Minesweeper.exe">Minesweeper</a></p>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://gilzu.com/?feed=rss2&#038;p=27</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Speed Challange: MineSweeper – Actual Programming</title>
		<link>http://gilzu.com/?p=15</link>
		<comments>http://gilzu.com/?p=15#comments</comments>
		<pubDate>Mon, 16 May 2011 06:39:15 +0000</pubDate>
		<dc:creator>Gil</dc:creator>
				<category><![CDATA[Speed Programming]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[MineSweeper]]></category>
		<category><![CDATA[Use Case]]></category>

		<guid isPermaLink="false">http://gilzu.com/?p=15</guid>
		<description><![CDATA[Since most of the design was documented and well-defined by the Use-Cases, I decided to go in a Copy/Paste approach: I would take the Use-Case directly into the development environment and translate each line into code. About 80% of the &#8230; <a href="http://gilzu.com/?p=15">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Since most of the design was documented and well-defined by the Use-Cases, I decided to go in a Copy/Paste approach: I would take the Use-Case directly into the development environment and translate each line into code.</p>
<div id="attachment_17" class="wp-caption alignnone" style="width: 310px"><a href="http://gilzu.com/wp-content/uploads/2011/05/minesweeper1.jpg" target="_blank"><img class="size-medium wp-image-17 " title="Minesweeper Speedchallange" src="http://gilzu.com/wp-content/uploads/2011/05/minesweeper1-300x239.jpg" alt="Taking Use-Case text and transforming it into code" width="300" height="239" /></a><p class="wp-caption-text">Minesweeper code</p></div>
<p><span id="more-15"></span></p>
<p>About 80% of the methods i wrote involved translating 2-3 sentences in English into C#. Since most of the logic was already encompassed within those lines, it allowed me to steamroll through the code without straying through the design process.</p>
<p>Even though the task of writing the code took much less time, the code came out much more organized and well documented.There were a few processes which the Use-Cases did not cover such as the GetNumberOfSorroundingMines(). I admit that I did not had them in mind while writing the Use-Case document.</p>
<p>I found that they contained absolutely zero comments. But since they contained such a low code complexity &#8211; writing such amount of Use-Case and code comments will be either a design overkill or unnecessary time overhead to such secondary code.</p>
<div id="attachment_20" class="wp-caption alignnone" style="width: 310px"><a href="http://gilzu.com/wp-content/uploads/2011/05/minesweeper31.jpg" target="_blank"><img class="size-medium wp-image-20 " title="Minesweeper non-Use-Case method" src="http://gilzu.com/wp-content/uploads/2011/05/minesweeper31-300x148.jpg" alt="Minesweeper non-Use-Case method" width="300" height="148" /></a><p class="wp-caption-text">Minesweeper non-Use-Case method</p></div>
<p>I found it most useful to use the NotImplementedException as a bookmark to jump between implementation of methods. Some of the Use-Cases contained references to other and in some cases I had to take actual breaks which left loose-ends in my code.</p>
<div id="attachment_22" class="wp-caption alignnone" style="width: 310px"><a href="http://gilzu.com/wp-content/uploads/2011/05/minesweeper2.jpg" target="_blank"><img class="size-medium wp-image-22 " title="Minesweeper Code" src="http://gilzu.com/wp-content/uploads/2011/05/minesweeper2-300x277.jpg" alt="Minesweeper Code" width="300" height="277" /></a><p class="wp-caption-text">NotImplementedException</p></div>
<p>A few more features are left such as the High scores table and the game timer, but other than that &#8211; the minesweeper is pretty much done <img src='http://gilzu.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://gilzu.com/?feed=rss2&#038;p=15</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Speed Challange: MineSweeper &#8211; Use Cases</title>
		<link>http://gilzu.com/?p=10</link>
		<comments>http://gilzu.com/?p=10#comments</comments>
		<pubDate>Fri, 13 May 2011 11:34:20 +0000</pubDate>
		<dc:creator>Gil</dc:creator>
				<category><![CDATA[Speed Programming]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[MineSweeper]]></category>
		<category><![CDATA[Use Case]]></category>

		<guid isPermaLink="false">http://gilzu.com/?p=10</guid>
		<description><![CDATA[For my first speed challange I decided to take a small and well defined application so that i&#8217;d be able to examine how well using Use Cases contributes to my productivity as a programmer. Took me an hour to lay &#8230; <a href="http://gilzu.com/?p=10">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>For my first speed challange I decided to take a small and well defined application so that i&#8217;d be able to examine how well using Use Cases contributes to my productivity as a programmer. Took me an hour to lay out a list of MineSweeper&#8217;s Use Cases that defines the mechanics of the application.</p>
<p>I tired to be <a title="Effective Use Cases" href="http://www.gatherspace.com/static/use_case_example.html">more productive without being over perfectionist</a>, following a defined format for each Use Case so I won&#8217;t get over-zealous with the design and sticking to the standard.</p>
<p>Here&#8217;s what I came up with:</p>
<p><span id="more-10"></span></p>
<h1>Use Case: Create New Mine Placement Board</h1>
<p>Activating Actor: The System.</p>
<p>Description:  The system asks for new placements of mines on the board. This should not be confused with Use Case: Create game which initialized the board shown to the user and the user markings.</p>
<h6>Preconditions:</h6>
<ul>
<li>A board size must be set.</li>
<li>Number of mines for this board size must be set.</li>
<li>The number of mines should never be equal or greater to the number of squares on the board minus the first selected square.</li>
</ul>
<h6>Basic Flow:</h6>
<ol>
<li>Create a list of the possible locations.</li>
<li>Create an empty board according to the board created in the last Use Case: Create game.</li>
<li>For each mine needed:</li>
</ol>
<ul>
<li>Remove a random location from the possible location list</li>
<li>Mark a mine on that location</li>
</ul>
<ol>
<li>Initialize and Start the game stop-watch.</li>
<li>Reset mine marked counter.</li>
</ol>
<p>&nbsp;</p>
<h6>Exceptions:</h6>
<p>None, so far.</p>
<h1>Use Case: Clear Mine Square</h1>
<p>Activating Actor: The User, and in case of [Exception 4.1], The System.</p>
<p>Description: The user left-clicks a square to clear it and test whether it contains a mine.</p>
<h6>Preconditions:</h6>
<ul>
<li>Square is on the board.</li>
<li>Game has not won yet.</li>
<li>Square has not already cleared.</li>
<li>Square is not marked as containing a mine by the user as described in Use Case: Mark Possible Containing Square Mine.</li>
<li>Check for game end condition as described in Use Case: Check for Win.</li>
</ul>
<h6>Basic Flow:</h6>
<ol>
<li>User left-clicks a square.</li>
<li>If no square has been cleared before, create new board to make sure no mine will ever explode on the first clearance – refer to Use Case: Create Mine Placement Board.</li>
<li>Check if a mine is located under this location</li>
<li>Show the number of mines surrounding this square.</li>
</ol>
<h6>Exceptions:</h6>
<p>3.1. [A mine is located underneath this location]</p>
<ul>
<li>If so, end the game – refer to Use Case: Game Lost.</li>
</ul>
<p>4.1 [The number of mines is 0]</p>
<ul>
<li>Activate this use case recursively for each of the surrounding  squares.</li>
</ul>
<p>&nbsp;</p>
<h1>Use Case: Clear Surrounding Mine Square</h1>
<p>Activating Actor: The User.</p>
<p>Description: The user to clear every surrounding square according to Use Case: Clear Square.</p>
<h6>Preconditions:</h6>
<ul>
<li>Square must be on the board.</li>
<li>Game has not won yet.</li>
<li>Square must already be a cleared square according to Use Case: Clear Square.</li>
<li>The number of user marked squares according to Use Case: Mark Possible Containing Square Mine surrounding the selected square should be equal the mines declared on the square.</li>
</ul>
<h6>Basic Flow:</h6>
<ol>
<li>The user releases both right and left mouse buttons on a square.</li>
<li>Every surrounding square is cleared according to Use Case: Clear Square.</li>
</ol>
<h6>Exceptions:</h6>
<ul>
<li>None so far</li>
</ul>
<p>&nbsp;</p>
<p>&nbsp;</p>
<h1>Use Case: Game Lost</h1>
<p>Activating Actor: The System.</p>
<p>Description: Once the game is lost, show every mine marking and non-mine marking on the visual board.</p>
<h6>Preconditions:</h6>
<ul>
<li>A mine-placement board must have been created.</li>
</ul>
<h6>Basic Flow:</h6>
<ol>
<li>For each of the visual squares:
<ol>
<li>Remove any player marking on the mine.</li>
<li>Display the number of mines underneath or a mine present.</li>
<li>Stop the game stop-watch.</li>
</ol>
</li>
</ol>
<h6>Exceptions:</h6>
<ul>
<li>None so far</li>
</ul>
<h1>Use Case: Check for Win</h1>
<p>Activating Actor: The System.</p>
<p>Description: The system checks whether the player has successfully finished the game.</p>
<h6>Preconditions:</h6>
<ul>
<li>Every square had either been cleared as described in the Use Case: Clear Square or had been marked as described in the Use Case: Mark Possible Containing Square Mine.</li>
<li>The mine counter is 0.</li>
</ul>
<h6>Basic Flow:</h6>
<ol>
<li>Check if every marked mine location is right.</li>
<li>End the game.</li>
<li>Check For a new High-Score.
<ol>
<li>If it’s a high-Score, replace the current one.</li>
</ol>
</li>
</ol>
<h6>Exceptions:</h6>
<p>1. [a mine is located in an incorrect location]</p>
<p>1.1. Continue the game and stop at [1.]</p>
<h1>Use Case: Mark Possible Containing Square Mine</h1>
<p>Activating Actor: The User.</p>
<p>Description: Player right-clicks a square to remember that it might contain a mine.</p>
<h6>Preconditions:</h6>
<ul>
<li>Square is on the board.</li>
<li>Square had not been cleared as described in Use Case: Clear Mine Square.</li>
<li>Game has not won yet.</li>
</ul>
<h6>Basic Flow:</h6>
<ol>
<li>User right-clicks the square.</li>
<li>The system marks the square.</li>
<li>Check for game end condition as described in Use Case: Check for Win.</li>
<li>Decrease mine marked counter.</li>
</ol>
<h6>Exceptions:</h6>
<p>1.1. [A Square has already been marked as containing a square mine]</p>
<ul>
<li>Unmark it.</li>
<li>Increase mine marked counter.</li>
</ul>
<p>&nbsp;</p>
<h1>Use Case: Create New Game</h1>
<p>Activating Actor: The User.</p>
<p>Description: The User wishes to start a new game.</p>
<h6>Preconditions:</h6>
<ul>
<li>None so far</li>
</ul>
<h6>Basic Flow:</h6>
<ol>
<li>The user selects one of 3 difficulties:
<ol>
<li>Easy : 10&#215;10 Board with 10 mines.</li>
<li>Medium: 16&#215;16 board with 40 mines.</li>
<li>Hard: 30&#215;16 board with 99 mines.</li>
<li>According to [1.]:
<ol>
<li>The system redraws the screen.</li>
<li>Clears any marking on the visual board.</li>
<li>Resets the stopwatch.</li>
</ol>
</li>
</ol>
</li>
</ol>
<h6>Exceptions:</h6>
<ul>
<li>None so far</li>
</ul>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://gilzu.com/?feed=rss2&#038;p=10</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Serial Port Hell</title>
		<link>http://gilzu.com/?p=6</link>
		<comments>http://gilzu.com/?p=6#comments</comments>
		<pubDate>Tue, 10 May 2011 21:37:45 +0000</pubDate>
		<dc:creator>Gil</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[9-Bit]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Driver]]></category>
		<category><![CDATA[P/Invoke]]></category>
		<category><![CDATA[Parity Bit]]></category>
		<category><![CDATA[SerialPort]]></category>
		<category><![CDATA[Windows API]]></category>

		<guid isPermaLink="false">http://gilzu.com/?p=6</guid>
		<description><![CDATA[Had to implement a 9-bit serial port protocol under c#. Normally, the 8 bit information transfer is supported by the .NET SerialPort class, whereas the extra bit is used for parity check. To send a 9 bit through the serial &#8230; <a href="http://gilzu.com/?p=6">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Had to implement a 9-bit serial port protocol under c#. Normally, the 8 bit information transfer is supported by the <a title=".NET Serial port class" href="http://msdn.microsoft.com/en-us/library/system.io.ports.serialport.aspx" target="_blank">.NET SerialPort class</a>, whereas the extra bit is used for parity check.</p>
<p>To send a 9 bit through the serial port is pretty easy: Send the first 8 bits normally with either a Mark(=1)/Space(=0) parity setting for the extra 9th bit.</p>
<p>The hell I went through involves SENDING each 9 bits, and this is where my story starts&#8230;</p>
<p><span id="more-6"></span></p>
<p><strong>Using the .NET SerialPort Class</strong></p>
<p>To recieve byte, I set my serial port to a Space(=0) parity setting, and for each byte I would check for a parity error. No parity error = 9th bit 0, whereas a parity error = 9th bit 1.</p>
<p>Sounds easy, right? WRONG!</p>
<p>.NET Serial Class gives you 2 interfaces to identify parity errors. The first is an event called <a title="ErrorRecieved" href="http://msdn.microsoft.com/en-us/library/system.io.ports.serialport.errorreceived.aspx" target="_blank">ErrorRecieved</a> which according to MS:</p>
<blockquote><p>ErrorReceived events may be called out of order, and there may be a slight delay between when the underlying stream reports the error and when code can when the event handler is executed.</p>
<p>The ErrorReceived event is raised on a secondary thread when an error is received from the <a href="http://msdn.microsoft.com/en-us/library/system.io.ports.serialport.aspx">SerialPort</a> object. Because this event is raised on a secondary thread, and not the main thread</p></blockquote>
<p>According to this and the event delegate signature, when a parity error occures you can not rely it will happen in a reasonable time nor will you know on <strong>which</strong> of the bytes the error had occured.</p>
<p>Second way is to use the <a title="ParityReplace" href="http://msdn.microsoft.com/en-us/library/system.io.ports.serialport.parityreplace.aspx" target="_blank">ParityReplace member</a> which quite effectively, replace a parity errored-byte into a value of your choosing. This allows parity detection for the price of the 8 bits it follows. No good as well.</p>
<p><strong>Using Windows API functions</strong></p>
<p>There&#8217;s a bunchload of <a title="Serial Port Related resources" href="http://www.lvr.com/serport.htm" target="_blank">Serial Port related</a> resources about <a title="P/Invoke" href="http://pinvoke.net/" target="_blank">P/Invoking</a> a <a title="Windows API Serial port functions in a .NET Environment" href="http://msdn.microsoft.com/en-us/magazine/cc301786.aspx" target="_blank">lower-level Windows API functions</a> to handle serial-port communication, which hopefully give me some solution to my problem.</p>
<p>So I wrote a new SerialPort class which encapsulates the P/Invoke&#8217;ed Win32 API functions using some <a title="Windows API SerialPort Example" href="http://www.codeproject.com/KB/system/SerialPortComm.aspx" target="_blank">nice examples across the web</a>. This time, detecting a parity error went without a hitch, I&#8217;d <a title="ReadFile Example" href="http://msdn.microsoft.com/en-us/library/aa450604.aspx" target="_blank">ReadFile</a> a single byte from the port and then <a title="GetLastError()" href="http://msdn.microsoft.com/en-us/library/ms679360%28VS.85%29.aspx" target="_blank">check for the last error</a> for a parity problem. Another nice touch is to use the <a title="DCB" href="http://msdn.microsoft.com/en-us/library/aa363214%28v=vs.85%29.aspx" target="_blank">fAbortOnError member in the DCB</a> which stops all read operation upon stumbling an error (specifically, a parity error).</p>
<p>This proved to be a working solution, until it was used under the production environment. It appeared that detecting parity errors (the 9th bit) worked inconsistently. Further inspection of both the program and the <a href="http://www.motherboardpoint.com/mscomm-vc-parity-error-t155403.html" target="_blank">web</a>, revealed that the root of the problem lies in a much lower level &#8211; the windows serial.sys device driver.</p>
<p><strong>The Serial Port Device Driver</strong></p>
<p>Every unhandled incoming data recieved by the serial port is queued into the driver FIFO buffer to be handled by the next API read. Whoever wrote this driver, only queued the recieved bytes and not the recieved data (both the 8 bits and the parity bit). So if your program is polling information fast enough not to let any byte enter the buffer you&#8217;re safe, and if you plan any other non-serial-polling-software-centric you&#8217;re not.</p>
<p>So i turned to the <a title="Windows Driver Kit" href="http://msdn.microsoft.com/en-us/windows/hardware/gg487428" target="_blank">Windows Driver Kit</a> to revise the current <a title="Serial.sys" href="http://msdn.microsoft.com/en-us/library/ff542632%28v=VS.85%29.aspx" target="_blank">serial.sys (code included with the WDK)</a> driver to fit to my needs. It took a while, but now when the serial port recieves a byte, it enqueues two bytes: the recieved byte and the parity.</p>
<p>Problem solved.</p>
]]></content:encoded>
			<wfw:commentRss>http://gilzu.com/?feed=rss2&#038;p=6</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
