<?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>Hackerbot Labs &#187; coding</title>
	<atom:link href="http://www.hackerbotlabs.com/tag/coding/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.hackerbotlabs.com</link>
	<description>Our blog. Let us show you it.</description>
	<lastBuildDate>Thu, 02 Feb 2012 20:33:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>The Laser Box</title>
		<link>http://www.hackerbotlabs.com/2009/03/the-laser-box/</link>
		<comments>http://www.hackerbotlabs.com/2009/03/the-laser-box/#comments</comments>
		<pubDate>Mon, 02 Mar 2009 05:18:58 +0000</pubDate>
		<dc:creator>Gnewt</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Electronics]]></category>
		<category><![CDATA[Featured]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[lasers]]></category>
		<category><![CDATA[shinp]]></category>

		<guid isPermaLink="false">http://www.hackerbotlabs.com/?p=326</guid>
		<description><![CDATA[Parts list: SHINP CL-16RGY OpenDMX USB dongle A while ago I was given a SHINP CL-16RGY by 3ric, to play with. We had no software for it, no experience with the box, and no clue what we could make it do. Here&#8217;s the story of what I did to make it work, and what we&#8217;re [...]]]></description>
			<content:encoded><![CDATA[<div class="mceTemp">
<dl>
<dt> </dt>
<dt><img class="size-full wp-image-343" src="http://www.hackerbotlabs.com/wp-content/uploads/2009/03/gnewt.jpg" alt="This is a long-exposure photo of me being scanned by the laser." width="450" height="299" /></dt>
</dl>
</div>
<p>Parts list:</p>
<ul>
<li>SHINP CL-16RGY</li>
<li>OpenDMX USB dongle</li>
</ul>
<p>A while ago I was given a <a href="http://szshinp.com/en/products.asp?nsid=4&amp;pid=13" target="_blank">SHINP CL-16RGY</a> by 3ric, to play with. We had no software for it, no experience with the box, and no clue what we could make it do. Here&#8217;s the story of what I did to make it work, and what we&#8217;re going to use it for in the future.</p>
<p>First, I needed to install a driver the Enttec Open DMX USB dongle. This is how we send signals to the laser. The first bit of info I found was <a href="http://www.opendmx.net/index.php/LLA_and_Q_Light_Controller_Ubuntu_Tutorial">here</a>, a tutorial on exactly the USB dongle we have. One problem: it&#8217;s for a Linux box. I have a Windows laptop. I fired up my Ubuntu virtual machine and got to work.</p>
<p>Compiling the driver was fairly easy. Mentioned in the tutorial I linked to is a driver from erwinrol.com. All I had to do was run a git command, make, copy the driver into the right directory, and then depmod. Voila, plugged the dongle into my laptop and it was recognized by Ubuntu as /dev/dmx0. Perfect! Next step was figuring out how to send it commands. I found some sample code somewhere (though unfortunately I can&#8217;t remember where). It looked like this:</p>
<pre>#include &lt;stdio.h&gt;
#include &lt;string.h&gt;
#include &lt;fcntl.h&gt;

int main()
{
  unsigned char buffer[513];
  int fd;

  memset(buffer, '\0', 513);

  fd = open("/dev/dmx0", O_WRONLY, 0);
  while (1) {
    write(fd, buffer, sizeof(buffer));
  }
}</pre>
<dl>
<dt><img class="size-full wp-image-329" src="http://www.hackerbotlabs.com/wp-content/uploads/2009/02/cl-16.jpg" alt="The CL-16RGY from szshinp.com" width="450" height="310" /></dt>
</dl>
<p>This worked to prove that the driver was working. The laser box has a little green LED on the back which signifies DMX512 data being received. It was blinking furiously. I thought &#8220;well, since it&#8217;s receiving data, everything after this will be easy.&#8221; I was very wrong. The manual told me that certain channels controlled certain things (channel 1 for X position, channel 2 for Y position, etc), and I assumed that the information would be correct. No. Of course not. It can&#8217;t be that easy.</p>
<p>I nearly gave up the project at this point. The terrible layout of the buffer was pissing me off. After a while though, I found a Windows DMX program. It didn&#8217;t work how I would have liked it do, but it let me adjust the channels in realtime, so I could figure out what things were. I squealed with joy (on the inside, of course) and took note of which channels corresponded to which functions. At the time, my code was in Python, so I edited the Python file and ran it. LAZOR WORKING! I tried editing a few of the channel values to make sure I was editing the correct positions in the buffer, and it worked just like it should.</p>
<p>My code at this time was in Python though, and I wanted the end result in C. I pretty much recreated the same code in C, implemented getopt, and cleaned up the code. It ended up being beautiful! Here is the sourcecode, a binary, and the CL-16RGY manual:</p>
<p><a href="http://www.gnewt.at/lazor/">http://www.gnewt.at/lazor/</a></p>
<img src="http://www.hackerbotlabs.com/?ak_action=api_record_view&id=326&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://www.hackerbotlabs.com/2009/03/the-laser-box/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

