<?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>Swing &#8211; Henry Poon&#039;s Blog</title>
	<atom:link href="https://blog.henrypoon.com/blog/tag/swing/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.henrypoon.com</link>
	<description></description>
	<lastBuildDate>Tue, 04 Oct 2022 21:49:22 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	
<site xmlns="com-wordpress:feed-additions:1">83044199</site>	<item>
		<title>A very brief tour of Reykjavik</title>
		<link>https://blog.henrypoon.com/blog/2019/01/17/a-very-brief-tour-of-reykjavik/</link>
					<comments>https://blog.henrypoon.com/blog/2019/01/17/a-very-brief-tour-of-reykjavik/#respond</comments>
		
		<dc:creator><![CDATA[hp]]></dc:creator>
		<pubDate>Fri, 18 Jan 2019 03:04:46 +0000</pubDate>
				<category><![CDATA[europe]]></category>
		<category><![CDATA[Animals]]></category>
		<category><![CDATA[architecture]]></category>
		<category><![CDATA[Beef]]></category>
		<category><![CDATA[beer]]></category>
		<category><![CDATA[Brennivín]]></category>
		<category><![CDATA[cafe loki]]></category>
		<category><![CDATA[candy]]></category>
		<category><![CDATA[Chinese people]]></category>
		<category><![CDATA[Chocolate]]></category>
		<category><![CDATA[Cola]]></category>
		<category><![CDATA[COM]]></category>
		<category><![CDATA[Countries]]></category>
		<category><![CDATA[D]]></category>
		<category><![CDATA[Euro]]></category>
		<category><![CDATA[Europe]]></category>
		<category><![CDATA[Event]]></category>
		<category><![CDATA[fish]]></category>
		<category><![CDATA[food]]></category>
		<category><![CDATA[Food and drink]]></category>
		<category><![CDATA[Go]]></category>
		<category><![CDATA[Hákarl]]></category>
		<category><![CDATA[Hallgrimskirkja]]></category>
		<category><![CDATA[iceland]]></category>
		<category><![CDATA[Icelandic cuisine]]></category>
		<category><![CDATA[IDE]]></category>
		<category><![CDATA[IME]]></category>
		<category><![CDATA[ise]]></category>
		<category><![CDATA[It]]></category>
		<category><![CDATA[Lag]]></category>
		<category><![CDATA[lamb]]></category>
		<category><![CDATA[Light]]></category>
		<category><![CDATA[Lost]]></category>
		<category><![CDATA[Meat]]></category>
		<category><![CDATA[minke whale]]></category>
		<category><![CDATA[Outside]]></category>
		<category><![CDATA[Pho]]></category>
		<category><![CDATA[Potato]]></category>
		<category><![CDATA[puffin]]></category>
		<category><![CDATA[rain]]></category>
		<category><![CDATA[Sauce]]></category>
		<category><![CDATA[Seattle]]></category>
		<category><![CDATA[shark]]></category>
		<category><![CDATA[Sharks]]></category>
		<category><![CDATA[STR]]></category>
		<category><![CDATA[Swing]]></category>
		<category><![CDATA[tapas barinn]]></category>
		<category><![CDATA[Thou]]></category>
		<category><![CDATA[Time]]></category>
		<category><![CDATA[YouTube]]></category>
		<category><![CDATA[Z]]></category>
		<guid isPermaLink="false">https://blog.henrypoon.com/?p=3319</guid>

					<description><![CDATA[Seeing that I spent so much time outside of Reyjavik, I really only spent a handful of hours here and there in this city. The best experience I had here was eating all the different kinds of stereotypical Icelandic food! On my first night staying in Reykjavkik, I had the &#8220;Icelandic Gourmet Feast&#8221; at Tapas [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">Seeing that I spent so much time outside of Reyjavik, I really only spent a handful of hours here and there in this city.  The best experience I had here was eating all the different kinds of stereotypical Icelandic food!  On my first night staying in Reykjavkik, I had the &#8220;Icelandic Gourmet Feast&#8221; at <a rel="noreferrer noopener" aria-label="Tapas Barinn (opens in a new tab)" href="http://www.tapas.is/en/" target="_blank">Tapas Barinn</a>.  The name of that sounds totally like something like you would see from a tourist trap kind of place (I highly doubt locals eat this stuff on the regular), but everything was really good and I still recommend it even after going!</p>



<figure class="wp-block-image"><a href="https://photos.google.com/share/AF1QipP6VOT6wbagLRnCE2QVVvZhi_GnWhjJxGDM88xCkgGRF3KxzXgUcHRFxQWt5XjBVw/photo/AF1QipN4oQaYGAXG57RlZv1jFKtiBVAucglQFS1UJwxD?key=cHNJZmoxV1N5NUxkQm8zR1ZNaUVMSk40clJVN2N3" target="_blank" rel="noreferrer noopener"><img decoding="async" src="https://lh3.googleusercontent.com/sSB4tRWgx_qe7fxo7j2Rw73hZRxZnzDulDIP3qbGiPco6QiCQNXVq4ykEgzAi5CRzfkHsBMyBV0j3kpKJt-RaNHtIEZw_6Q5ZgmydkAQBw40x1YY_xDkLACev0QYGz3kqrJuWXOfQj_deZtqkWj2EiNfjiBmuGzoe-kHvMyAymrEjCI6bBSD8WM5CMWWd5sxCE_qVXanzpI0YSmRfRwNF7ua3o7i9zVQ0Tnx8FcGYsHgkPNa7HdJZglSfgt48P-K8ecc4AaEkb_bu2i-ATXyEwy09xLHKP45963yaqVplzAoJLe6YYr8CjfCOVEoQip55OwAFXMHDIunO6UmJ49Reu9HFe7A4zLVr7Oi3X2MhVfXDeoJhB8DpRgMfl9lDoHYUw5eQ7hGHbGtu03lQklHgXswEdG9rynirQ9a71H2l5QyxMZ1NrQPPJtlKW0b6e0JxGkb3knnkx01qWBQPA3NtZv2QIEqqSBTRKxdJioBCnqPHXwNuN5aWq-HNpDULev7bzwE-wq-1b9sdE4Y-x2GrFIyl12RWFtItNRKcxzRvIWG0WijhREjWF47RxpQz1YYTp3KXTmasP14bz5yS7sPPbMOJcbqH1nZgPx09l8ZRqKJXBliYVwGy4rSH_xQ0Q6SlbmwB7VP9mvXHMMayGbXFd2QbTd78SgCVslusZukYlPSVxRx6JhEy1EOXwtgQSjqNtaNnBK3mw4bAt-0y6E=w1464-h824-no" alt=""/></a><figcaption> Smoked puffin with blueberry “brennivín” sauce</figcaption></figure>



<figure class="wp-block-image"><a href="https://photos.google.com/share/AF1QipP6VOT6wbagLRnCE2QVVvZhi_GnWhjJxGDM88xCkgGRF3KxzXgUcHRFxQWt5XjBVw/photo/AF1QipNwKdk023b1AV2IdQfLzF1-j_MtPmpqBGX5wRyC?key=cHNJZmoxV1N5NUxkQm8zR1ZNaUVMSk40clJVN2N3" target="_blank" rel="noreferrer noopener"><img decoding="async" src="https://lh3.googleusercontent.com/SQBFzDtDk0BnYLYPpkBVOcRevr06Q7Pew-2EbHB_c1CyUwu0tQh0w_EdAVPAegToIPgJ-1Ders45m7pCe6dKJaI8Qcz_3skZ6-W42D1xRIKJTaaCHxer43R7VoZEzOOZZ98py4ZC0GcRuUQ_FQPS1N2nLl4eTq0Ixyco3f2zRr5-KF0rAd3JQiezS0fn-OS5tVOhiwJn2zoTIyYTCTh-ntCHSzypjQPOSFpmnqILLRmaA9jjG8qmmaJYNbpV3XpGJqxmoHCnwYWVResvJpNZ7tcYWOSoXnWGsHBa3Hfv7IzRXqeg_L-bOujOcrU4IQWwicgNHicgOW_iPiGDSBKAe72jcpJZ28vIg-db_p_O2a1cqOojh1oAGyMnLGd03VHXXxmIuWnpjUpf61JwGtRTXBhGbgKIzA6bd_jrBuTWll9uxEPzRKQRZj2HgpR-pfCClaG7T557cTPU1fCAwBLuMJvl0Fx4eWk7WKnMwldb2s4P-Zeecw2y-edwL8CDQ-6BbShzJdWZzxPIPspeap6m_pRU-gEsOuZWQNU8mg42HUkdfNTrotf7UJHeVQumLlNrFKErcbu6dMMiluR9lvaAJ5mclVHaBxcoFGI7TJMDujcS19v6to_D4RQZX59Jab1renIwu2rnvWpwG1OQLr8xi_ore1S0fXs8XQrVEmvcbvk_ENQGi0GWPgMhRdP_sFm3YbDmzrBQ6HgCvGWYoqk=w1464-h824-no" alt=""/></a><figcaption> Lobster tails baked in garlic</figcaption></figure>



<figure class="wp-block-image"><a href="https://photos.google.com/share/AF1QipP6VOT6wbagLRnCE2QVVvZhi_GnWhjJxGDM88xCkgGRF3KxzXgUcHRFxQWt5XjBVw/photo/AF1QipOFg-DgeW_tS62Rbhhpz34WoIvE-TLxqROVZvLi?key=cHNJZmoxV1N5NUxkQm8zR1ZNaUVMSk40clJVN2N3" target="_blank" rel="noreferrer noopener"><img decoding="async" src="https://lh3.googleusercontent.com/1UXTulKyb_ToEct1ZXsn5-onsjyhTs6L1Qtz-gFVmLCGJQ0WUvaxOd5WbbKINydS4NcOx5ZG4JR072FzzgUQY5rIuerUIvRwt16uCefqM7XQacJLWOd5AkgPrCRJqzOgkjeBlpJSbi3LGaRmv0xz-Sn0DKIHSAOEldkp3Jl92N5KEIDMegoCxxaVOgRuQbIu89kSRPryDmOR4SMLJhQzunOFcWXSiUTIsc8_Jv7WKG38ZFXgQYhAYo6kd7UmB4hqGAPwIAh-MHwdlzrnwUxikMIi5ZTDpz616wOfigeYpK7i21D0Iut4qe16fFkn-OpFPcmzpGtoTh0KL7L5iqlGGo14Q1pjfvfXLPeKFGzrJTZx6ZadUaoWnsfc3lBVbA_Qg_JcDu-tBO20N25zN0LHDFbZHYNUFnF-ksBhNYk9vORAdukQm9TEPZfwqCDGSx3xXABlFfPG5ZwezUFugEmbBHZwsUvAZeHrjHf8fp9WOA5xhdvs0_UUf_CZumkkFPUKLex5Cjq-onw7Dt2eu7u21SC8ugRj83TS6osH1o3GOdcbk3UUnhKwvUSg4zzpZXm4rNJyHzj6lirffAOUSjtfZClkWvjrJJCcpj9hkhe_krO9WwlIKnMB1YIrODZgwu1mMldPdfXOSpbCA7rmoDhg45ay7LfyA6ub2V--z18i-PayfyvtQAS_ad-UHTHjC7oLKjMcVclrKYHRezgnNSs=w1464-h824-no" alt=""/></a><figcaption>   Icelandic arctic char with candy beets salad, asparagus and elderflower-hollandaise</figcaption></figure>



<figure class="wp-block-image"><a href="https://photos.google.com/share/AF1QipP6VOT6wbagLRnCE2QVVvZhi_GnWhjJxGDM88xCkgGRF3KxzXgUcHRFxQWt5XjBVw/photo/AF1QipPF-TLikMGeU-P8OFKG92PdoopkRvLgScfR9nHh?key=cHNJZmoxV1N5NUxkQm8zR1ZNaUVMSk40clJVN2N3" target="_blank" rel="noreferrer noopener"><img decoding="async" src="https://lh3.googleusercontent.com/D8F9dqItxhETmv3dDSZbLTNbGDvOEyoVNRZHsmpmWI2iOFhcbD3MoeZwxASUj482JxbLMXFt0VxNDRQCTke0ROIUOYPQBCXVaqCk2csaIkjPuKfndltc5qN4LaS_0VkxJXMor1HGhbITqFV5AYibmRFlT7mf2WLTa3qI7kHJaeBK1wVc6vLuvN0vldtb0jIDi7Ih9YpN24n4GUzRjahWP-iLt5PDZeXfZQadyJ2lWDRscux6ppDvnrQpSgpy7aK46dVMel2IF8VwWTj04YdG2E2pbCB-2K7qdo9jODBG5chAwlv0uVcTN_nNg1kMz8Q3Z9YqVGTsSXLIkj8XaNpMrFURfqfE8lzbhxc7oqDj8ysoERSP0ZgR_Ocow8CcUfupzneoxBbpzdzF_PIg9fG4bQCmeeSf5bXUg93FEIKYr043uX0XxuED47Q6_J6eBl_rvmMupSWNgfpTKUh_7mrldmdFgIvxODrZa_Mrm0sKQOtS9tWTb_iZXV3L-mV_fF45J-Wt3wtQ_Rvh0UL-7e71UFOF0s7qm8WkqGIpDKZoAQ0w0pKUnU1OpkN7UsVI4XZ1Rv0f7cVtvEiaddwuBWCMMXSGRJNbfFuLWR_-JmS8XT9dekPCr8xZihIHwSRqSk_thgL5uDkWByFxRFOkygP9wji3dV2Z2n8C95zlzS6UE-sgVqHWAXkNG7n77RsF-hrlfKP7mlN4q5MlCOhlVUM=w1464-h824-no" alt=""/></a><figcaption> Pan-fried blue ling with lobster sauce</figcaption></figure>



<figure class="wp-block-image"><a href="https://photos.google.com/share/AF1QipP6VOT6wbagLRnCE2QVVvZhi_GnWhjJxGDM88xCkgGRF3KxzXgUcHRFxQWt5XjBVw/photo/AF1QipMzaNROFDhEMDOHTHaoL-AWlzkcG7igb_SQLv73?key=cHNJZmoxV1N5NUxkQm8zR1ZNaUVMSk40clJVN2N3" target="_blank" rel="noreferrer noopener"><img decoding="async" src="https://lh3.googleusercontent.com/3ORa0NdCj48yqjTRKpKol9HBtW_NvXzFb7kU_AR54CRIEha6WV6j2DJ_tr14Hp28vYrBcn_y_OLctbE5QAq3gJQLLP1xq_09_30M-o8FWPs4_GK7uIOvznpJ8eH4BnxTr_LolQkE9SGb4UojM2rMJuXn-Hhr4BJrNQQUiSRIk7Q8oTDnO5h16llCmIVGgFXr0TewApNyXQEm7W36L7fuDViYJUKBh-TgKKQybAAS6-CMYe1drbt7SpOuJNSJ17b2lresvBiZvt0fjHxlOvTQux0zbSLSZ_PLF_qB5K5OfNSGl3wPrcy0bKghQ3KdbyXt6Uxny-f7s1zk7_xZpuSRW3T1RqXjTrHnQ558BL8z98cVxHDYHqZOW-vZnDE7LA3JVCklcw0DLt71CUIiHimGxUiSx9eIQFZd3xZtbvXOpfTlAcOxGODqaVA56g_sYRkMYLW36_4pM18msMbWUOmkTn6hPUQzLagmFt9Hr9Nmu1r0Q0aSTbVsRZFtZ4aSWctep_qkqTuUkca-422LD5aqEZNmiZyL41UuER5JCkp8BAw6RfO-HDIxksBiXZlsNMzJYBsqknvQCzA65Ie4gwLLeDecyPRtExmXSof9ZBn5IQm9mQl8PW6COFrFJ-fvTBozaR1oR63blMSK1SV1YjULJQqG0uh9lsMH8W7obbMC9lesTvfVjhUF0NDxU5HZ8xR_WJzatWsWY6FZrS2Vr9I=w1464-h824-no" alt=""/></a><figcaption> Grilled Icelandic lamb tenderloin with beer-butterscotch sauce</figcaption></figure>



<figure class="wp-block-image"><a href="https://photos.google.com/share/AF1QipP6VOT6wbagLRnCE2QVVvZhi_GnWhjJxGDM88xCkgGRF3KxzXgUcHRFxQWt5XjBVw/photo/AF1QipOEIL0pAb3tWwboES31uBHZtr8oIE6bjbXpSwhT?key=cHNJZmoxV1N5NUxkQm8zR1ZNaUVMSk40clJVN2N3" target="_blank" rel="noreferrer noopener"><img decoding="async" src="https://lh3.googleusercontent.com/OxSBxjRVyHEtF_3gqbdgQOw0x8QIAepG3wJYBai_maVG_MN4I5XjyO8OQ84b7-Hb_dm_JNgXMnNJicAZo2J07lOMhREOYiyvbsssiSePYkS2DeH_nZU4k0NpY2ABkEXKYhptynLM75gyoSqw9dOD05G6oFn0l6GTtqnUqzCWmGQQ1iX8ZwR0kMbUGp7Wm4lsdjwITUBk04PeiPv6SZEZuQNL7uIYdea-pqoV_ESoPdnOeVDbDeCuuQq203yMkgYsBhHDRVlhNtj_wSf7C82kxQHtTN_h-wTXP2fhJg9XP5_OlUqatDE9Zi0qIo9cku2n6IM0tqwlvhN49r0a1l1E8NdgvTTbGuza3cxdXrpy56HnDjN-GtHE-datnPV5N8puNdpRLnsbbt1PuzKEOCPlfMt6_LyzNEbkt-DiXPrIz8egUsxQ0r1lWRIiUo5-8L1BEXJ-hisLw6pU7NGJ-plIH9gUAa2_9B8UtMH65tRzymaBb06BLzKQwvJLBi935L95iTWDfMRFKo7mU1ya50L_J5Dx9LRkLogdiT4yuCwzFtyrsAwlc5ZHWhR77ih1QJi3ufakgP3QUYlbA69tbweZ_QXsTtpk1C3nuBZgk83UgAsYttZPHwwjHi_kUJvCiRM0xJuSsbPRD7La2DY-mrA2-lSzg5SHzSHHlsbnMuE72Pa_wmFdMQPqseDaVteOnUp-6Cxyjt5WZBgwG_XFZ44=w1464-h824-no" alt=""/></a><figcaption> Minke Whale with sweet potato mash and malt sauce</figcaption></figure>



<figure class="wp-block-image"><a href="https://photos.google.com/share/AF1QipP6VOT6wbagLRnCE2QVVvZhi_GnWhjJxGDM88xCkgGRF3KxzXgUcHRFxQWt5XjBVw/photo/AF1QipOdBYqqvE7v7KN1My9mGxswUVDZVuGRdSCYpp0_?key=cHNJZmoxV1N5NUxkQm8zR1ZNaUVMSk40clJVN2N3" target="_blank" rel="noreferrer noopener"><img decoding="async" src="https://lh3.googleusercontent.com/VCFKOZ4fHT6GXU-2bKXFSW6gMQBY3mWl_Ly0FuC1OTzxl2Kwh-ECot8N5qkD_2WnGJbQgprA5WvFjUAuGp6uY_oDQsW21J2OD76dlGbcGzzYj5B0FetoAJYoJnHsRS2OT5D4_UIIU4JPhlp5ExU4KdU9lyQG6gS9fBJ1KkuS_eE7wIJcaR-DN7wICmvuwqdt1tUc5gPQXmf74EEgG17mVCAydWuaDfl0XtOd2YAP0vnJK8g6Ut8DDm4PKtB6vTWY-ormAT5IMzPXMZ4-NxQrsSWNPiBhFzyJgCfBS4g-gPXlhl5G4N0NddjTDigpPOYVaHr2FTCvo6nB3uym4nFVo8PfXt5pl6gXsBJPrJfrEFKUgGJuHGcLXdT-5cxCdCxcSLmsw2eadplXOoKbJYn-bQKnLXq2YRRk3shq091e2KORwjgVcfzqmlczNQJtDb-EziqlEyvGoWXnxHjdbaZgE1l2M5fUhy0StJshg0uN13XDPkiOG8WYi0CY-4DMszzqT19yjEAt3LsnpcSNpt1WmMTzqORHgj4D-kEjhHjPeJ0QckYB69JmQYJvvWOVxQjnLRkYIBR8BHRK2q6tuMGonTNchZ5p4cbUtFBRe39yz3pVBhYDONb6quS64aDgM0iL44LS6ZbuXEE4t_el9VtQVhrRA8G1XCoJLtjNYwJVEcO0h737aWUjcuUdwEQ0YeAQMM3Cwl5DZAQh6FCWK8I=w1464-h824-no" alt=""/></a><figcaption>This was a lamb dish that I don&#8217;t remember what it was because it was on the house!</figcaption></figure>



<figure class="wp-block-image"><a href="https://photos.google.com/share/AF1QipP6VOT6wbagLRnCE2QVVvZhi_GnWhjJxGDM88xCkgGRF3KxzXgUcHRFxQWt5XjBVw/photo/AF1QipMFQghQ8PbejtriSC4-rWhGHSi3DtDuq6zVkzXu?key=cHNJZmoxV1N5NUxkQm8zR1ZNaUVMSk40clJVN2N3" target="_blank" rel="noreferrer noopener"><img decoding="async" src="https://lh3.googleusercontent.com/1zo1YqBqTTWQpu4hHH9BmenB5U_PZUYSqSzvn5V1od57nyHTx4UOZVZpl6JHKgvAXwlWrMbHKCQqrxO3xpAZYx03TzaLH0fdGvOrBzKbjv54mwzeagKhpjgIp7tb3zMcL0RgV-SKTHg0PMA7LBQAXXmUmRMGVCeusRENp0ngSKY6bcNlAempAcqd0-ojkiBh9t2Z3MX7jnaZVIJiPOjRN6AzOmLEoy4xY_Le14WTHhZ9g0CE-0UtwQXw8Srx6WsuiiDIyRbLVgx1TUJImr8UbKgxzyg1s4PrxzTfJya0vcfDS57U3veP3FdefnQHmG94xEPnem6Vs--OaldNQG_NW0ZICCCNe7qtCQp2Urq7CS5MPw0QrNejxEmiO8S4MvbT0Y27wS3CTO1btAoKWOlWDii_MtzLNLUb6NnXzJ3FCryV5tblvgXnyeHA2J6F4IIXCYEKkQvkXYyZLMJnxVm0u7zDutuMTbkwM626QZ4y3LUhP4PnqBu1O1e1C6Ira_8CsIqIfOff0rdaqShtRTmBURd7ybLVkl02904oqtAC9dL8V2_t6xH4koMf3bePJS_uVxYzh-j8f9C9VI4ErujB-f2oKRM9vd9zVvnEH82wmM3tnMi_f1tqBJ31ksAmgZhaGhr7QUDoRI67xO2zoR6YwmsJBJQqopMy2YNRj52G7fO_zEZ5nBPx20zjJ0K1sYpGGPGCT4Q_D5MTcFCTYpM=w1464-h824-no" alt=""/></a><figcaption> White chocolate &#8220;Skyr&#8221; mousse with passion coulis</figcaption></figure>



<p class="wp-block-paragraph">I was totally sold on this meal even before I went to Iceland. The part of this meal that I was most excited for was the puffin and the minke whale! I had never eaten them before! Puffin is supposed to have a bit of a fishy taste to it, but since it was smoked, that taste wasn&#8217;t very strong. It doesn&#8217;t really have a distinct flavour and was a bit chewy. It tastes a bit like minke whale, and minke whale tastes like really chewy red meat &#8211; without the strong flavours like beef, and not that fishy.  The lobster tails were also amazing. I didn&#8217;t even know lobsters can be this tiny, or maybe it was a crayfish that was lost in translation?</p>



<p class="wp-block-paragraph">Oh and it&#8217;s true what people say about Iceland being really windy.  I was told to open a car door slowly and to hold on tight as I open it to prevent the damage to the car door from swinging wide open from the wind.</p>



<figure class="wp-block-embed-youtube wp-block-embed is-type-video is-provider-youtube wp-embed-aspect-4-3 wp-has-aspect-ratio wp-embed-aspect-16-9"><div class="wp-block-embed__wrapper">
<iframe title="Iceland is windy" width="1280" height="720" src="https://www.youtube.com/embed/zFjejzclkE4?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
</div></figure>



<p class="wp-block-paragraph">Another place I went was <a rel="noreferrer noopener" aria-label="Cafe Loki (opens in a new tab)" href="http://loki.is/" target="_blank">Cafe Loki</a>, just outside the Hallgrimskirkja.  Everything tastes like what you&#8217;d expect, EXCEPT the thing in the middle.  That is Hákarl, whcih is fermetted shark meat.  Some people say it&#8217;s rotten shark.</p>



<figure class="wp-block-image"><a href="https://photos.google.com/share/AF1QipP6VOT6wbagLRnCE2QVVvZhi_GnWhjJxGDM88xCkgGRF3KxzXgUcHRFxQWt5XjBVw/photo/AF1QipMw7OaBQ7GpDKczaPYDqHY6qJ3szLgvQrbCuhZp?key=cHNJZmoxV1N5NUxkQm8zR1ZNaUVMSk40clJVN2N3" target="_blank" rel="noreferrer noopener"><img decoding="async" src="https://lh3.googleusercontent.com/J-8lpZnbnCbTDyeesEALZx65d_lviQpbxAY6KwoXNDjivjPq4MdEijEDcPILeWTB3uTiGltySlES-b47PRE86eMZByPTzFQHqCg7vtVHqmBN2phnIdlQWlBh-FnPfAAhQc_qXPrN7OP4kecLKKG7s2e0IyELMib6CzdYERbE_G-x6nJ3Ylxp_BP-OpR57Ya8Sc99IOJFUml66jV988iJAExOYRKWVrNBuLzHqEI4pQ6v7RLrOeGyzuOYzI-xqZ3CwPDh8viz-bxYkMVsZaz4FVsTND8hi-yFSnH508oToikxs5BTzmYq4aVFZpHE4NYRMbjfNg95KiJCZU_6NMGvmcoyjjsQ11aXWDC4lpp6nb9Nyu0y99V4dVcF8lmLqfL13aSYuZ4fwOqgSRlS2tNoGV0Xq2gWJZ8e-_-9noE2jVT28NVFogtHZs13G7X9pR3_hdW_CL353dT-r89CPSwtceoCb3tDmdy6ahCKY4rwaR8VMtngxpXVCH0ixBSeUbrKQtCPyqRifXun7pmJOtlsTy2-W8X9V9qii1xL447i1GfpNSZm5Zk7XMK-IhEAKfnRUvgYjUQGXusB9LlKgAIYV5WpVGqAMv85FJBE1mesoeuDnxgDVdNJb0eYWMSFTrCDgdYnoI9Hf6xo9S9SFacuvUWPfQlwbheeWD3I2f11H5SCW2uWwzsO3Px0FBK8LHpYCr5fS6QLI87LW7aA07g=w1464-h824-no" alt=""/></a></figure>



<p class="wp-block-paragraph">This isn&#8217;t shark fin like what Chinese people like to eat, but this is actual shark meat.  It&#8217;s a bit chewy and has a slightly sour flavour to it.  Would not eat again.</p>



<p class="wp-block-paragraph">After the meal, I checked out the Hallgrimskirkja.  It&#8217;s a church, but the architecture on the outside is quite unique!  It isn&#8217;t like the old baroque/gothic/etc style churches in a lot of parts of Europe.</p>



<div class="wp-block-image"><figure class="aligncenter"><a href="https://photos.google.com/share/AF1QipP6VOT6wbagLRnCE2QVVvZhi_GnWhjJxGDM88xCkgGRF3KxzXgUcHRFxQWt5XjBVw/photo/AF1QipNf2GKwXqyPKg5HeVbrfLTxYtF-enmwZiJiGu_9?key=cHNJZmoxV1N5NUxkQm8zR1ZNaUVMSk40clJVN2N3" target="_blank" rel="noreferrer noopener"><img decoding="async" src="https://lh3.googleusercontent.com/qAZzM2pLkX_30zdeLsWnnxm3Nolb4upxi4U3qN2Kq9FNip44heC_QqZh_3fcfejU8OnlKo6-pRsbncxzTJwmajRD2fH8TFZOWqiC5SH7RFZSUnWIF-FPWNCnE3KqSJ6xDPI8IJKagDh_8fVChkuQrnQNo0jIGgTfdH5s6pMyCPoYwO3M0fL9cTcyuMHaS3M1W3N_19SFs1Iks2av0GWj0NXMs0o5gfaQk_CHh36KuOwCS2BUCPjsftHbGZxo2O9u_5lTElYv540V37w4_m_ZnETMSdoRcbnbW8c3iSbwRMvTVeei5mFoPzAnU203Vkgm6o_uiUhdsY3kzhFiVEzzqnVqchj6y0wUA5p_Ks0pOdTN7b9UfKnnA4arooeNgWct_W8JL8wLWf8oLTmrFcTjKt4mJHR-GKumJUOnbysfkyML_8BSbGdwwFYvbEJKQpfoflbwGlgkfOfQi7t_1KeJKj8I7cnX1W_GZeFk5WLF-HNm7EL-1lcZeQpL39TYese3i0Cx2I0omqDWlKKJEbAkAZv998kU7sZRbrjDres8u9NFO32mwe_LdEhfSRXSUn9G033WWgMvsTuueg_txj6tsldZid3HSvYKKbNqUC195gmRTYOYSjjlbOZj_5S7SUp8dkTDto6d3198QNbjlShDtZYPTFZUNQ6iMVwUkM5uVfO5HSCZlK7PDJUUOTsVbk3Ft6YKDtXdP-gCH9V93eU=w533-h946-no" alt=""/></a></figure></div>



<p class="wp-block-paragraph">I got to try some craft beers as well.  They were pretty good &#8211; not better or worse than the craft beers I&#8217;m used to drinking.  I do live in Seattle, so that might speak highly of Icelandic craft beers!</p>



<figure class="wp-block-image"><a href="https://photos.google.com/share/AF1QipP6VOT6wbagLRnCE2QVVvZhi_GnWhjJxGDM88xCkgGRF3KxzXgUcHRFxQWt5XjBVw/photo/AF1QipNxy7mThZBctuuwF3bz88vYBOZnnpPpO7s7BSpk?key=cHNJZmoxV1N5NUxkQm8zR1ZNaUVMSk40clJVN2N3" target="_blank" rel="noreferrer noopener"><img decoding="async" src="https://lh3.googleusercontent.com/42ff8MyUwtrzN95uRXiHx34o8eogFPh_rXMSFjl869Nb7MNs81z-fB96MMFqlerpJ6wUFNyRRqBVJ1u7U-mqxSDWiNYtIdbimJwUwud3UA9zUmK5EXJye6ZGyMOFSDATnfKjWFyfsLvYO_u_XTaep7ak5HqrRAl1RCkS0cQ29Sl1Fv5UjDTr8WnqNvsFTZvIKOIc48X5rPv7FvuY6pFFgAAI8qO2yFBYISUTsymjtagr6TtU2C3-M44qrTzw48cKv2RTEmA0hMHjbG_C4AS1bsHqCnJXf3h-0GyIeHUNoDfM8Hqo9hJWQj6-Bmps2yrJWgIvo2SrpJYkQiwqC3Es10nvuih5fuKp1r3czKht4d8nfn9rVRDIoIvrOfJbgK0wPaBZjM4oHcNuxM6BeVeuB4PVfbdhdjNTgajpPskf7WXuMw-5H0pjbzVB4pErmPQa34WBJ5LsQStrtvps7dmqKkdsVqXIkMlx2fgFjZeEibFtYE-0wDQRoP4D2TWCmBTjWg1ZX-LGYl2CW8uC578RCKNPcbcnAuVrO3fjY1OjobikWVGu5hUVs4KWW6pAQLAd-Celk5FopaykWch2sVrvE2VusZdcHaTmuqHQ9uW1eKAg8MOAE3m0ZmKDMb5H-I_ePLVWgEKQdQdVmasjqiWkUc7X13EpU5CWBIxL30mMq_1pOvi2uAKk-xOO_fN2yYAKElKBrJomTTFcalowd1k=w1464-h824-no" alt=""/></a><figcaption>Clockwise from top left: 1) Viking lager; 2) Viking Rokkr; 3) Viking Red IPA; 4) Viking Stout; 5) Einstök White Ale; 6) Einstök Arctic Pale Ale</figcaption></figure>



<p class="wp-block-paragraph">As a little bonus, I saw a guy get his ass kicked at the bar.  Story was that the guy who got his ass kicked was being creepy towards some women and was asked to leave, but instead attacked the employee who happened to train in MMA&#8230;</p>



<figure class="wp-block-image"><a href="https://photos.google.com/share/AF1QipP6VOT6wbagLRnCE2QVVvZhi_GnWhjJxGDM88xCkgGRF3KxzXgUcHRFxQWt5XjBVw/photo/AF1QipPNvJA5hWqJSB6p7w525vDFSwjvgDyHNhaW4ehZ?key=cHNJZmoxV1N5NUxkQm8zR1ZNaUVMSk40clJVN2N3" target="_blank" rel="noreferrer noopener"><img decoding="async" src="https://lh3.googleusercontent.com/NCzI83WwCmukiCr4VX5-eij7HT47lGn0H8o10jzVM61Uqr8dYFSFJ1CBgavcGOrATyHhBXxv3QxTNxsgJMF32A_qsopUBow3H1IhbmqHtRjODRUP5-1rDUkDAmz376wLLPxTcnPGRIdaFGU3zAVWqCAjUzygmzYRp6X-U-3Sdes9Uy6N8lJ-30CjeZEpDsM3mPYls8b134oiogogPDsjgLbJXKZhKMyg3ZVTyFWRYIewYW0abMM4K1B7YB-jiH4UrZIewZs_hTefbEjYd8aopf-GtJj0IXApjShAUX6XcDPTWq6Xj-2cF0oSEfIWxHKfpV3ZXr0OqkxEp-gXSPa-3nIswvLj9obKLVA2y4cOpQjm8TwvRyqyq43isk9o5WA5EMctyvgZbsMp60veRkt5e4i5ZMs1cAaRBI7U8-2GZ7Gts5ep6GnQ5S9zuzmJPiAeprYQQQHqtKSgPQlYFLeUxj51bn_UVRtAazlEjv8mAE_WridukN-7v1vnWbYc7VOUVxL7lcnDjnqICm16b579gVReOb45XBnCjIJWS-DgaXqJtJrTMpqxS8ffDPP6-3b5VjuemeJ2GzqROUR29HGUVff8S2nPQNsWpqEwhQF7m7rtX4fkvzKXKlIs4vkgbUfS56TZHS3JiWf1IS785Hq3mVmMUhHq3ycB3PGg7Un9WELoaTp4bPiMsgGCX_8gJUb8Ph0fWhzCu1HTwL9d8b0=w1464-h824-no" alt=""/></a></figure>



<p class="wp-block-paragraph">That concludes my trip to Iceland!  Photos <a href="https://photos.app.goo.gl/1aScsjzBQjRi8AT67" target="_blank" rel="noreferrer noopener" aria-label="here (opens in a new tab)">here</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.henrypoon.com/blog/2019/01/17/a-very-brief-tour-of-reykjavik/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">3319</post-id>	</item>
		<item>
		<title>Serial Communication in Java with Example Program</title>
		<link>https://blog.henrypoon.com/blog/2011/01/01/serial-communication-in-java-with-example-program/</link>
					<comments>https://blog.henrypoon.com/blog/2011/01/01/serial-communication-in-java-with-example-program/#comments</comments>
		
		<dc:creator><![CDATA[hp]]></dc:creator>
		<pubDate>Sun, 02 Jan 2011 01:46:37 +0000</pubDate>
				<category><![CDATA[computer stuff]]></category>
		<category><![CDATA[9]]></category>
		<category><![CDATA[All That]]></category>
		<category><![CDATA[APT]]></category>
		<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Blog]]></category>
		<category><![CDATA[Books]]></category>
		<category><![CDATA[Chan]]></category>
		<category><![CDATA[COM]]></category>
		<category><![CDATA[Comment]]></category>
		<category><![CDATA[Computer]]></category>
		<category><![CDATA[Computer languages]]></category>
		<category><![CDATA[Const]]></category>
		<category><![CDATA[Cookbook]]></category>
		<category><![CDATA[D]]></category>
		<category><![CDATA[Data types]]></category>
		<category><![CDATA[Dia]]></category>
		<category><![CDATA[Download]]></category>
		<category><![CDATA[Drive]]></category>
		<category><![CDATA[EAR]]></category>
		<category><![CDATA[Event]]></category>
		<category><![CDATA[Events]]></category>
		<category><![CDATA[Final]]></category>
		<category><![CDATA[Find]]></category>
		<category><![CDATA[Flag]]></category>
		<category><![CDATA[Go]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[Hole]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[IDE]]></category>
		<category><![CDATA[IME]]></category>
		<category><![CDATA[Introduction]]></category>
		<category><![CDATA[IOS]]></category>
		<category><![CDATA[ise]]></category>
		<category><![CDATA[It]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Lag]]></category>
		<category><![CDATA[Lie]]></category>
		<category><![CDATA[Link]]></category>
		<category><![CDATA[Object]]></category>
		<category><![CDATA[Object-oriented programming languages]]></category>
		<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[Over]]></category>
		<category><![CDATA[Page]]></category>
		<category><![CDATA[Parameter]]></category>
		<category><![CDATA[PDF]]></category>
		<category><![CDATA[Plan]]></category>
		<category><![CDATA[Port]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Programming languages]]></category>
		<category><![CDATA[RAR]]></category>
		<category><![CDATA[Reference]]></category>
		<category><![CDATA[Rolling]]></category>
		<category><![CDATA[Run]]></category>
		<category><![CDATA[Serial]]></category>
		<category><![CDATA[Serial communication]]></category>
		<category><![CDATA[Software design patterns]]></category>
		<category><![CDATA[Software engineering]]></category>
		<category><![CDATA[Speed]]></category>
		<category><![CDATA[STR]]></category>
		<category><![CDATA[String]]></category>
		<category><![CDATA[Struct]]></category>
		<category><![CDATA[Swing]]></category>
		<category><![CDATA[Thou]]></category>
		<category><![CDATA[Time]]></category>
		<category><![CDATA[UNC]]></category>
		<category><![CDATA[URL]]></category>
		<category><![CDATA[Variable]]></category>
		<category><![CDATA[Vol]]></category>
		<category><![CDATA[Wiki]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress.com]]></category>
		<category><![CDATA[Writing]]></category>
		<category><![CDATA[XBee]]></category>
		<category><![CDATA[Z]]></category>
		<category><![CDATA[Zip]]></category>
		<guid isPermaLink="false">http://henrypoon.mooo.com/blog/serial-communication-in-java-with-example-program</guid>

					<description><![CDATA[This is more of a follow-up to my previous post about serial programming in Java (here) and how to install the RXTX libraries (here).&#160; This post also assumes that Java is already properly set up with RXTX. Generally, communication with serial ports involves these steps (in no particular order): Searching for serial ports Connecting to [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">This is more of a follow-up to my previous post about serial programming in Java (<a title="Java Serial&nbsp;Programming" href="http://henrypoon.wordpress.com/2010/10/11/java-serial-programming/" target="_blank" rel="noopener">here</a>) and how to install the RXTX libraries (<a title="Installing RXTX for Serial Communication with&nbsp;Java" href="http://henrypoon.wordpress.com/2010/12/25/installing-rxtx-for-serial-communication-with-java/" target="_blank" rel="noopener">here</a>).&nbsp; This post also assumes that Java is already properly set up with RXTX.</p>



<p class="wp-block-paragraph">Generally, communication with serial ports involves these steps (in no particular order):</p>



<ul class="wp-block-list"><li>Searching for serial ports</li><li>Connecting to the serial port</li><li>Starting the input output streams</li><li>Adding an event listener to listen for incoming data</li><li>Disconnecting from the serial port</li><li>Sending Data</li><li>Receiving Data</li></ul>



<p class="wp-block-paragraph">I wrote an example program that includes all of those steps in it and are each in their own separate method within the class, but first I will go through my hardware set up.</p>



<h1 class="wp-block-heading">Hardware Setup</h1>



<p class="wp-block-paragraph">My current hardware setup is as follows:</p>



<ul class="wp-block-list"><li>PC connected to an XBee</li><li>Arduino connected to an XBee</li></ul>



<p class="wp-block-paragraph">User input is given from the PC through the a Java GUI that contains code for serial communication, which is the code presented here.</p>



<p class="wp-block-paragraph">The Arduino is responsible for reading this data.&nbsp; This set up is pretty much using my computer as a remote control for whatever device is on the Arduino end.&nbsp; It could be a motor control, on-off switch, etc.</p>



<h1 class="wp-block-heading">Existing Code</h1>



<p class="wp-block-paragraph">The purpose of this post is to discuss serial programming in Java, and not GUI’s.&nbsp; However, I did create a GUI for testing purposes.&nbsp; See the Code Downloads section for the actual files.</p>


<div class="wp-block-image">
<figure class="aligncenter"><img data-recalc-dims="1" decoding="async" width="300" height="136" src="https://i0.wp.com/blog.henrypoon.com/wp-content/uploads/2011/03/javagui.png?resize=300%2C136&#038;ssl=1" alt="" class="wp-image-933" srcset="https://i0.wp.com/blog.henrypoon.com/wp-content/uploads/2011/03/javagui.png?resize=300%2C136&amp;ssl=1 300w, https://i0.wp.com/blog.henrypoon.com/wp-content/uploads/2011/03/javagui.png?w=640&amp;ssl=1 640w" sizes="(max-width: 300px) 100vw, 300px" /></figure>
</div>


<p class="wp-block-paragraph">Above is the picture of the GUI complete with the buttons that I use to interact with the program.&nbsp; I also added key bindings which I can use to control the throttle.</p>



<p class="wp-block-paragraph">When the program is first started, none of the GUI elements will work except for the combo box and the connect button.&nbsp; Once a successful connection is made the controls are enabled.&nbsp; This is done through the use of the <em>setConnected(true)</em> and the <em>toggleControls()</em> methods shown in the example code that follows.</p>



<h1 class="wp-block-heading">Imports</h1>



<p class="wp-block-paragraph">The imports i used for this program were as follows:</p>



<pre class="wp-block-code"><code lang="java" class="language-java">import gnu.io.*;
import java.awt.Color;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.TooManyListenersException;</code></pre>



<p class="wp-block-paragraph">Depending on the Java IDE it might already know to tell you to use these imports except for the first one.&nbsp; That first import is specific to RXTX, and all its library methods/classes are in there.</p>



<h1 class="wp-block-heading">Class Declaration</h1>



<p class="wp-block-paragraph">The code here reads:</p>



<pre class="wp-block-code"><code lang="java" class="language-java">public class Communicator implements SerialPortEventListener</code></pre>



<p class="wp-block-paragraph">I named my class <em>Communicator</em>, but the name is really up to the programmer.&nbsp; The name pretty much reflects its intended use.</p>



<p class="wp-block-paragraph">The class should also <em>implement</em> the <em>SerialPortEventListener</em> class.&nbsp; This is a class in RXTX and is required in order to receive incoming data.</p>



<p class="wp-block-paragraph">On some IDE’s this may generate a public void method called <em>serialEvent()</em>.&nbsp; This method will be defined later.</p>



<h1 class="wp-block-heading">Class Variables and Constants</h1>



<p class="wp-block-paragraph">Below are the variables and constants that I defined in my class.&nbsp; What the variables are for is in the comments but a more detailed explanation will follow.</p>



<pre class="wp-block-code"><code lang="java" class="language-java">    //passed from main GUI
    GUI window = null;

    //for containing the ports that will be found
    private Enumeration ports = null;
    //map the port names to CommPortIdentifiers
    private HashMap portMap = new HashMap();

    //this is the object that contains the opened port
    private CommPortIdentifier selectedPortIdentifier = null;</code></pre>



<p class="wp-block-paragraph">I could have easily put the variable definitions in the constructor but it wouldn’t change anything.</p>



<p class="wp-block-paragraph">The <em>GUI</em> object is another class that I wrote separate from this one that contains all the GUI elements.&nbsp; The GUI class extends <em>javax.swing.JFrame</em>.</p>



<p class="wp-block-paragraph">The <em>HashMap</em> is for mapping each of the ports’ names to the actual object. What that means is that I can associate (<em>put()</em> method) the name of a serial port, say a string that says COM1, to an object in the code.&nbsp; Later, I can access the name COM1 from the <em>HashMap</em> by using the <em>get()</em> method and it will return the object that it was associated with previously.</p>



<p class="wp-block-paragraph">The <em>CommPortIdentifiers</em> object is needed to gather the list of ports that are available for connection. by using its <em>getPortIdentifiers()</em> method.</p>



<p class="wp-block-paragraph">The <em>SerialPort</em> object is for storing the data for the port once a successful connection is made.</p>



<p class="wp-block-paragraph">The <em>InputStream</em> and <em>OutputStream</em> is the object that is required for sending and receiving data.</p>



<p class="wp-block-paragraph">The Boolean variable <em>bConnected</em> is just a flag that I use for enabling and disabling elements on the GUI.</p>



<p class="wp-block-paragraph">The constant <em>TIMEOUT</em> is a number required when opening the port so that it knows how long to try for before stopping.</p>



<p class="wp-block-paragraph">The constants for the ASCII values are some values that I use to send through the output stream that act as delimiters for data.</p>



<p class="wp-block-paragraph">The string <em>logText</em> is basically what the comment says.&nbsp; When stuff happens in the program, the program stores a string in this variable and it will be appended to a text area in the GUI.</p>



<h1 class="wp-block-heading">Searching for Available Serial Ports</h1>



<p class="wp-block-paragraph">The method below is for searching for available serial ports on the computer.&nbsp; Code adapted from Discovering Available Comm Ports from the Reference Material.</p>



<pre class="wp-block-code"><code lang="java" class="language-java">    //search for all the serial ports
    //pre style="font-size: 11px;": none
    //post: adds all the found ports to a combo box on the GUI
    void searchForPorts()
    {
        ports = CommPortIdentifier.getPortIdentifiers();

        &lt;span style="color: blue;"&gt;while (ports.hasMoreElements())
        {
            CommPortIdentifier curPort = (CommPortIdentifier)ports.nextElement();

            //get only serial ports
            &lt;span style="color: blue;"&gt;if (curPort.getPortType() == CommPortIdentifier.PORT_SERIAL)
            {
                window.cboxPorts.addItem(curPort.getName());
                portMap.put(curPort.getName(), curPort);
            }
        }
    }</code></pre>



<p class="wp-block-paragraph">The method <em>getPortIdentifiers()</em> returns an Enumeration of all the comm ports on the computer.&nbsp; The code can iterate through each element inside the Enumeration and determine whether or not it is a serial port.&nbsp; The method <em>getPortType()</em> can identify what kind of port it is.&nbsp; If it is a serial port, then the code will add its name to a combo box in the GUI (so that users can pick what port to connect to).&nbsp; The serial port that is found should also be mapped to the HashMap so we can identify the object later.&nbsp; This is helpful because the names listed in the combo box are the actual names of the object (COM1, COM2, etc), and so we can use these names to identify the actual object they are tied to.</p>



<h1 class="wp-block-heading">Connecting to the Serial Port</h1>



<p class="wp-block-paragraph">The method below is for connecting to the serial port once they have been found (see previous section).&nbsp; See How to Open A Serial Port in the Reference Material for more information.</p>



<pre class="wp-block-code"><code lang="java" class="language-java">
    //connect to the selected port in the combo box
    //ports are already found by using the searchForPorts
    //method
    //post: the connected comm port is stored in commPort, otherwise,
    //an exception is generated
    public void connect()
    {
        String selectedPort = (String)window.cboxPorts.getSelectedItem();
        selectedPortIdentifier = (CommPortIdentifier)portMap.get(selectedPort);

        CommPort commPort = null;

        try
        {
            //the method below returns an object of type CommPort
            commPort = selectedPortIdentifier.open("TigerControlPanel", TIMEOUT);
            //the CommPort object can be casted to a SerialPort object
            serialPort = (SerialPort)commPort;

            //for controlling GUI elements
            setConnected(true);

            //logging
            logText = selectedPort + " opened successfully.";
            window.txtLog.setForeground(Color.black);
            window.txtLog.append(logText + "n");

            //CODE ON SETTING BAUD RATE ETC OMITTED
            //XBEE PAIR ASSUMED TO HAVE SAME SETTINGS ALREADY

            //enables the controls on the GUI if a successful connection is made
            window.keybindingController.toggleControls();
        }
        catch (PortInUseException e)
        {
            logText = selectedPort + " is in use. (" + e.toString() + ")";

            window.txtLog.setForeground(Color.RED);
            window.txtLog.append(logText + "n");
        }
        catch (Exception e)
        {
            logText = "Failed to open " + selectedPort + "(" + e.toString() + ")";
            window.txtLog.append(logText + "n");
            window.txtLog.setForeground(Color.RED);
        }
    }</code></pre>



<p class="wp-block-paragraph">Using the <em>HashMap</em> we can retrieve the <em>CommPortIdentifier</em> object from the string that was mapped earlier.&nbsp; This is achieved through the <em>HashMap’s</em> <em>get()</em> method.&nbsp; The object must also be casted as a <em>CommPortIdentifier</em> because the <em>get()</em> method has a return type of <em>Object</em>.</p>



<p class="wp-block-paragraph">The <em>setConnected </em>method just changes a boolean flag so that the program can store whether or not it is connected to a serial port or not.</p>



<p class="wp-block-paragraph">The <em>CommPort</em> must also be initialized because the port object will be stored here once a successful connection is made.</p>



<p class="wp-block-paragraph">The main method of interest here is the <em>open()</em> method.&nbsp; This instructs the program to open the port, and this method will return the object for the opened port, which I store in in the previously initialized <em>CommPort </em>object.&nbsp; I then cast this object as a <em>SerialPort</em> and store it as well.&nbsp; This is helpful for accessing the methods and variables specific to the <em>SerialPort</em> class.</p>



<p class="wp-block-paragraph">It should also be noted that the <em>open()</em> method requires the use of a try-catch block.&nbsp; So applying that, I catch two different exceptions.&nbsp; The <em>PortInUseException</em> is what the name says.&nbsp; If the port is in use, then this exception is thrown.&nbsp; The next catch block is just for the generic exceptions that occur.&nbsp; I never came across that during testing, nor do I know how to replicate that.</p>



<p class="wp-block-paragraph">I neglected to include any code for setting the baud rate and other settings on the XBee’s (see Hardware Configuration), because I already set those parameters previously using X-CTU (more on setting up XBee’s here).</p>



<h1 class="wp-block-heading">Initializing the Input and Output Streams</h1>



<p class="wp-block-paragraph">This method is pretty short and is pretty straightforward to read.</p>



<pre class="wp-block-code"><code lang="java" class="language-java">    //open the input and output streams
    //pre style="font-size: 11px;": an open port
    //post: initialized input and output streams for use to communicate data
    public boolean initIOStream()
    {
        //return value for whether opening the streams is successful or not
        boolean successful = false;

        try {
            //
            input = serialPort.getInputStream();
            output = serialPort.getOutputStream();
            writeData(0, 0);

            successful = true;
            return successful;
        }
        catch (IOException e) {
            logText = "I/O Streams failed to open. (" + e.toString() + ")";
            window.txtLog.setForeground(Color.red);
            window.txtLog.append(logText + "n");
            return successful;
        }
    }</code></pre>



<p class="wp-block-paragraph">The streams are initialized by returning the input and output streams of the open serial port.&nbsp; In order for the serial port object to not be null, it must store the object for the open serial port.</p>



<p class="wp-block-paragraph">The <em>getInputStream()</em> and <em>getOutputStream()</em> methods both require a try-catch block.&nbsp; The important exception to catch here is the <em>IOException</em> to signify whether the streams failed to open or not.&nbsp; For more information see How to Open A Serial Port in the Reference Material.</p>



<p class="wp-block-paragraph">I also call a method called <em>writeData(0, 0)</em>.&nbsp; This is the method that encapsulates the code required to write serial data.&nbsp; More on that later.&nbsp; Right now it is just used to set variables on the microcontroller side to zero.</p>



<h1 class="wp-block-heading">Setting Up Event Listeners to Read Data</h1>



<p class="wp-block-paragraph">Once the port is open, the serial port must know whenever there is data to be read.&nbsp; This approach is event driven rather than by polling.&nbsp; When the event is hit, a special block of code will run.&nbsp; This is advantageous to polling because polling requires constantly asking if data is available.&nbsp; The code for the event driven approach is below.&nbsp; See Event Based Two Way Communication for more information.</p>



<pre class="wp-block-code"><code lang="java" class="language-java">    //starts the event listener that knows whenever data is available to be read
    //pre style="font-size: 11px;": an open serial port
    //post: an event listener for the serial port that knows when data is received
    public void initListener()
    {
        try
        {
            serialPort.addEventListener(this);
            serialPort.notifyOnDataAvailable(true);
        }
        catch (TooManyListenersException e)
        {
            logText = "Too many listeners. (" + e.toString() + ")";
            window.txtLog.setForeground(Color.red);
            window.txtLog.append(logText + "n");
        }
    }</code></pre>



<p class="wp-block-paragraph">The code here is pretty much the whole reason why this class implements <em>SerialPortEventListener</em>.&nbsp; The parameter for adding the event listener is just the object itself.&nbsp; The base class has a method called <em>serialEvent(event)</em> that should be overridden before the event code will work.&nbsp; Overriding that method defines what happens when the event is hit.</p>



<p class="wp-block-paragraph">The method <em>addEventListener(this)</em> is the event that is always checking for <em>SerialEvents</em>.&nbsp; It isn’t really important to know what the events actually are, just that the one we’re interested in is the one that tells us whenever data is received.&nbsp; Adding the event listener is complemented by the method <em>notifyOnDataAvailable(true)</em>, which definitely helps us achieve what I mentioned previously.</p>



<p class="wp-block-paragraph">This code requires a try-catch box.&nbsp; The exception here is that there may be too many event listeners.&nbsp; I only use one in the code, so this exception should never be hit.</p>



<h1 class="wp-block-heading">Disconnecting from the Serial Port</h1>



<p class="wp-block-paragraph">Once all the communication is completed, the serial port must be disconnected.&nbsp; In some instances, some ports stay stuck open, which isn’t exactly a good thing.</p>



<pre class="wp-block-code"><code lang="java" class="language-java">    //disconnect the serial port
    //pre style="font-size: 11px;": an open serial port
    //post: closed serial port
    public void disconnect()
    {
        //close the serial port
        try
        {
            writeData(0, 0);

            serialPort.removeEventListener();
            serialPort.close();
            input.close();
            output.close();
            setConnected(false);
            window.keybindingController.toggleControls();

            logText = "Disconnected.";
            window.txtLog.setForeground(Color.red);
            window.txtLog.append(logText + "n");
        }
        catch (Exception e)
        {
            logText = "Failed to close " + serialPort.getName()
                              + "(" + e.toString() + ")";
            window.txtLog.setForeground(Color.red);
            window.txtLog.append(logText + "n");
        }
    }</code></pre>



<p class="wp-block-paragraph">The code here requires a try-catch block so there it is.&nbsp; The exception to catch here is pretty generic.</p>



<p class="wp-block-paragraph">Before closing the port, I reset the data on the microcontroller.&nbsp; That step is optional depending on the application.&nbsp; For example, if the value sent to the microcontroller is controlling the speed of a motor, I’d want the motor to turn off if I turn off the remote control.</p>



<p class="wp-block-paragraph">The event listener should be removed as it is no longer needed.</p>



<p class="wp-block-paragraph">The method to close the port is the <em>close()</em> method.</p>



<p class="wp-block-paragraph">The input and output streams should also be closed via the same method as above.</p>



<p class="wp-block-paragraph">See How to Close A Serial Port in the Reference section for more information.</p>



<h1 class="wp-block-heading">Reading Data – The <em>serialEvent</em> Method</h1>



<p class="wp-block-paragraph">This is a follow-up to the section on preparing to Read Data.&nbsp; It has information on how to process the data that the program reads.</p>



<pre class="wp-block-code"><code lang="java" class="language-java">    //what happens when data is received
    //pre style="font-size: 11px;": serial event is triggered
    //post: processing on the data it reads
    public void serialEvent(SerialPortEvent evt) {
        if (evt.getEventType() == SerialPortEvent.DATA_AVAILABLE)
        {
            try
            {
                byte singleData = (byte)input.read();

                if (singleData != NEW_LINE_ASCII)
                {
                    logText = new String(new byte[] {singleData});
                    window.txtLog.append(logText);
                }
                else
                {
                    window.txtLog.append("n");
                }
            }
            catch (Exception e)
            {
                logText = "Failed to read data. (" + e.toString() + ")";
                window.txtLog.setForeground(Color.red);
                window.txtLog.append(logText + "n");
            }
        }
    }</code></pre>



<p class="wp-block-paragraph">Since we only want to read data if it exists, we test the condition in the if statement above.&nbsp; This could be redundant because we wouldn’t be in this method if the event never got triggered.</p>



<p class="wp-block-paragraph">Reading the data requires a try-catch block.&nbsp; The <em>read()</em> method returns an integer, but the value in it is actually a byte value so this is casted to a byte, in which I store in a variable called <em>singleData</em>.&nbsp; When I was testing this code before, I noticed that the data being read would always have random new line characters in it, and I never knew why this happened.&nbsp; I never wrote any new line characters.&nbsp; Since I don’t want these, I add an if condition saying that if it encounters that, don’t display that data on the screen.</p>



<p class="wp-block-paragraph">Java also has a nice way of converting bytes to a string.  A byte array can be used as a parameter when initializing a string, which is what I’ve done when I assign a value to <em>logText</em>.</p>



<p class="wp-block-paragraph">The exception here is just the usual generic one.</p>



<h1 class="wp-block-heading">Writing Data</h1>



<p class="wp-block-paragraph">Here is the method for writing data.&nbsp; In my application, I am writing two integers sequentially to my microcontroller.&nbsp; Data that is sent to the MCU can be used for such things such as controlling motor speeds, which is what I am trying to do here.&nbsp; I hope to use the data sent do control the PWM duty cycle of the motor for speed control.</p>



<pre class="wp-block-code"><code lang="java" class="language-java">    //method that can be called to send data
    //pre style="font-size: 11px;": open serial port
    //post: data sent to the other device
    public void writeData(int leftThrottle, int rightThrottle)
    {
        try
        {
            output.write(leftThrottle);
            output.flush();
            //this is a delimiter for the data
            output.write(DASH_ASCII);
            output.flush();

            output.write(rightThrottle);
            output.flush();
            //will be read as a byte so it is a space key
            output.write(SPACE_ASCII);
            output.flush();
        }
        catch (Exception e)
        {
            logText = "Failed to write data. (" + e.toString() + ")";
            window.txtLog.setForeground(Color.red);
            window.txtLog.append(logText + "n");
        }
    }</code></pre>



<p class="wp-block-paragraph">The <em>write() </em>method here requires a try-catch block just like many of the other methods used for serial communication.&nbsp; Using the output stream, I call that method to write an integer value.&nbsp; I also write a dash and a space to separate the actual data being read.&nbsp; See the ASCII Table for the values of what these characters should be.&nbsp; This helps me differentiate the sets of data that is sent back and forth.&nbsp; The dash separates the two integers being sent and the space separates the entire set.&nbsp; On the Arduino end, four called to <em>read()</em> can separate the data without mixing things up.&nbsp; Example of that later.</p>



<h1 class="wp-block-heading">Putting All the Java Code Together</h1>



<p class="wp-block-paragraph">Once all these methods are setup, they need to be called somewhere in the program so we can put them to use.&nbsp; When the program starts, the code for searching for serial ports will run so that it can populate the combo box on the GUI.&nbsp; The GUI buttons also need to be disabled to reflect the fact they should be disabled when there is no connection to a port.&nbsp; When the connect button is pressed, the input and output streams are started and the event listener is added.&nbsp; The code for that is shown below.</p>



<pre class="wp-block-code"><code lang="java" class="language-java">        private void btnConnectActionPerformed(java.awt.event.ActionEvent evt) {
            communicator.connect();
            if (communicator.getConnected() == true)
            {
                if (communicator.initIOStream() == true)
                {
                    communicator.initListener();
                }
            }
        }</code></pre>



<p class="wp-block-paragraph">The if statement is needed such that the code will not run if a successful connection was not made.&nbsp; This is the precondition for the <em>initIOStream() </em>and the <em>initLIstener() </em>methods.</p>



<p class="wp-block-paragraph">When the user decides to disconnect from the serial port, the user only needs to call the <em>disconnect()</em> method when the disconnect button is pressed.</p>



<p class="wp-block-paragraph">The up/down arrows on my GUI are set to write data to the serial port when they are pressed.&nbsp; When data is written to the Arduino, the MCU will send the data back to the Java program, which will signal the event listener to display that data back to the screen.</p>



<h1 class="wp-block-heading">Arduino Code</h1>



<p class="wp-block-paragraph">The Arduino code is pretty straight forward.&nbsp; There are just a few calls to the <em>read()</em> method.</p>



<p class="wp-block-paragraph">Update 6 May 2012: the syntax for the Arduino code has updated since the writing of this article. &nbsp;Apparently, the lines</p>



<pre class="wp-block-code"><code lang="c" class="language-c">Serial.print(separator, BYTE);
Serial.print(space, BYTE);</code></pre>



<p class="wp-block-paragraph">are no longer valid and have since been replaced by the following:</p>



<pre class="wp-block-code"><code lang="c" class="language-c">Serial.write(byte(separator));
Serial.write(byte(space));</code></pre>



<p class="wp-block-paragraph">The code below hasn&#8217;t been edited with this change, but basically the code required for writing a byte value through serial communication has changed.</p>



<pre class="wp-block-code"><code lang="c" class="language-c">
// this is where we will put our data
int left = 0;
int right = 0;
byte space = 0;
byte separator = 0;

void setup(){
  // Start up our serial port, we configured our XBEE devices for 38400 bps. 
  Serial.begin(9200);
}

void loop(){
  // handle serial data, if any
  if (Serial.available() &amp;gt;= 4){
    left = Serial.read();
    separator = Serial.read();
    right = Serial.read();
    space = Serial.read();
    Serial.flush();

    Serial.print(left);
    Serial.print(separator, BYTE);
    Serial.print(right);
    Serial.print(space, BYTE);
    Serial.print("n");
  }
}</code></pre>



<p class="wp-block-paragraph">I first declare four variables to reflect the fact that I’m writing four different variables to the serial port.</p>



<p class="wp-block-paragraph">In the loop method, I added a condition which will check whether there are four pieces of data available before reading them.&nbsp; This again reflects the fact I’m writing four values.</p>



<p class="wp-block-paragraph">The four variables initially declared store the values in the order that they are written, and then are just printed to the screen.</p>



<p class="wp-block-paragraph">The <em>print()</em> method is able to convert the byte value to an actual character by adding a second parameter called <em>BYTE</em>.&nbsp; The left and right variables don’t need it because the values written were integers to begin with, however, the dash and space characters were written as ASCII values.</p>



<p class="wp-block-paragraph">For more information about Arduino and Java, and Arduino’s Serial library, please refer to those in the Reference Section.</p>



<h1 class="wp-block-heading">Code Downloads</h1>



<p class="wp-block-paragraph">Here are the code downloads for the GUI, key bindings and the serial communication.&nbsp; WordPress doesn’t allow uploads of zip or java files so I uploaded it all to Megaupload.</p>



<p class="wp-block-paragraph">Link to download:&nbsp;<a href="http://www.mediafire.com/?z2l26ncypmzn20z" target="_blank" rel="noopener">http://www.mediafire.com/?z2l26ncypmzn20z</a></p>



<h1 class="wp-block-heading">Other Examples</h1>



<p class="wp-block-paragraph">There are also other sites I looked at which had example code for serial port communication in Java.&nbsp; The sites are Programming Serial and Parallel Ports and Serial Port Access Using RXTX in Java, which are both in the Reference section.</p>



<h1 class="wp-block-heading">Reference Material</h1>



<p class="wp-block-paragraph">Below are a bunch of links to reference sites that I used to find some of the information written here.&nbsp; I mostly referred to bits and pieces of each article to understand the serial code and to come up with the example I present here.&nbsp; The list is in the order that I referenced them.</p>



<h2 class="wp-block-heading">Discovering Available Comm Ports</h2>



<p class="wp-block-paragraph"><a href="http://rxtx.qbang.org/wiki/index.php/Discovering_available_comm_ports" target="_blank" rel="noopener">http://rxtx.qbang.org/wiki/index.php/Discovering_available_comm_ports</a></p>



<p class="wp-block-paragraph">The code on this page is pretty specific to the title of this heading, and the code is pretty easy to follow.</p>



<h2 class="wp-block-heading">How to Open A Serial Port</h2>



<p class="wp-block-paragraph"><a target="_blank" rel="noopener">http://embeddedfreak.wordpress.com/2008/08/08/how-to-open-serial-port-using-rxtx/</a></p>



<p class="wp-block-paragraph">This page provides a very concise and detailed explanation on what each line of code does in order to get a serial port open.&nbsp; Definitely work a look if you’re trying to understand the code.</p>



<h2 class="wp-block-heading">Event Based Two Way Communication</h2>



<p class="wp-block-paragraph"><a href="http://rxtx.qbang.org/wiki/index.php/Event_Based_Two_Way_Communication" target="_blank" rel="noopener">http://rxtx.qbang.org/wiki/index.php/Event_Based_Two_Way_Communication</a></p>



<p class="wp-block-paragraph">This page has example code on how to connect to a serial port and how to interact with it.&nbsp; The code here uses events, rather than polling, to send data back and forth, which means that whenever data is received, the event code is triggered.</p>



<h2 class="wp-block-heading">How to Close A Serial Port</h2>



<p class="wp-block-paragraph"><a target="_blank" rel="noopener">http://embeddedfreak.wordpress.com/2008/08/08/how-to-close-serial-port-in-rxtx/</a></p>



<p class="wp-block-paragraph">This article is written by the same author who wrote the article on how to open serial ports.  Good example code here.</p>



<h2 class="wp-block-heading">ASCII Table</h2>



<p class="wp-block-paragraph"><a href="http://www.asciitable.com/" target="_blank" rel="noopener">http://www.asciitable.com/</a></p>



<p class="wp-block-paragraph">Having the ASCII Table is quite handy for serial data because data being sent and written are bytes, so being able to know what byte values correspond to what character really helps.</p>



<h2 class="wp-block-heading">Arduino and Java</h2>



<p class="wp-block-paragraph"><a href="http://www.arduino.cc/playground/Interfacing/Java" target="_blank" rel="noopener">http://www.arduino.cc/playground/Interfacing/Java</a></p>



<p class="wp-block-paragraph">This article discusses how to use the serial port communication with Java and Arduino, which is exactly what I am after.&nbsp; It has example code on pretty much the entire process of serial port communication, but it may be too much to read since there is little explanation about the code.</p>



<h2 class="wp-block-heading">Arduino Serial Class</h2>



<p class="wp-block-paragraph"><a href="http://arduino.cc/en/Reference/Serial" target="_blank" rel="noopener">http://arduino.cc/en/Reference/Serial</a></p>



<p class="wp-block-paragraph">A good reference for Arduino’s Serial class methods.&nbsp; Also has example code to look at.</p>



<h2 class="wp-block-heading">Programming Serial and Parallel Ports</h2>



<figure class="wp-block-embed is-type-rich is-provider-embed-handler wp-block-embed-embed-handler"><div class="wp-block-embed__wrapper">
https://docs.google.com/viewer?url=http%3A%2F%2Fjava.sun.com%2Fdeveloper%2FBooks%2Fjavaprogramming%2Fcookbook%2F11.pdf
</div></figure>



<p class="wp-block-paragraph">This article provides a brief introduction to programming serial ports and has information on the steps required to talk to the serial port.&nbsp; However, the code examples in there may be hard to follow for someone new to serial programming.</p>



<h2 class="wp-block-heading">Serial Port Access Using RXTX in Java</h2>



<p class="wp-block-paragraph"><a href="http://gomultidomain.blogspot.com/2008/06/serial-port-access-using-rxtx-in-java.html" target="_blank" rel="noopener">http://gomultidomain.blogspot.com/2008/06/serial-port-access-using-rxtx-in-java.html</a></p>



<p class="wp-block-paragraph">This page also has complete code for serial communication in Java, but what I was looking for here was how to use the write method to send serial data from Java.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.henrypoon.com/blog/2011/01/01/serial-communication-in-java-with-example-program/feed/</wfw:commentRss>
			<slash:comments>144</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">566</post-id>	</item>
	</channel>
</rss>
