<?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>Spice World!</title>
	<atom:link href="http://www.cyberspice.org.uk/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.cyberspice.org.uk/blog</link>
	<description>The life and times of a jet setting software engineer!</description>
	<lastBuildDate>Sun, 28 Feb 2010 16:11:28 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Capturing still images from video devices in PHP using Framegrab</title>
		<link>http://www.cyberspice.org.uk/blog/2010/02/28/capturing-still-images-from-video-devices-in-php-using-framegrab/</link>
		<comments>http://www.cyberspice.org.uk/blog/2010/02/28/capturing-still-images-from-video-devices-in-php-using-framegrab/#comments</comments>
		<pubDate>Sun, 28 Feb 2010 16:10:34 +0000</pubDate>
		<dc:creator>cyberspice</dc:creator>
				<category><![CDATA[C]]></category>
		<category><![CDATA[Geek]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Framegrab]]></category>
		<category><![CDATA[PECL]]></category>

		<guid isPermaLink="false">http://www.cyberspice.org.uk/blog/?p=433</guid>
		<description><![CDATA[I found I had a need to capture and process still video images from video devices using PHP so I wrote the Framegrab PECL extension.  This post introduces the basics of Framegrab.

The framegrab extension is currently only available for Linux although Windows and OS X support will be coming soon.  On Linux the [...]]]></description>
			<content:encoded><![CDATA[<p>I found I had a need to capture and process still video images from video devices using PHP so I wrote the Framegrab PECL extension.  This post introduces the basics of Framegrab.<br />
<span id="more-433"></span><br />
The framegrab extension is currently only available for Linux although Windows and OS X support will be coming soon.  On Linux the extension uses the Video For Linux API version 2.</p>
<p>Framegrab adds two classes to PHP.  <em>FrameGrabDevice</em> represents a video capture device and <em>FrameGrabImage</em> an image captured with a FrameGrabDevice.     </p>
<p>You can create a new <em>FrameGrabDevice</em> for the default video capture device as follows:</p>
<pre>
	$device = new FrameGrabDevice();
</pre>
<p>The extension will iterate through available video devices until it finds one that supports video capture.  A <em>FrameGrabDeviceException</em> will be thrown either if no video devices are available or if the available video devices do not support video capture.</p>
<p>You can supply an argument to the constructor (see below) if you want to initialise a specific video device.  In this case the <em>FrameGrabDeviceException</em> will be thrown if that specific device does not exist or does not support video capture.</p>
<pre>
	$device = new FrameGrabDevice('/dev/video1');
</pre>
<p>Once you have a device you can then grab an image using the <em>grab()</em> method.  The method takes no arguments and returns a <em>FrameGrabImage</em> object or false on error.  As the <em>FrameGrabImage</em> constructor is a protected method you cannot create objects directly using new.</p>
<p>Once you have the image you can either save the image to the file in PNG format or have it returned as a string in PNG format using the writeAsPNG() and toStringAsPNG() methods respectively.  The former takes a filename as the sole argument and returns false on error.  The latter takes no arguments and returns either the PNG data as a string or false on error.</p>
<p>The two objects also support a number of properties.  The code below demonstrates the extension in use.  It returns an image captured from the default video device as a PNG.  The image has capture device and image meta data embedded in it visible in the top left corner of the image.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
try <span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// Get the default frame grabber device.  Throws an exception if a device</span>
	<span style="color: #666666; font-style: italic;">// cannot be found.</span>
	<span style="color: #000088;">$device</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> FrameGrabDevice<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Grab am image.</span>
	<span style="color: #000088;">$fgimage</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$device</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">grab</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$fgimage</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// Create a GD image from a frame grab image</span>
		<span style="color: #000088;">$gdimage</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecreatefromstring</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fgimage</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">toStringAsPNG</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// Output data about the image on to the image</span>
		<span style="color: #000088;">$font</span>  <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$black</span> <span style="color: #339933;">=</span> <span style="color: #990000;">imagecolorallocate</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$gdimage</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$fh</span>    <span style="color: #339933;">=</span> <span style="color: #990000;">imagefontheight</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$font</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$x</span>     <span style="color: #339933;">=</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$y</span>     <span style="color: #339933;">=</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">imagestring</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$gdimage</span><span style="color: #339933;">,</span> <span style="color: #000088;">$font</span><span style="color: #339933;">,</span> <span style="color: #000088;">$x</span><span style="color: #339933;">,</span> <span style="color: #000088;">$y</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Device: &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$device</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">device</span><span style="color: #339933;">,</span> <span style="color: #000088;">$black</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$y</span> <span style="color: #339933;">+=</span> <span style="color: #000088;">$fh</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">imagestring</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$gdimage</span><span style="color: #339933;">,</span> <span style="color: #000088;">$font</span><span style="color: #339933;">,</span> <span style="color: #000088;">$x</span><span style="color: #339933;">,</span> <span style="color: #000088;">$y</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Card: &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$device</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">card</span><span style="color: #339933;">,</span> <span style="color: #000088;">$black</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$y</span> <span style="color: #339933;">+=</span> <span style="color: #000088;">$fh</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">imagestring</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$gdimage</span><span style="color: #339933;">,</span> <span style="color: #000088;">$font</span><span style="color: #339933;">,</span> <span style="color: #000088;">$x</span><span style="color: #339933;">,</span> <span style="color: #000088;">$y</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Width: &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$fgimage</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">width</span><span style="color: #339933;">,</span> <span style="color: #000088;">$black</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$y</span> <span style="color: #339933;">+=</span> <span style="color: #000088;">$fh</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">imagestring</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$gdimage</span><span style="color: #339933;">,</span> <span style="color: #000088;">$font</span><span style="color: #339933;">,</span> <span style="color: #000088;">$x</span><span style="color: #339933;">,</span> <span style="color: #000088;">$y</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Height: &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$fgimage</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">height</span><span style="color: #339933;">,</span> <span style="color: #000088;">$black</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$y</span> <span style="color: #339933;">+=</span> <span style="color: #000088;">$fh</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">imagestring</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$gdimage</span><span style="color: #339933;">,</span> <span style="color: #000088;">$font</span><span style="color: #339933;">,</span> <span style="color: #000088;">$x</span><span style="color: #339933;">,</span> <span style="color: #000088;">$y</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Format: &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$fgimage</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">format</span><span style="color: #339933;">,</span> <span style="color: #000088;">$black</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$y</span> <span style="color: #339933;">+=</span> <span style="color: #000088;">$fh</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">imagestring</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$gdimage</span><span style="color: #339933;">,</span> <span style="color: #000088;">$font</span><span style="color: #339933;">,</span> <span style="color: #000088;">$x</span><span style="color: #339933;">,</span> <span style="color: #000088;">$y</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;Bytes per line: &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$fgimage</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">bytes_per_line</span><span style="color: #339933;">,</span> <span style="color: #000088;">$black</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #666666; font-style: italic;">// Output the image</span>
		<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-Type: image/png'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">imagepng</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$gdimage</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">imagedestroy</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$gdimage</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span> catch <span style="color: #009900;">&#40;</span>Exception <span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// Handle the FrameGrabDevice exception here.</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>The extension is available <a href="http://pecl.php.net/package/framegrab">at the PECL site</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cyberspice.org.uk/blog/2010/02/28/capturing-still-images-from-video-devices-in-php-using-framegrab/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Serial IO in PHP using the DIO extension</title>
		<link>http://www.cyberspice.org.uk/blog/2010/02/15/serial-io-in-php-using-the-dio-extension/</link>
		<comments>http://www.cyberspice.org.uk/blog/2010/02/15/serial-io-in-php-using-the-dio-extension/#comments</comments>
		<pubDate>Mon, 15 Feb 2010 16:36:03 +0000</pubDate>
		<dc:creator>cyberspice</dc:creator>
				<category><![CDATA[C]]></category>
		<category><![CDATA[Geek]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[DIO]]></category>
		<category><![CDATA[PECL]]></category>

		<guid isPermaLink="false">http://www.cyberspice.org.uk/blog/?p=429</guid>
		<description><![CDATA[DIO is the Direct IO extension for PHP.  I recently took over maintaining this extension and have implemented comprehensive stream support for both POSIX and Windows systems.  To demonstrate the use of DIO this post will describe a PHP script that sends an SMS using a USB 3G modem.

To make control of modems [...]]]></description>
			<content:encoded><![CDATA[<p>DIO is the Direct IO extension for PHP.  I recently took over maintaining this extension and have implemented comprehensive stream support for both POSIX and Windows systems.  To demonstrate the use of DIO this post will describe a PHP script that sends an SMS using a USB 3G modem.<br />
<span id="more-429"></span></p>
<p>To make control of modems easier over twenty years ago the Hayes Corporation developed a serial command protocol, the Hayes or AT command set.  Many other modems adopted the protocol and now its a de-facto standard.  Over the years as modem functionality expanded so did the command set.  Now it supports FAX, cell phone address books, SMSes and so on.  The AT command set comprises a set of text based commands terminated with CRLF.  The responses are similarly text strings terminated with CRLF.  Typically the modem responds with &#8220;OK&#8221;, &#8220;ERROR&#8221; or a setting value.</p>
<p>DIO currently provides two stream types <em>raw</em> and <em>serial</em>.  Raw streams provide low level access to operating system devices.  Serial streams provide access to, and abstract, serial ports.  DIO stream support is accessed just like any other PHP streams.  The appropriate URI is <a href="http://uk2.php.net/manual/en/function.fopen.php">fopen</a>ed.  The relevant URIs are:</p>
<pre>
dio.raw://[device]
</pre>
<p>for raw streams and</p>
<pre>
dio.serial://[device]
</pre>
<p>for serials streams.  In both cases [device] is the device name to open.  For example this could be /dev/random for the random device on Linux; or /dev/ttyS0 for a comms port on Linux; or COM1 for a comms port on Windows.  We&#8217;ll be using the later form of the URI as we&#8217;re opening a serial port.  </p>
<p>The example code opens the serial port as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$f</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fopen</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;dio.serial:///dev/tty.ZTEUSBATPort_&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;r+&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #000088;">$c</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The first argument is the device to open.  In this case a serial port to the USB 3G modem connected to my MacBook.  The second is the open mode, in this case read/write.  The third is an optional argument that comprises a flag that indicates whether to search the include path for the file to open.  We don&#8217;t want this.  The final optional argument is a stream context which is a collection of stream specific additional parameters.</p>
<p>A stream context is created using <a href="http://uk2.php.net/manual/en/function.stream-context-create.php">stream_context_create</a>().  The code in the example that creates the context, prior to opening the port, is shown below.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$c</span> <span style="color: #339933;">=</span> <span style="color: #990000;">stream_context_create</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'dio'</span> <span style="color: #339933;">=&gt;</span> 
	<span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'data_rate'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">9600</span><span style="color: #339933;">,</span> 
		  <span style="color: #0000ff;">'data_bits'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">8</span><span style="color: #339933;">,</span> 
		  <span style="color: #0000ff;">'stop_bits'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> 
		  <span style="color: #0000ff;">'parity'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> 
		  <span style="color: #0000ff;">'flow_control'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
		  <span style="color: #0000ff;">'is_blocking'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
		  <span style="color: #0000ff;">'canonical'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The first four context options are pretty obvious.  The serial port is being configured for 9600 bits per second, 8 bits per byte with 1 additional stop bit per byte and no parity checking.</p>
<p>The next option disables hardware flow control.  Serial ports are relatively slow so they often have hardware control lines which indicate when there is data ready to be sent and space in the buffer ready to receive data.  My USB modem does not have these so the hardware flow control is disabled.</p>
<p>Next we turn off blocking.  With blocking function calls the operating system waits for data and only returns when it is ready to return the data that was requested i.e. the operating system blocks on the data.  Non-blocking function calls return whether there is data or not.  The POSIX open call also blocks on the state of the Data Carrier Detect (&#8220;DCD&#8221;) hardware control line.  Some modems have this control line and use it to indicate there&#8217;s a carrier signal on the telephone line.  Again since the USB modem does not have this we disable it.</p>
<p>Finally we enable canonical mode.  Canonical IO on POSIX means that the serial port driver will wait for a line of text ending in a newline (or the internal buffer being full) before returning.  If less characters than were entered on the line were requested the driver buffers the data for subsequent reads until the entire line is returned.  In canonical mode you can actually connect a terminal to the serial port as line editing is supported.  Since Windows does not have a canonical mode DIO provides an implementation on top of the Windows driver.  The alternative to canonical mode is byte mode where by DIO waits until the requested number of bytes have been read and returns regardless of whether there are more bytes available.</p>
<p>If all that sounds a little complicated think of it like this.  If you&#8217;re reading strings terminated with a new line use canonical mode otherwise use byte mode.</p>
<p>Remember that blocking was disabled so that opening the serial device did not block.  This isn&#8217;t desirable when actually reading data.  Blocking mode can be re-enabled on an open stream using <a href="http://uk2.php.net/manual/en/function.stream-set-blocking.php">stream_set_blocking</a> as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">stream_set_blocking</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$f</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Once the serial port has been opened with the appropriate port settings and blocking re-enabled the port can be written and read using the standard <a href="http://uk2.php.net/manual/en/function.fprintf.php">fprintf</a> and <a href="http://uk2.php.net/manual/en/function.fgets.php">fgets</a> PHP functions.</p>
<p>There are two AT commands related to sending an SMS.  The first is &#8220;AT+CMGF=1&#8243; which tells the modem to operate in SMS text mode.  This should respond with &#8220;OK&#8221;.  The second is &#8220;AT+CMGS=&#8221; which is followed by a string comprising a telephone number.  This accepts the text of an SMS which is sent when CTRL-Z is entered.  </p>
<p>There&#8217;s a little bit of additional work in the example as the modem echos data sent to it back to the sender so the PHP code consumes data after a command is sent until it sees the sent command echoed back.  The full example follows.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> 
&nbsp;
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'PHONE_NUMBER'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'5551234'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">define</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'SMS_TEXT'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Hello world!'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/**
 * Sends data to the modem
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> send_data<span style="color: #009900;">&#40;</span><span style="color: #000088;">$f</span><span style="color: #339933;">,</span> <span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt; <span style="color: #006699; font-weight: bold;">$string</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #990000;">fprintf</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$f</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$string</span><span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/**
 * Reads lines from the serial port.  It reads until a non blank line is
 * received then returns it.
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> get_string<span style="color: #009900;">&#40;</span><span style="color: #000088;">$f</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">do</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// remove carriage returns, line feeds and excess white space</span>
		<span style="color: #000088;">$response</span> <span style="color: #339933;">=</span> <span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">str_replace</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span>&quot;</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #990000;">fgets</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$f</span><span style="color: #009900;">&#41;</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: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$response</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$response</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/**
 * Waits for OK to be sent back by the modem.
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> wait_for_ok<span style="color: #009900;">&#40;</span><span style="color: #000088;">$f</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">do</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$response</span> <span style="color: #339933;">=</span> get_string<span style="color: #009900;">&#40;</span><span style="color: #000088;">$f</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&gt; <span style="color: #006699; font-weight: bold;">$response</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$response</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">&quot;OK&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;">// MAIN CODE</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Create the context</span>
<span style="color: #000088;">$c</span> <span style="color: #339933;">=</span> <span style="color: #990000;">stream_context_create</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'dio'</span> <span style="color: #339933;">=&gt;</span> 
	<span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'data_rate'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">9600</span><span style="color: #339933;">,</span> 
		  <span style="color: #0000ff;">'data_bits'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">8</span><span style="color: #339933;">,</span> 
		  <span style="color: #0000ff;">'stop_bits'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> 
		  <span style="color: #0000ff;">'parity'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> 
		  <span style="color: #0000ff;">'flow_control'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
		  <span style="color: #0000ff;">'is_blocking'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
		  <span style="color: #0000ff;">'canonical'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Open the port</span>
<span style="color: #000088;">$f</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fopen</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;dio.serial:///dev/tty.ZTEUSBATPort_&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;r+&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #000088;">$c</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$f</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// Re-enable blocking</span>
	<span style="color: #990000;">stream_set_blocking</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$f</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Set SMS text entry mode</span>
	send_data<span style="color: #009900;">&#40;</span><span style="color: #000088;">$f</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;AT+CMGF=1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	wait_for_ok<span style="color: #009900;">&#40;</span><span style="color: #000088;">$f</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Send an SMS</span>
	send_data<span style="color: #009900;">&#40;</span><span style="color: #000088;">$f</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;AT+CMGS=<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span> <span style="color: #339933;">.</span> PHONE_NUMBER <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	send_data<span style="color: #009900;">&#40;</span><span style="color: #000088;">$f</span><span style="color: #339933;">,</span> SMS_TEXT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #666666; font-style: italic;">// Send CTRL-Z to end SMS text entry</span>
	<span style="color: #990000;">fprintf</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$f</span><span style="color: #339933;">,</span> <span style="color: #990000;">chr</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">26</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
	wait_for_ok<span style="color: #009900;">&#40;</span><span style="color: #000088;">$f</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Close the port</span>
	<span style="color: #990000;">fclose</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$f</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;">?&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.cyberspice.org.uk/blog/2010/02/15/serial-io-in-php-using-the-dio-extension/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>PHP DIO Extension: Looking for beta testers</title>
		<link>http://www.cyberspice.org.uk/blog/2010/02/02/php-dio-extension-looking-for-beta-testers/</link>
		<comments>http://www.cyberspice.org.uk/blog/2010/02/02/php-dio-extension-looking-for-beta-testers/#comments</comments>
		<pubDate>Tue, 02 Feb 2010 19:58:20 +0000</pubDate>
		<dc:creator>cyberspice</dc:creator>
				<category><![CDATA[C]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[DIO]]></category>
		<category><![CDATA[PECL]]></category>

		<guid isPermaLink="false">http://www.cyberspice.org.uk/blog/?p=424</guid>
		<description><![CDATA[A few months ago I had a need to do some serial IO from PHP.  After asking around I found out there was a PHP extension for this but it was unmaintained, unowned and out of date.  To cut a long story short I ended up as the maintainer of said extension and [...]]]></description>
			<content:encoded><![CDATA[<p>A few months ago I had a need to do some serial IO from PHP.  After asking around I found out there was a PHP extension for this but it was unmaintained, unowned and out of date.  To cut a long story short I ended up as the maintainer of said extension and since them I have been fixing and extending it.</p>
<p>The original DIO API is very basic and POSIX oriented.  Serial support is not very configurable and doesn&#8217;t work at all on Window platforms.  So I have been working on implementing PHP stream extensions that allow you to do raw and serial IO via streams.  Anyway its ready for testing by people other than me on POSIX (Linux, OS X etc) and Windows platforms so I&#8217;m looking for beta testers.</p>
<p><span id="more-424"></span></p>
<h2>Where to get it</h2>
<p>The release candidate is downloadable as a package from:</p>
<p><a href="http://www.cyberspice.org.uk/downloads/dio-0.0.4rc3.tgz">http://www.cyberspice.org.uk/downloads/dio-0.0.4rc3.tgz</a></p>
<p>And directly from SVN at:</p>
<p><a href="http://svn.php.net/repository/pecl/dio/tags/RELEASE_0_0_4RC3">http://svn.php.net/repository/pecl/dio/tags/RELEASE_0_0_4RC3</a></p>
<h2>Documentation</h2>
<p>While I write proper PHP documentation below is a brief over view of how you use DIO.</p>
<h3>Streams</h3>
<p>DIO streams are just PHP streams.  You use <a href="http://www.php.net/manual/en/function.fopen.php">fopen()</a> to open them and <a href="http://www.php.net/manual/en/function.fread.php">fread()</a>, <a href="http://www.php.net/manual/en/function.fwrite.php">fwrite()</a>, <a href="http://www.php.net/manual/en/function.fgets.php">fgets()</a>, <a href="http://www.php.net/manual/en/function.stream-set-blocking.php">stream_set_blocking()</a> etc. There are two DIO streams, dio.raw and dio.serial.  </p>
<p>dio.raw is as it sounds, raw streams.  It uses the low level OS streams such as open(), read(), write(), close() etc. on POSIX and CreateFile(), OpenFile(), ReadFile(), WriteFile(), CloseFile() on Windows.  It does not buffer except the internal PHP buffering.</p>
<p>dio.serial is full serial support.  It allows setting of data rates, data size, stop bits, handshaking and raw/canonical modes etc.</p>
<p>Both stream types support timeouts and blocking/non-blocking use.</p>
<h3>Example code</h3>
<p>Below is a small example that opens a serial port, configuring it with a stream context, and then reads and writes from it before closing it.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> 
	<span style="color: #666666; font-style: italic;">// Create a stream context that configures the serial port</span>
	<span style="color: #666666; font-style: italic;">// And enables canonical input.</span>
	<span style="color: #000088;">$c</span> <span style="color: #339933;">=</span> <span style="color: #990000;">stream_context_create</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'dio'</span> <span style="color: #339933;">=&gt;</span> 
		<span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'data_rate'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">115200</span><span style="color: #339933;">,</span> 
		      <span style="color: #0000ff;">'data_bits'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">8</span><span style="color: #339933;">,</span> 
		      <span style="color: #0000ff;">'stop_bits'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span> 
		      <span style="color: #0000ff;">'parity'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> 
		      <span style="color: #0000ff;">'is_canonical'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Are we POSIX or Windows?  POSIX platforms do not have a</span>
	<span style="color: #666666; font-style: italic;">// Standard port naming scheme so it could be /dev/ttyUSB0</span>
	<span style="color: #666666; font-style: italic;">// or some long /dev/tty.serial_port_name_thingy on OSX.</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>PATH_SEPARATOR <span style="color: #339933;">!=</span> <span style="color: #0000ff;">&quot;;&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$filename</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;dio.serial:///dev/ttyS0&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$filename</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;dio.serial://COM1&quot;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Open the stream for read only and use it.</span>
	<span style="color: #000088;">$f</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fopen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$filename</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;r+&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #000088;">$c</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$f</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Writing to port...<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #990000;">fprintf</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$f</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;Hello world<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Reading from port...<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fgets</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$f</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$data</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #990000;">fclose</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$f</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;">?&gt;</span></pre></div></div>

<h3>Stream context</h3>
<p>DIO uses the stream context to obtain the port configuration settings.  There are settings which are common to all DIO streams and settings which are sub-stream specific.  The common settings are:</p>
<style type="text/css">
th,td { text-align:left; vertical-align:top; }
</style>
<table style="width: 600px; margin: 0 auto">
<tr>
<th>perms</th>
<td>Integer</td>
<td>Sets the file permissions mask when creating a file (POSIX specific, ignored on Windows)</td>
</tr>
<tr>
<th>is_blocking</th>
<td>Boolean</td>
<td>Indicates whether the stream is blocking (true, default) or non blocking (false)</td>
</tr>
<tr>
<th>timeout_secs</th>
<td>Integer</td>
<td>The time to wait for input in seconds before returning.  Also sets the stream non blocking.</td>
</tr>
<tr>
<th>timeout_usecs</th>
<td>Integer</td>
<td>The time to wait for input in micro seconds before returning.  Used in conjunction with timeout_secs.  If omitted but timeout_secs is defined it is assumed to be zero.</td>
</tr>
</table>
<p>Both the blocking setting and the timeout settings can changed after the stream is open using the PHP functions <a href="http://www.php.net/manual/en/function.stream-set-blocking.php">stream_set_blocking()</a> and <a href="http://www.php.net/manual/en/function.stream-set-timeout.php">stream_set_timeout()</a> respectively.</p>
<p>The serial stream has the following additional configuration settings.</p>
<table style="width: 600px; margin: 0 auto">
<tr>
<th>data_rate</th>
<td>Integer</td>
<td>Sets the data rate in bits per second (Not BAUD.  BAUD is symbols per second.  A symbol may include more than one bit)</td>
</tr>
<tr>
<th>data_bits</th>
<td>Integer</td>
<td>Number of bits per byte.  Typically 5, 6, 7 or 8 (default).</td>
</tr>
<tr>
<th>stop_bits</th>
<td>Integer</td>
<td>The number of stop bits. 1 (default), 2 or 3 (1.5 stop bits)</td>
</tr>
<tr>
<th>parity</th>
<td>Integer</td>
<td>The parity checking.  0 (None, default), 1 (Odd), 2 (Even).</td>
</tr>
<tr>
<th>flow_control</th>
<td>Boolean</td>
<td>Enables/disables hardware flow control</td>
</tr>
<tr>
<th>is_canonical</th>
<td>Boolean</td>
<td>Enables canonical input mode.  Canonical input buffers the input until either internal buffer is full or an end of line has been received.  So a read in canonical mode will block until an end of line or file even if more than the requested characters have been read from the remote machine.  </p>
<p>Full canonical mode handles control characters, delete, echoing characters back to the remote machine and so on.  Its basically used to implement a terminal.  DIO doesn&#8217;t have any of the latter other than the buffering. Yet!</td>
</tr>
</table>
<h3>Finally</h3>
<p>So there you are.  Any results, good or bad, are useful.  DIO has error checking and will return useful warnings if you try and feed it silly values.  Logs, PHP versions, etc. would be useful diagnosing issues.  Thanks.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cyberspice.org.uk/blog/2010/02/02/php-dio-extension-looking-for-beta-testers/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Manchester Geek Girl Afternoon Tea</title>
		<link>http://www.cyberspice.org.uk/blog/2010/01/11/manchester-geek-girl-afternoon-tea/</link>
		<comments>http://www.cyberspice.org.uk/blog/2010/01/11/manchester-geek-girl-afternoon-tea/#comments</comments>
		<pubDate>Mon, 11 Jan 2010 17:24:41 +0000</pubDate>
		<dc:creator>cyberspice</dc:creator>
				<category><![CDATA[Electronics]]></category>
		<category><![CDATA[Geek]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Women In Technology]]></category>
		<category><![CDATA[LinkedIn]]></category>
		<category><![CDATA[mggd]]></category>
		<category><![CDATA[mggt]]></category>

		<guid isPermaLink="false">http://www.cyberspice.org.uk/blog/?p=418</guid>
		<description><![CDATA[While I&#8217;m announcing appearances I am excited to announce that I am presenting an Arduino workshop at Manchester Geek Girl Afternoon Tea this month at Madlab, Manchester&#8217;s Hackspace in the Northern Quarter.
I will be bringing a long several Arduino-a-likes together with a variety of components and CDs of the IDE so that we can get [...]]]></description>
			<content:encoded><![CDATA[<p>While I&#8217;m announcing appearances I am excited to announce that I am presenting an <a href="http://www.arduino.cc/">Arduino</a> workshop at <a href="http://girlgeektea.eventbrite.com/">Manchester Geek Girl Afternoon Tea</a> this month at <a href="http://madlab.org.uk/content/girl-geek-afternoon-tea-2/">Madlab</a>, Manchester&#8217;s Hackspace in the Northern Quarter.</p>
<p>I will be bringing a long several Arduino-a-likes together with a variety of components and CDs of the IDE so that we can get together in groups, code and play.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cyberspice.org.uk/blog/2010/01/11/manchester-geek-girl-afternoon-tea/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Newcastle Maker Faire 2010</title>
		<link>http://www.cyberspice.org.uk/blog/2010/01/11/newcastle-maker-faire-2010/</link>
		<comments>http://www.cyberspice.org.uk/blog/2010/01/11/newcastle-maker-faire-2010/#comments</comments>
		<pubDate>Mon, 11 Jan 2010 17:08:44 +0000</pubDate>
		<dc:creator>cyberspice</dc:creator>
				<category><![CDATA[Crafty]]></category>
		<category><![CDATA[Electronics]]></category>
		<category><![CDATA[Geek]]></category>
		<category><![CDATA[2010]]></category>
		<category><![CDATA[LinkedIn]]></category>
		<category><![CDATA[Makerfaire]]></category>
		<category><![CDATA[Newcastle]]></category>

		<guid isPermaLink="false">http://www.cyberspice.org.uk/blog/?p=416</guid>
		<description><![CDATA[I am delighted to announce that I have been selected to exhibit at Newcastle Maker Faire.  The theme of my display will be crafty geekery.  
I am intending to take along items which are a mix of traditional crafts such as knitting and jewellery making combined with tech.  For example programmable earrings, [...]]]></description>
			<content:encoded><![CDATA[<p>I am delighted to announce that I have been selected to exhibit at <a href="http://www.makerfaire.com/newcastle/2010/">Newcastle Maker Faire</a>.  The theme of my display will be crafty geekery.  </p>
<p>I am intending to take along items which are a mix of traditional crafts such as knitting and jewellery making combined with tech.  For example programmable earrings, a temperature sensing hat and a bag that has a proximity detector and RFID tag so it can detect its owner.  </p>
<p>I am also going to show off a couple of my other projects like an ethernet adapter for a BBC microcomputer and a &#8220;Mood Wall&#8221; (It analyses twitter tweets for the mood of the content displaying patterns and colours which reflect the prevailing mood).</p>
<p>Hopefully I will see you there!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cyberspice.org.uk/blog/2010/01/11/newcastle-maker-faire-2010/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>101 goals in 1001 days and a photo a day</title>
		<link>http://www.cyberspice.org.uk/blog/2010/01/02/101-goals-in-1001-days-and-a-photo-a-day/</link>
		<comments>http://www.cyberspice.org.uk/blog/2010/01/02/101-goals-in-1001-days-and-a-photo-a-day/#comments</comments>
		<pubDate>Sat, 02 Jan 2010 02:54:36 +0000</pubDate>
		<dc:creator>cyberspice</dc:creator>
				<category><![CDATA[Getting Things Done]]></category>
		<category><![CDATA[Photography]]></category>

		<guid isPermaLink="false">http://www.cyberspice.org.uk/blog/?p=411</guid>
		<description><![CDATA[So its a new year and a significant year, 2010, so I&#8217;ve decided to start two projects which are somewhat related.  My first project is &#8220;101 goals in 1001 days&#8221;.  Basically I am setting myself 101 personal goals to achieve 1001 days i.e. by the end of 27 September 2012.  This can [...]]]></description>
			<content:encoded><![CDATA[<p>So its a new year and a significant year, 2010, so I&#8217;ve decided to start two projects which are somewhat related.  My first project is &#8220;101 goals in 1001 days&#8221;.  Basically I am setting myself 101 personal goals to achieve 1001 days i.e. by the end of 27 September 2012.  This can be anything from cycling to work, knitting a jumper to carrying out a solo sky dive.  </p>
<p>In order to record my achievements or otherwise I have created a new blog at <a href="http://www.cyberspice.org.uk/101in1001/">http://www.cyberspice.org.uk/101in1001/</a>.  And my (growing) list of goals with links to pages that describe each goal is <a href="http://www.cyberspice.org.uk/101in1001/about/">here</a>.</p>
<p>The first goal is &#8220;A photo a day for at least 365 days&#8221;.  Basically I have set myself the task of taking, and posting to a blog, a photo each day for at least a year.  So I&#8217;ve created a new blog for that too at <a href="http://www.cyberspice.org.uk/oneaday/">http://www.cyberspice.org.uk/oneaday/</a>.  Below is my photo for Jan 1, 2010.</p>
<div style="text-align:center;"><a href="http://www.flickr.com/photos/39013214@N03/4234817545" title="View 'BBC Micro keyboard' on Flickr.com"><img border="0" width="333" alt="BBC Micro keyboard" src="http://farm5.static.flickr.com/4032/4234817545_d1376beacd.jpg" height="500"/></a></div>
]]></content:encoded>
			<wfw:commentRss>http://www.cyberspice.org.uk/blog/2010/01/02/101-goals-in-1001-days-and-a-photo-a-day/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ribbed Scarf and Beads</title>
		<link>http://www.cyberspice.org.uk/blog/2009/12/24/ribbed-scarf-and-beads/</link>
		<comments>http://www.cyberspice.org.uk/blog/2009/12/24/ribbed-scarf-and-beads/#comments</comments>
		<pubDate>Thu, 24 Dec 2009 14:09:18 +0000</pubDate>
		<dc:creator>cyberspice</dc:creator>
				<category><![CDATA[Crafty]]></category>
		<category><![CDATA[Beads]]></category>
		<category><![CDATA[Knitting]]></category>

		<guid isPermaLink="false">http://www.cyberspice.org.uk/blog/?p=408</guid>
		<description><![CDATA[For those who want to know, this is how the ribbed scarf turned out!

I have given it to one of my my sister&#8217;s as a gift.  For the other sister I made her some beaded jewelery.

]]></description>
			<content:encoded><![CDATA[<p>For those who want to know, this is how the ribbed scarf turned out!</p>
<div style="text-align:center;"><a href="http://www.flickr.com/photos/39013214@N03/4189705027" title="View 'Finished ribbed tassle scarf' on Flickr.com"><img border="0" width="500" alt="Finished ribbed tassle scarf" src="http://farm3.static.flickr.com/2783/4189705027_d8160aa4db.jpg" height="333"/></a></div>
<p>I have given it to one of my my sister&#8217;s as a gift.  For the other sister I made her some beaded jewelery.</p>
<div style="text-align:center;"><a href="http://www.flickr.com/photos/39013214@N03/4190469596" title="View 'Necklace and earrings' on Flickr.com"><img border="0" width="500" alt="Necklace and earrings" src="http://farm3.static.flickr.com/2623/4190469596_8fbe1d6470.jpg" height="333"/></a></div>
]]></content:encoded>
			<wfw:commentRss>http://www.cyberspice.org.uk/blog/2009/12/24/ribbed-scarf-and-beads/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>T&#8217;info about Dash</title>
		<link>http://www.cyberspice.org.uk/blog/2009/12/24/tinfo-about-dash/</link>
		<comments>http://www.cyberspice.org.uk/blog/2009/12/24/tinfo-about-dash/#comments</comments>
		<pubDate>Thu, 24 Dec 2009 12:45:15 +0000</pubDate>
		<dc:creator>cyberspice</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[dash]]></category>
		<category><![CDATA[libncurses]]></category>
		<category><![CDATA[libtinfo]]></category>
		<category><![CDATA[sh]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://www.cyberspice.org.uk/blog/?p=404</guid>
		<description><![CDATA[Once upon a time there was the Bourne command shell.  sh as it is known is core at the heart of any UNIXy type operating system and others too.  However for some it didn&#8217;t do enough so the Bourne Again shell, bash, was written and nearly every system ships with that.  These [...]]]></description>
			<content:encoded><![CDATA[<p>Once upon a time there was the Bourne command shell.  <strong>sh</strong> as it is known is core at the heart of any UNIXy type operating system and others too.  However for some it didn&#8217;t do enough so the Bourne Again shell, <strong>bash</strong>, was written and nearly every system ships with that.  These shells are not the same.  The have similar syntax but do not behave similarly.</p>
<p>There are other shells which have a completely different syntax and other scripting languages such as Perl and PHP so when writing a shell script you can indicate the correct interpreter using the <em>&#8216;hash bang bin bash&#8217;</em> comment to indicate you are using <strong>bash</strong>.  I.e.</p>
<pre>
#!/bin/bash
</pre>
<p>Some lazy programmers don&#8217;t indicate the exact shell they require and use </p>
<pre>
#!/bin/sh
</pre>
<p>to mean <strong>bash</strong> when it means <strong>sh</strong>.</p>
<p>Ubuntu, in their wisdom, have decided to go for <strong>dash</strong> as their shell.  It is an evolution of the Almquist shell and is smaller and lighter weight than <strong>bash</strong> however they install <strong>bash</strong> anyway.  <strong>dash</strong> and <strong>bash</strong> have the common subset of <strong>sh</strong> commands but are different.  So if you find you have a problem building or similar on Ubuntu it may be that the wrong shell is being used.  Ubuntu has a symlink as follows:</p>
<pre>
lrwxrwxrwx 1 root root       4 Mar 29  2009 sh -> dash
</pre>
<p>You may need to change this to point to dash as follows:</p>
<pre>
$ cd /bin
$ sudo rm sh
$ sudo ln -s bash sh
</pre>
<p>While we&#8217;re handling Ubuntu oddities building against NCurses, the terminal output library, can also be problematical.  A little while ago NCurses was split in to two libraries, <em>libncurses.so</em> and <em>libtinfo.so</em>.  Some badly written software will try and link explicitly with <em>libtinfo.so</em> directly rather than trying <em>libncurses.so</em> first.  Ubuntu does not split these two libraries but provides just the one <em>libncurses.so</em> library so if you have an issue with a missing <em>libtinfo.so</em> you will need to add symlinks in to your library directory as follows:</p>
<pre>
$ cd /usr/lib
$ ln -s libncurses.so.5 libtinfo.so.5
$ ln -s libtinfo.so.5 libtinfo.so
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.cyberspice.org.uk/blog/2009/12/24/tinfo-about-dash/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>iPhone cosy</title>
		<link>http://www.cyberspice.org.uk/blog/2009/12/01/iphone-cosy/</link>
		<comments>http://www.cyberspice.org.uk/blog/2009/12/01/iphone-cosy/#comments</comments>
		<pubDate>Tue, 01 Dec 2009 15:42:43 +0000</pubDate>
		<dc:creator>cyberspice</dc:creator>
				<category><![CDATA[Crafty]]></category>
		<category><![CDATA[Knitting]]></category>

		<guid isPermaLink="false">http://www.cyberspice.org.uk/blog/?p=398</guid>
		<description><![CDATA[A short while ago I went down with the &#8216;flu&#8217;.  Usually in these cases the best thing for me to do is rest and sleep.  But eventually I get bored so I have to find something to do.  So this time I sat in a recliner, watching a movie, whilst teaching myself [...]]]></description>
			<content:encoded><![CDATA[<p>A short while ago I went down with the &#8216;flu&#8217;.  Usually in these cases the best thing for me to do is rest and sleep.  But eventually I get bored so I have to find something to do.  So this time I sat in a recliner, watching a movie, whilst teaching myself to Purl.  I wanted a project I could finish in an evening to use my new found skill so I modified the &#8220;Cricket&#8217;s Cell Phone Cozy&#8221; design and learnt to do stockinette stitch and add and remove stitches in rows.  Below is the result.</p>
<div style="text-align:center;"><a href="http://www.flickr.com/photos/39013214@N03/4124326497" title="View 'iPhone Cosy MK I' on Flickr.com"><img border="0" width="500" alt="iPhone Cosy MK I" src="http://farm3.static.flickr.com/2794/4124326497_30ac381004.jpg" height="333"/></a></div>
<p>It has a couple of things I could improve on.  I put the cutout for the headphone cable on the wrong side and you have to take it out to charge.  The next one will have a button hole type slot in the bottom for the charging cable.</p>
<p>Knowing Purl has meant I can do ribbing so I&#8217;ve started knitting a ribbed scarf out of some great multicolour yarn.</p>
<div style="text-align:center;"><a href="http://www.flickr.com/photos/39013214@N03/4125097356" title="View 'Ribbed Scarf (WIP)' on Flickr.com"><img border="0" width="500" alt="Ribbed Scarf (WIP)" src="http://farm3.static.flickr.com/2509/4125097356_4077389a5e.jpg" height="333"/></a></div>
]]></content:encoded>
			<wfw:commentRss>http://www.cyberspice.org.uk/blog/2009/12/01/iphone-cosy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Building PHP C extensions on Ubuntu 9.10</title>
		<link>http://www.cyberspice.org.uk/blog/2009/12/01/building-php-c-extensions-on-ubuntu-9-10/</link>
		<comments>http://www.cyberspice.org.uk/blog/2009/12/01/building-php-c-extensions-on-ubuntu-9-10/#comments</comments>
		<pubDate>Tue, 01 Dec 2009 13:58:28 +0000</pubDate>
		<dc:creator>cyberspice</dc:creator>
				<category><![CDATA[Geek]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[PECL]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://www.cyberspice.org.uk/blog/?p=395</guid>
		<description><![CDATA[I have just taken over maintenance of the PECL Direct IO extension as it has been unmaintained for a while.  Naturally the first thing I did before writing any new code was to check out the extension from SVN and try and build it.  Building the source was fine but when I tried [...]]]></description>
			<content:encoded><![CDATA[<p>I have just taken over maintenance of the PECL Direct IO extension as it has been unmaintained for a while.  Naturally the first thing I did before writing any new code was to check out the extension from SVN and try and build it.  Building the source was fine but when I tried <em>make test</em> it failed producing output like the following:</p>
<pre>
PHP Warning:  PHP Startup: Unable to load dynamic library 'modules/gd.so' -
modules/gd.so: cannot open shared object file: No such file or
directory in Unknown on line 0

Warning: PHP Startup: Unable to load dynamic library 'modules/gd.so' -
modules/gd.so: cannot open shared object file: No such file or
directory in Unknown on line 0
</pre>
<p>The default PHP package on Ubuntu 9.10 is fairly minimalist.  Most extensions are provided as separate packages which include an INI file and a dynamic library.  The dynamic library is stored in:</p>
<pre>
/usr/lib/php5/20060613+lfs
</pre>
<p>And the INI file for each extension is in: </p>
<pre>
/etc/php5/conf.d.
</pre>
<p>The <em>make tests</em> rule in the generated Makefile in the extension you are compiling modifies the path that PHP searches for extensions by to point to the modules directory within the extension source.  So PHP, which is used to run the tests, cannot find the extensions.</p>
<p>I&#8217;ve found the easiest way (if slightly hacky) to fix the <em>make test</em> failure is just to copy the .so files from the PHP5 extension directory in to the modules directory within the extension source.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.cyberspice.org.uk/blog/2009/12/01/building-php-c-extensions-on-ubuntu-9-10/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
