<?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>derxen Blog &#187; Relaiskarte</title>
	<atom:link href="http://www.derxen.de/blog/tag/relaiskarte/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.derxen.de/blog</link>
	<description>systematisch, funktionell, kreativ</description>
	<lastBuildDate>Thu, 10 Jul 2014 13:10:35 +0000</lastBuildDate>
	<language>de-DE</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.1.41</generator>
	<item>
		<title>Widerstandsmessung Conradrelaiskarte</title>
		<link>http://www.derxen.de/blog/2011/technik/widerstandsmessung-conradrelaiskarte/</link>
		<comments>http://www.derxen.de/blog/2011/technik/widerstandsmessung-conradrelaiskarte/#comments</comments>
		<pubDate>Mon, 19 Dec 2011 15:40:19 +0000</pubDate>
		<dc:creator><![CDATA[Heinrich]]></dc:creator>
				<category><![CDATA[Technik]]></category>
		<category><![CDATA[Relaiskarte]]></category>
		<category><![CDATA[Widerstand]]></category>

		<guid isPermaLink="false">http://www.derxen.de/blog/?p=1868</guid>
		<description><![CDATA[Siehe auch: Conrad-Relaiskarte mit JAVA steuern . Da das Handbuch mir nichts über den Widerstand der Relaiskarte verraten hat, musste ich eine eigene Messung vornehmen, um eben jenes herauszufinden. In der Graphik seht ihr die Messreihe als Graphen. . Der Widerstand ist abhängig von der Anzahl n der eingeschalteten Relais. Bei n=0 Relais ist der Widerstand [&#8230;]]]></description>
				<content:encoded><![CDATA[<div style="width: 142px" class="wp-caption alignleft"><a href="http://www.google.de/products/catalog?q=conrad+relaiskarte&amp;hl=de&amp;client=firefox-a&amp;hs=4ja&amp;rls=org.mozilla:de:official&amp;prmd=ivns&amp;biw=1366&amp;bih=613&amp;um=1&amp;ie=UTF-8&amp;tbm=shop&amp;cid=4659892043775063980&amp;sa=X&amp;ei=uYhGTu-vKpGG-wbN2YDuBg&amp;ved=0CEIQ8wIwAA"><img class=" " title="Conrad Relaiskarte" src="http://lh3.googleusercontent.com/public/IixvUL-7aGVgYxvgetyIlEig8dWeQ25_Vb-rD_uBnzpWo6o8zlGqCgDLtCobsBsj96MTMPeia6zjRgtZhd86n7WgElmBMCZJm0KctvVki74GEGgmH0c_6IYN3Sm-yDmPrv4ao2BQpKgU-B2VQX1EYjojVgaJsJQphiq-Dnh-03qgV8DYwGdynofshJtOY7OofOx6Hd8Y4Q8plU544UDV37I-QsppEafOtpV-257sph37" alt="Conrad Relaiskarte" width="132" height="132" /></a><p class="wp-caption-text">Wie groß ist der Widerstand der Conrad-Relaiskarte? (Bildquelle: Google)</p></div>
<div>Siehe auch: <a title="Conrad-Relaiskarte mit JAVA steuern" href="http://www.derxen.de/blog/2011/top-thema/relaiskarte-mit-java-steuern/">Conrad-Relaiskarte mit JAVA steuern</a></div>
<div>.</div>
<div>Da das Handbuch mir nichts über den Widerstand der Relaiskarte verraten hat, musste ich eine eigene Messung vornehmen, um eben jenes herauszufinden. In der Graphik seht ihr die Messreihe als Graphen.</div>
<div>.</div>
<div>Der Widerstand ist abhängig von der Anzahl n der eingeschalteten Relais. Bei n=0 Relais ist der Widerstand am höchsten. Werden Relais eingeschaltet, sinkt der Gesamt-Widerstand der Relaiskarte.</div>
<div>
<p><a href="http://www.derxen.de/blog/wp-content/uploads/2011/12/WiderstandskennlinieCR1.png"><img class="alignnone size-medium wp-image-1877" style="padding-bottom: 40px;" title="WiderstandskennlinieCR" src="http://www.derxen.de/blog/wp-content/uploads/2011/12/WiderstandskennlinieCR1-300x180.png" alt="" width="300" height="180" /></a></p>
<p>&nbsp;</p>
</div>
<p><strong><br />
</strong></p>
<div style="clear: both;"></div>]]></content:encoded>
			<wfw:commentRss>http://www.derxen.de/blog/2011/technik/widerstandsmessung-conradrelaiskarte/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Conrad-Relaiskarte mit JAVA steuern</title>
		<link>http://www.derxen.de/blog/2011/technik/relaiskarte-mit-java-steuern/</link>
		<comments>http://www.derxen.de/blog/2011/technik/relaiskarte-mit-java-steuern/#comments</comments>
		<pubDate>Sat, 13 Aug 2011 14:43:48 +0000</pubDate>
		<dc:creator><![CDATA[Heinrich]]></dc:creator>
				<category><![CDATA[Technik]]></category>
		<category><![CDATA[JAVA]]></category>
		<category><![CDATA[Relaiskarte]]></category>
		<category><![CDATA[Schnittstelle]]></category>
		<category><![CDATA[USB]]></category>

		<guid isPermaLink="false">http://www.derxen.de/blog/?p=1747</guid>
		<description><![CDATA[&#160; Siehe auch: Conrad Relaiskarte Widerstand Conrad-Relaiskarte mit JAVA ansteuern unter Windows 7 / USB-Schnittstelle Kürzlich erwarb ich eine Relaiskarte von Conrad. Doch schnell stieß ich auf ein Problem: Ich möchte die Karte über JAVA ansteuern, jedoch gibt es keine Anleitung im Internet, die einem bei diesem Vorhaben konkret weiterhelfen. Nach einiger Recherche hier mein [&#8230;]]]></description>
				<content:encoded><![CDATA[<div style="width: 230px" class="wp-caption alignleft"><a href="http://www.google.de/products/catalog?q=conrad+relaiskarte&amp;hl=de&amp;client=firefox-a&amp;hs=4ja&amp;rls=org.mozilla:de:official&amp;prmd=ivns&amp;biw=1366&amp;bih=613&amp;um=1&amp;ie=UTF-8&amp;tbm=shop&amp;cid=4659892043775063980&amp;sa=X&amp;ei=uYhGTu-vKpGG-wbN2YDuBg&amp;ved=0CEIQ8wIwAA"><img title="Conrad Relaiskarte" src="http://lh3.googleusercontent.com/public/IixvUL-7aGVgYxvgetyIlEig8dWeQ25_Vb-rD_uBnzpWo6o8zlGqCgDLtCobsBsj96MTMPeia6zjRgtZhd86n7WgElmBMCZJm0KctvVki74GEGgmH0c_6IYN3Sm-yDmPrv4ao2BQpKgU-B2VQX1EYjojVgaJsJQphiq-Dnh-03qgV8DYwGdynofshJtOY7OofOx6Hd8Y4Q8plU544UDV37I-QsppEafOtpV-257sph37" alt="Conrad Relaiskarte" width="220" height="220" /></a><p class="wp-caption-text">Conrad Relaiskarte (Quelle: Google)</p></div>
<p>&nbsp;</p>
<p>Siehe auch: <a title="Widerstandsmessung Conradrelaiskarte" href="http://www.derxen.de/blog/2011/elektrotechnik/widerstandsmessung-conradrelaiskarte/">Conrad Relaiskarte Widerstand</a></p>
<p><strong>Conrad-Relaiskarte mit JAVA ansteuern</strong> unter Windows 7 / USB-Schnittstelle</p>
<p>Kürzlich erwarb ich eine Relaiskarte von Conrad. Doch schnell stieß ich auf ein Problem: Ich möchte die Karte über JAVA ansteuern, jedoch gibt es keine Anleitung im Internet, die einem bei diesem Vorhaben konkret weiterhelfen. Nach einiger Recherche hier mein Ergebnis:</p>
<p>1. Um die Karte über USB anzusteuern, benötigt man zusätzlich zur Karte noch einen RS232-Converter (ca. 15 EUR).</p>
<p>2. Um eine Verbindung per JAVA unter Windows 7 herzustellen, braucht man die RXTXcomm-Bibliothek</p>
<p>3. Es muss eine passende Klasse programmiert werden, mit der man die Relaiskarte steuern kann.</p>
<p><strong>1.: Die Hardwarevoraussetzungen</strong></p>
<p>Im folgenden arbeite ich mit der <a href="http://www.conrad.de/ce/de/product/197720/?hk=WW4&amp;insert=V0&amp;WT.mc_id=Froogle2&amp;utm_source=google&amp;utm_medium=deeplink&amp;utm_content=dl_article&amp;utm_campaign=g_shopping">Conrad-Relaiskarte</a>. Möchte man diese per USB ansteuern (so wie hier beschrieben), so braucht man für die erste Karte einen <a href="http://www.conrad.de/ce/de/product/197257/USB-TO-RS232-CONVERTER-IC?ref=oz">RS232-Converter</a><strong>.<br />
</strong></p>
<p><strong>2.: Die RXTXcomm.jar für Windows 7</strong></p>
<p>Mit der Standard-JAVA-Bibliothek ist es nicht möglich, die Karte anzusteuern. Man muss in sein Projekt noch folgende Bibliothek einbinden:</p>
<p><a href="http://www.jcontrol.org/download/rxtx_en.html">RXTXcomm</a> (download)</p>
<p><a href="http://www.jcontrol.org/download/readme_rxtx_en.html">RXTXcomm Installationsanweisung</a> | <a href="http://circuitnegma.wordpress.com/2007/02/07/how-to-install-the-java-communications-api-in-a-windows-environment">Alternative Anleitung</a></p>
<p><strong>3.: Die eigentliche Klasse<br />
</strong></p>
<p>Im Handbuch der Relaiskarte ist von sogenannten Kommandos die Rede, mit denen man die einzelnen Relais ansteuern kann. Meine Klasse arbeitet wie folgt:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> Main <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main <span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> args<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">//VERBINDUNG AUFBAUEN</span>
		CRelais cRelais <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> CRelais<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;COM17&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">//RELAISKARTE-INITIIEREN</span>
		cRelais.<span style="color: #006633;">cmd</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">1</span>, <span style="color: #cc66cc;">0</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">//TEST: TOGGLE-BEFEHL MIT ALLEN KOMBINATIONEN HINTEREINANDER DURCHFÜHREN</span>
		<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span><span style="color: #cc66cc;">255</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			cRelais.<span style="color: #006633;">cmd</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">8</span>, <span style="color: #cc66cc;">1</span>, i <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//(int) Math.pow(2, i));</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
                <span style="color: #666666; font-style: italic;">//VERBINDUNG SCHLIE?EN</span>
		cRelais.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>&nbsp;</p>
<p>Wer sich mit dem <a href="http://www.produktinfo.conrad.com/datenblaetter/175000-199999/197720-an-01-ml-8FACH_RELAISKARTE_24V_7A_de_en_fr_nl.pdf">Handbuch</a> auseinandersetzt, der weiß auch, was die Zahlen im JAVA-Code bedeuten.</p>
<p>Hier der Quellcode <em>CRelais</em>-Klasse:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">gnu.io.CommPortIdentifier</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">gnu.io.SerialPort</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">gnu.io.SerialPortEvent</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">gnu.io.SerialPortEventListener</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">gnu.io.UnsupportedCommOperationException</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.BufferedOutputStream</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.IOException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.InputStream</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.OutputStream</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.TooManyListenersException</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> CRelais <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">private</span> CommPortIdentifier commPortIdentifier<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> SerialPort serialPort<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">OutputStream</span> outputStream<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">BufferedOutputStream</span> out<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">int</span> sleepTime<span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">InputStream</span> inputStream<span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//KONSTRUKTOR: VERBINDUNG MIT RELAISKARTE HERSTELLEN (z.B. comName = &quot;COM17&quot; )</span>
	CRelais<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> comName<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">//comName = &quot;COM17&quot;;</span>
		sleepTime <span style="color: #339933;">=</span> <span style="color: #cc66cc;">50</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//SEND + RESPOND works until 14ms, but not lower. 50ms sounds healthy ;) </span>
&nbsp;
		<span style="color: #666666; font-style: italic;">//COM-PORT-OPEN</span>
		<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
			commPortIdentifier <span style="color: #339933;">=</span> CommPortIdentifier.<span style="color: #006633;">getPortIdentifier</span><span style="color: #009900;">&#40;</span>comName<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			serialPort <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>SerialPort<span style="color: #009900;">&#41;</span> commPortIdentifier.<span style="color: #006633;">open</span><span style="color: #009900;">&#40;</span>comName,<span style="color: #cc66cc;">2000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			serialPort.<span style="color: #006633;">setSerialPortParams</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">19200</span>, SerialPort.<span style="color: #006633;">DATABITS_8</span>, SerialPort.<span style="color: #006633;">STOPBITS_1</span>, SerialPort.<span style="color: #006633;">PARITY_NONE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			outputStream <span style="color: #339933;">=</span> serialPort.<span style="color: #006633;">getOutputStream</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			out <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">BufferedOutputStream</span><span style="color: #009900;">&#40;</span>outputStream<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Connected to &quot;</span> <span style="color: #339933;">+</span> comName <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		 <span style="color: #009900;">&#125;</span>
		 <span style="color: #000000; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> exc<span style="color: #009900;">&#41;</span>
		 <span style="color: #009900;">&#123;</span>
			 <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Fehler Outputstream :&quot;</span><span style="color: #339933;">+</span>exc<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		 <span style="color: #009900;">&#125;</span>
&nbsp;
		 <span style="color: #666666; font-style: italic;">//INPUT-STREAM</span>
		 <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
			inputStream <span style="color: #339933;">=</span> serialPort.<span style="color: #006633;">getInputStream</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Inputstream open &quot;</span> <span style="color: #339933;">+</span> comName <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		 <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">IOException</span> exc<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Fehler Inputstream :&quot;</span><span style="color: #339933;">+</span>exc<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		 <span style="color: #009900;">&#125;</span>
		 <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
				serialPort.<span style="color: #006633;">addEventListener</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> serialPortEventListener<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">TooManyListenersException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;TooManyListenersException für Serialport&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			serialPort.<span style="color: #006633;">notifyOnDataAvailable</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
				serialPort.<span style="color: #006633;">setSerialPortParams</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">19200</span>, SerialPort.<span style="color: #006633;">DATABITS_8</span>, SerialPort.<span style="color: #006633;">STOPBITS_1</span>, SerialPort.<span style="color: #006633;">PARITY_NONE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span><span style="color: #009900;">&#40;</span>UnsupportedCommOperationException e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Konnte Schnittstellen-Paramter nicht setzen&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//SETTER-METHODE FÜR SLEEPTIME (zweit, die gewartet wird, nachdem ein Kommando versendet wurde)</span>
	<span style="color: #000066; font-weight: bold;">void</span> setSleepTime<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> newTime<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		sleepTime <span style="color: #339933;">=</span> newTime<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//KOMMANDO-METHODE</span>
	<span style="color: #000066; font-weight: bold;">void</span> cmd<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> cmd, <span style="color: #000066; font-weight: bold;">int</span> adress, <span style="color: #000066; font-weight: bold;">int</span> data<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">//KOMMANDOS IN ARRAY SCHREIBEN</span>
		<span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> sendData <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">4</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		sendData<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#41;</span> cmd<span style="color: #339933;">;</span>
		sendData<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#41;</span> adress<span style="color: #339933;">;</span>
		sendData<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#41;</span> data<span style="color: #339933;">;</span>
		sendData<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#40;</span>cmd <span style="color: #339933;">^</span> adress <span style="color: #339933;">^</span> data<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">//DATEN SENDEN</span>
		<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
			out.<span style="color: #006633;">write</span><span style="color: #009900;">&#40;</span>sendData, <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			out.<span style="color: #006633;">flush</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Data send: cmd &quot;</span> <span style="color: #339933;">+</span> sendData<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;; adress &quot;</span> <span style="color: #339933;">+</span> sendData<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;; data &quot;</span> <span style="color: #339933;">+</span> sendData<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;; XOR &quot;</span> <span style="color: #339933;">+</span> sendData<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot; &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">IOException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;No data sended&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">//WARTEN</span>
		<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #003399;">Thread</span>.<span style="color: #006633;">sleep</span><span style="color: #009900;">&#40;</span>sleepTime<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">InterruptedException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Sleeping failed&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">//VERBINDUNG ZUR RELAISKARTE BEENDEN</span>
	<span style="color: #000066; font-weight: bold;">void</span> close<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		serialPort.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Connection closed&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> serialPortDataAvailable<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> data <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #000066; font-weight: bold;">byte</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">4</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
			<span style="color: #000000; font-weight: bold;">while</span><span style="color: #009900;">&#40;</span>inputStream.<span style="color: #006633;">available</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
				inputStream.<span style="color: #006633;">read</span><span style="color: #009900;">&#40;</span>data, <span style="color: #cc66cc;">0</span>, data.<span style="color: #006633;">length</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
				<span style="color: #666666; font-style: italic;">//XOR-CHECK</span>
				<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">^</span> data<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">^</span> data<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> data<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Data resp: TRUE ; &quot;</span> <span style="color: #339933;">+</span> data<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;; &quot;</span> <span style="color: #339933;">+</span> data<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;; &quot;</span> <span style="color: #339933;">+</span> data<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;; XOR &quot;</span> <span style="color: #339933;">+</span> data<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot; &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
				<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Data resp: !!! FALSE !!! ; &quot;</span> <span style="color: #339933;">+</span> data<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;; adress &quot;</span> <span style="color: #339933;">+</span> data<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;; &quot;</span> <span style="color: #339933;">+</span> data<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot;; XOR &quot;</span> <span style="color: #339933;">+</span> data<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">3</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot; &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
&nbsp;
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">IOException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;!!! Data could not be recieved !!!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">class</span> serialPortEventListener <span style="color: #000000; font-weight: bold;">implements</span> SerialPortEventListener <span style="color: #009900;">&#123;</span>
		<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> serialEvent<span style="color: #009900;">&#40;</span>SerialPortEvent event<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">switch</span> <span style="color: #009900;">&#40;</span>event.<span style="color: #006633;">getEventType</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000000; font-weight: bold;">case</span> SerialPortEvent.<span style="color: #006633;">DATA_AVAILABLE</span><span style="color: #339933;">:</span>
				serialPortDataAvailable<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
			<span style="color: #000000; font-weight: bold;">case</span> SerialPortEvent.<span style="color: #006633;">BI</span><span style="color: #339933;">:</span>
			<span style="color: #000000; font-weight: bold;">case</span> SerialPortEvent.<span style="color: #006633;">CD</span><span style="color: #339933;">:</span>
			<span style="color: #000000; font-weight: bold;">case</span> SerialPortEvent.<span style="color: #006633;">CTS</span><span style="color: #339933;">:</span>
			<span style="color: #000000; font-weight: bold;">case</span> SerialPortEvent.<span style="color: #006633;">DSR</span><span style="color: #339933;">:</span>
			<span style="color: #000000; font-weight: bold;">case</span> SerialPortEvent.<span style="color: #006633;">FE</span><span style="color: #339933;">:</span>
			<span style="color: #000000; font-weight: bold;">case</span> SerialPortEvent.<span style="color: #006633;">OUTPUT_BUFFER_EMPTY</span><span style="color: #339933;">:</span>
			<span style="color: #000000; font-weight: bold;">case</span> SerialPortEvent.<span style="color: #006633;">PE</span><span style="color: #339933;">:</span>
			<span style="color: #000000; font-weight: bold;">case</span> SerialPortEvent.<span style="color: #006633;">RI</span><span style="color: #339933;">:</span>
			<span style="color: #000000; font-weight: bold;">default</span><span style="color: #339933;">:</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>
]]></content:encoded>
			<wfw:commentRss>http://www.derxen.de/blog/2011/technik/relaiskarte-mit-java-steuern/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
