﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>RoboticsConnection User Forum / RoboticsConnection Software Support / Serializer .NET Library  / Trouble accessing CMPS03 via I2CGeneric / Latest Posts</title><generator>InstantForum.NET v4.1.4</generator><description>RoboticsConnection User Forum</description><link>http://www.roboticsconnection.com/userForums/</link><webMaster>info@roboticsconnection.com</webMaster><lastBuildDate>Thu, 04 Dec 2008 12:51:27 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Trouble accessing CMPS03 via I2CGeneric</title><link>http://www.roboticsconnection.com/userForums/Topic260-6-1.aspx</link><description>Cool!  That works!&lt;/P&gt;&lt;P&gt;I was using the '&amp;lt;&amp;lt;' shift operator t shift each sequential bit to the left, to convert the bytes into an int.&lt;/P&gt;&lt;P&gt;I didn't have time to compile it and debug it, and typed it at almost 1:00am. :)&lt;/P&gt;&lt;P&gt;Also, now that you have the updated firmware, you should be getting spaces between the values, instead of the '\r'.&lt;/P&gt;&lt;P&gt;Best Regards!</description><pubDate>Sat, 29 Mar 2008 13:40:55 GMT</pubDate><dc:creator>jsummerour</dc:creator></item><item><title>RE: Trouble accessing CMPS03 via I2CGeneric</title><link>http://www.roboticsconnection.com/userForums/Topic260-6-1.aspx</link><description>UPDATE:  I updated the firmware in the Serializer and it started working.  Guess I should have thought of that one first ...  :)</description><pubDate>Fri, 28 Mar 2008 21:05:20 GMT</pubDate><dc:creator>cjohns</dc:creator></item><item><title>RE: Trouble accessing CMPS03 via I2CGeneric</title><link>http://www.roboticsconnection.com/userForums/Topic260-6-1.aspx</link><description>Jason,&lt;/P&gt;&lt;P&gt;Thanks for quick response.  Had some trouble with the code, so I started stepping through it.  First problem seems to be that rather than strReadings getting "255 255" as your code assumed, it was actually pulling the value "255/r/n255r/n".  So before I could do the Split(' '), I had to do a replace  &lt;/P&gt;&lt;P&gt;readings.Replace("\r", " ");&lt;/P&gt;&lt;P&gt;With that taken care of, it now gets stuck on the line:&lt;/P&gt;&lt;FONT color=#0000ff size=2&gt;&lt;P&gt;int&lt;/FONT&gt;&lt;FONT color=#000000 size=2&gt; part = &lt;/FONT&gt;&lt;FONT color=#2b91af size=2&gt;Convert&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;FONT color=#000000&gt;.ToByte(r) &amp;lt;&amp;lt; (pos*1);&lt;/FONT&gt;&lt;/P&gt;&lt;/FONT&gt;&lt;P&gt;&lt;FONT size=2&gt;&lt;FONT color=#008000&gt;&lt;/FONT&gt;The runtime error it gives (which occurs the first time it hits this line) is "Input string was not in the correct format".&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size=2&gt;Since I am not entirely sure what you are doing on this row, I'm not sure how to debug it.  I'm not too familiar with the &amp;lt;&amp;lt; operator, although I just finished reading a little about it on MSDN.  And I am not sure why you would multiply pos by 1, that wouldn't ever do anything would it?&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size=2&gt;However, that problem aside, I'm thinking there is a bug in the I2CDevice class when it comes to reading the I2C registers.  I just compiled and ran your example code for the I2CDevice [url]http://www.roboticsconnection.com/multimedia/libraries/MSDNDocumentation/[/url] (modifying only the COM port, BaudRate, and the I2CAddress to the TPA81 so it would fully run on my system), and it too read only "255" off the compass sensor and 255 for all registers of the TPA81 as well.  (Both these sensors work fine when read from their respective CMPS03 and TPA81 classes).&lt;/FONT&gt;</description><pubDate>Fri, 28 Mar 2008 16:16:49 GMT</pubDate><dc:creator>cjohns</dc:creator></item><item><title>RE: Trouble accessing CMPS03 via I2CGeneric</title><link>http://www.roboticsconnection.com/userForums/Topic260-6-1.aspx</link><description>Try something like this...&lt;FONT color=#0000ff&gt;&lt;FONT color=#0000ff&gt;&lt;P&gt;&lt;FONT color=#0000ff&gt;private&lt;/FONT&gt; &lt;FONT color=#0000ff&gt;void&lt;/FONT&gt; ReadHighResCompassRegister()&lt;BR&gt;{&lt;BR&gt;    i2cd.Write(0xC0, &lt;FONT color=#a31515&gt;"2"&lt;/FONT&gt;);                      &lt;FONT color=#008000&gt;// Start reading at register 2&lt;BR&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;    string&lt;/FONT&gt; reading = i2cd.Read(0xC0, &lt;FONT color=#a31515&gt;"2"&lt;/FONT&gt;); &lt;FONT color=#008000&gt;// Read registers/bytes 2 and 3&lt;BR&gt;&lt;/FONT&gt;&lt;FONT color=#008000&gt;    // Bytes returned are separated by spaces:&lt;BR&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;    string&lt;/FONT&gt; [] readings = reading.Split(&lt;FONT color=#a31515&gt;' '&lt;/FONT&gt;);&lt;BR&gt;&lt;FONT color=#0000ff&gt;    int&lt;/FONT&gt; pos = 0;&lt;BR&gt;&lt;FONT color=#0000ff&gt;    int&lt;/FONT&gt; heading = 0;&lt;BR&gt;&lt;FONT color=#008000&gt;    // Convert bytes to word:&lt;BR&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;    foreach&lt;/FONT&gt; (&lt;FONT color=#0000ff&gt;string&lt;/FONT&gt; r &lt;FONT color=#0000ff&gt;in&lt;/FONT&gt; readings)&lt;BR&gt;    {&lt;BR&gt;&lt;FONT color=#008000&gt;        // There's probably a simpler way to do this...&lt;BR&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff&gt;        int&lt;/FONT&gt; part = &lt;FONT color=#2b91af&gt;Convert&lt;/FONT&gt;.ToByte(r) &amp;lt;&amp;lt; (pos * 1);&lt;BR&gt;        heading = heading | part;&lt;BR&gt;    }&lt;BR&gt;&lt;BR&gt;    lblCompass.Text = heading.ToString();&lt;BR&gt;}&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;Best Regards!&lt;/FONT&gt;</description><pubDate>Thu, 27 Mar 2008 20:48:43 GMT</pubDate><dc:creator>jsummerour</dc:creator></item><item><title>Trouble accessing CMPS03 via I2CGeneric</title><link>http://www.roboticsconnection.com/userForums/Topic260-6-1.aspx</link><description>I attempted to roughly follow the example for the I2CDevice accessing CMPS03 compass, posted at:&lt;BR&gt;&lt;A href="http://www.roboticsconnection.com/multimedia/libraries/MSDNDocumentation/_23n15r2ti.htm"&gt;http://www.roboticsconnection.com/multimedia/libraries/MSDNDocumentation/_23n15r2ti.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;The main difference being that I am doing it from a Windows Forms not Console.  Here is what I coded, which is not working (always returns "255").  [FYI, my compass is working fine using Serializer.NET class CMPS03, so its not a hardware issue].  Let me know if you see anything wrong here ...&lt;/P&gt;&lt;P&gt;[Declaration]:&lt;BR&gt;private static I2CDevice i2cd;&lt;/P&gt;&lt;P&gt;&lt;BR&gt;[Form_Load]:&lt;BR&gt;i2c = new I2CDevice(serializer)&lt;BR&gt;i2cd.I2CAddress = 0xC0;&lt;BR&gt;i2cd.ReadCommand = "1";&lt;BR&gt;i2cd.WriteCommand = "1";&lt;BR&gt;//I notice there is no i2cd.Update() like I would normally use for CMPS03 class?&lt;/P&gt;&lt;P&gt;[Periodic_Timer_Tick]:&lt;BR&gt;serializer.PumpEvents();&lt;BR&gt;i2cd.Write();&lt;BR&gt;lblCompass.Text = i2cd.Read().ToString();    //always posts 255 to my label</description><pubDate>Thu, 27 Mar 2008 17:21:25 GMT</pubDate><dc:creator>cjohns</dc:creator></item></channel></rss>