Page 26 of 26 FirstFirst ... 1617181920212223242526
Results 251 to 260 of 260

Thread: ** NEW Fusion Brain Version 6, Pre-Order NOW **

  1. #251
    Fusion Brain Creator 2k1Toaster's Avatar
    Join Date
    Mar 2006
    Location
    Colorado, but Canadian!
    Posts
    10,049
    Here is snippet of code I have from one of my test applications. The FusionBrain_WinUSB.dll is the lower level that I use to communicate with.

    The major difference with the V6 is that you only send it what you want to happen. So it takes "commands" essentially. So the "code" variable below can be 0x01, 0x02, or 0x03. Generally you use 0x03. This code however makes 8 LEDs turn on moves them sequentially down the ports so all of them turn on but a block of 8 at a time. So when you send code 0x01, that means turn off every digital output except for those specified in the stream. If you send 0x02, that means turn on every digital output except for those specified in the stream. If you send 0x03, then it just means treat every word as its own thing. Length is how many bytes are in the stream total, and the port_i is which port to command.

    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using FusionBrain_WinUSB;
    
    namespace FusionBrain_BasicCom
    {
        class Program
        {
            static void Main(string[] args)
            {
                int dShift = -2;
                DateTime _prev;
                DateTime _now;
    
                MainUSBClass.FindAllFusionBrains();
                MainUSBClass.FusionBrainConnected += new USBMonitor.FusionBrain_HardwareMonitorEventDelegate(MainUSBClass_FusionBrainConnected);
                MainUSBClass.FusionBrainDisconnected += new USBMonitor.FusionBrain_HardwareMonitorEventDelegate(MainUSBClass_FusionBrainDisconnected);
    
                int port_i = 0;
                bool allOn = false;
                DateTime allOnTime = DateTime.Now;
                while (true)
                {
                    if (MainUSBClass.allFusionBrains.Count <= 0)
                    {
                        System.Threading.Thread.Sleep(100); 
                        continue;
                    }
                    System.Threading.Thread.Sleep(150);
    
                    byte[] _toSendArray = new byte[3];
                    port_i = port_i % 32;
    
                    if (DateTime.Now.Subtract(allOnTime).TotalSeconds >= 2)
                    {
                        allOnTime = DateTime.Now;
                        allOn = !allOn;
                    }
    
                    int _code = allOn ? 0x02 : 0x01; // 0x01: All off except..., 0x02: All on except..., 0x03: Normal
                    _code = 0x01;
                    int _length = 0;
                    _length = 8;
                    _toSendArray = new byte[1 + (_length * 2)];
                    _toSendArray[0] = (byte)((_code << 5) + _length);
                    for (int l = 0; l < _length; l++)
                    {
                        _toSendArray[(l * 2) + 1] = (byte) ((port_i + l) << 3);
                        _toSendArray[(l * 2) + 2] = 0xFF;
                    }
                    port_i++;
                    MainUSBClass.allFusionBrains[0].SendDataToFusionBrain(_toSendArray, 0x01);
    
                    byte[] _allDigitalOutputReadStates = new byte[64];
                    byte[] _allAnalogues = new byte[64];
                    MainUSBClass.allFusionBrains[0].ReadDataFromFusionBrain(ref _allDigitalOutputReadStates, 0x01);
                    MainUSBClass.allFusionBrains[0].ReadDataFromFusionBrain(ref _allAnalogues, 0x02);
    
                    List<double> aValues = new List<double>();
                    for(int a = 0; a < 15*2; a+=2)
                    {
                        int aValue_INT = ((_allAnalogues[a] & 0x03) << 8) + _allAnalogues[a + 1];
                        aValues.Add(3.3 * ((double)aValue_INT) / 1023.0);
                    }
    
                    foreach (double d in aValues)
                    {
                        Console.Write("{" + d.ToString("0.000") + "} ");
                    }
                    Console.WriteLine();
                }
            }
    
            static void MainUSBClass_FusionBrainDisconnected(USBMonitor.HardwareMonitorEventDetails _details)
            {
                _connected--;
                //throw new NotImplementedException();
            }
    
            static void MainUSBClass_FusionBrainConnected(USBMonitor.HardwareMonitorEventDetails _details)
            {
                _connected++;
                //throw new NotImplementedException();
            }
    
            private static double Parse_AnalogueInput(byte input_byte1, byte input_byte2)
            {
                int digital_value = 0;
                digital_value = (int)(input_byte1 * 256) + (int)input_byte2;
                double reF = ((double)digital_value / 1023.0f) * 5.0;
                return reF;
            }
        }
    }
    Fusion Brain Version 6 Released!
    1.9in x 2.9in -- 47mm x 73mm
    30 Digital Outputs -- Directly drive a relay
    15 Analogue Inputs -- Read sensors like temperature, light, distance, acceleration, and more
    Buy now in the MP3Car.com Store

  2. #252
    Newbie
    Join Date
    Dec 2007
    Location
    Orlando, FL
    Posts
    22
    I figured out how to query the input values and translate them into voltages. I also peeked at the Sensors.cs file that FuseGL generated and used it to output a fairly accurate temperature value from the temp sensor I have attached.

    Code:
                const byte endPoint = 0x02;
                
                for (int i = 0; i < 64; i++)
                {
                    m_rawData[i] = 0;
                }
    
                MainUSBClass.allFusionBrains[0].ReadDataFromFusionBrain(ref m_rawData, endPoint);
                string output = String.Empty;
    
                for (int itr = 0; itr < 15; itr++)
                {
                    int rawVal = (int)(((m_rawData[itr * 2] & 0x03) << 8) + m_rawData[itr * 2 + 1]);
                    m_Voltages[itr] = 3.3 * (rawVal / 1023.0);
                    output += String.Format("port [{0:D2}] voltage = [{1:F5}]\r\n", itr + 1, m_Voltages[itr]);
                }
    
                 // temp sensor is attached to pin 3
                 if (m_Voltages[2] > 0)
                {
                    int tempF = (int)Math.Floor((((m_Voltages[2] - 0.400) / 0.0195) * (9.0 / 5.0)) + 32.0);
                    tempSensorText.Text = String.Format("{0} F", tempF);
                }
    the input jitters occasionally, and sometimes the voltage on pin 3 drops to zero for a second or so. [that's what the if (m_Voltages[2] > 0) check is for]

    I also saw this in Sensors.cs:
    Code:
    public static double Initialize___TempSensor___Celcius(FB_Monitor.AnalogueInputPort _port, FuseGL_Variable _variable)
            {
                _port.AnalogueInputDataReceivedEvent += new FB_Monitor.AnalogueInputPort.AnalogueInputDataReceived((input_port) => { TempSensor___Celcius(input_port, _variable); });
                return TempSensor___Celcius(_port, _variable);
            }
    I am trying to figure out how to use the FB_Monitor class to just process analog input events when they're fired using the delegate function (like above)

    I am having trouble instantiating an AnalogueInputPort object. I figure this is roughly what is supposed to happen:

    Code:
                FB_Monitor fbm = new FB_Monitor();
                fbm.FusionBrainConnected += new FB_Monitor.FusionBrain_HardwareMonitorEventDelegate(fbm_FusionBrainConnected);
    
                FB_Monitor.AnalogueInputPort tempSensorPort;
    
                try
                {
                    tempSensorPort = fbm.AnalogueInput("tempSensor");
                    tempSensorPort.AnalogueInputDataReceivedEvent += new FB_Monitor.AnalogueInputPort.AnalogueInputDataReceived(tempSensorPort_AnalogueInputDataReceivedEvent);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message); // throws exception : "Analogue Input not in Correct Format"
                }
    so it throws an exception "Analogue Input not in Correct Format", and I am not sure what to pass in the details string to the FB_Monitor.AnalogueInput method.

    Do you have any documentation for using the FB_Monitor functionality? It seems like a more high level method for communicating with the FB6 and I would like to use that if possible.

    thanks so far for the help.

    "The most likely way for the world to be destroyed, most experts agree, is by accident. That's where we come in; we're computer professionals. We cause accidents." - Nathaniel Borenstein

  3. #253
    Fusion Brain Creator 2k1Toaster's Avatar
    Join Date
    Mar 2006
    Location
    Colorado, but Canadian!
    Posts
    10,049
    It's higher level but not meant to be used outside of FuseGL. You might get it to work, but it is not meant for that.

    The string is the port in "F:P" format where F is Fusion Brain Index and P is the port index. So "0:5" is FB[0] Port[5].

    Code:
    AnalogueInputPort _theAI = AnalogueInput(portString);
    Fusion Brain Version 6 Released!
    1.9in x 2.9in -- 47mm x 73mm
    30 Digital Outputs -- Directly drive a relay
    15 Analogue Inputs -- Read sensors like temperature, light, distance, acceleration, and more
    Buy now in the MP3Car.com Store

  4. #254
    Newbie
    Join Date
    Dec 2007
    Location
    Orlando, FL
    Posts
    22
    this:

    Code:
     FB_Monitor fbm = new FB_Monitor();
                fbm.FusionBrainConnected += new FB_Monitor.FusionBrain_HardwareMonitorEventDelegate(fbm_FusionBrainConnected);
    
                FB_Monitor.AnalogueInputPort tempSensorPort;
    
                try
                {
                    tempSensorPort = fbm.AnalogueInput("0:2");
                    tempSensorPort.AnalogueInputDataReceivedEvent += new FB_Monitor.AnalogueInputPort.AnalogueInputDataReceived(tempSensorPort_AnalogueInputDataReceivedEvent);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message); // throws exception : "Analogue Input not in Correct Format"
                }
    throws the same "Analogue input not in correct format" exception. If we're not supposed to use FB_Monitor and its high level functionality, i'll go back to polling all the inputs at once and build a manager class on top of it instead to abstract some of the low-levelness away.

    thanks for the help. I think I am going to be able to do a lot with the fusionbrain.

    "The most likely way for the world to be destroyed, most experts agree, is by accident. That's where we come in; we're computer professionals. We cause accidents." - Nathaniel Borenstein

  5. #255
    Fusion Brain Creator 2k1Toaster's Avatar
    Join Date
    Mar 2006
    Location
    Colorado, but Canadian!
    Posts
    10,049
    Quote Originally Posted by hellthorne View Post
    this:

    Code:
     FB_Monitor fbm = new FB_Monitor();
                fbm.FusionBrainConnected += new FB_Monitor.FusionBrain_HardwareMonitorEventDelegate(fbm_FusionBrainConnected);
    
                FB_Monitor.AnalogueInputPort tempSensorPort;
    
                try
                {
                    tempSensorPort = fbm.AnalogueInput("0:2");
                    tempSensorPort.AnalogueInputDataReceivedEvent += new FB_Monitor.AnalogueInputPort.AnalogueInputDataReceived(tempSensorPort_AnalogueInputDataReceivedEvent);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message); // throws exception : "Analogue Input not in Correct Format"
                }
    throws the same "Analogue input not in correct format" exception. If we're not supposed to use FB_Monitor and its high level functionality, i'll go back to polling all the inputs at once and build a manager class on top of it instead to abstract some of the low-levelness away.

    thanks for the help. I think I am going to be able to do a lot with the fusionbrain.
    Try

    Code:
    tempSensorPort = fbm.AnalogueInput("0.2");
    My code uses colons to the user code but then changes it internally to the dot.
    Fusion Brain Version 6 Released!
    1.9in x 2.9in -- 47mm x 73mm
    30 Digital Outputs -- Directly drive a relay
    15 Analogue Inputs -- Read sensors like temperature, light, distance, acceleration, and more
    Buy now in the MP3Car.com Store

  6. #256
    Constant Bitrate
    Join Date
    May 2006
    Posts
    116
    Looking at the XML http output and I think that it would make parsing much easier if the several tag names were terminated by a '>' and then terminated by a '</tagname> to replace the '/>'. If you would change this, it would make coding a lot more straight forward, please.

    So:
    <FuseGL_DynamicStatusXML>
    <creation_time time="19:32:03:4294" date="02-04-2013"/>
    <Analogue_Inputs>
    <analogue_input full_port="0.1" fb_index="0" port_index="1" current_voltage="0.9516"/>
    </Analogue_Inputs>
    <Digital_Outputs/>
    <All_Variables>
    <FuseGL_Variable name="autoVariable___[Sensor - Temperature in Fahrenheit[0,1] - TESTER01]" type="Double" is_persistant="True" current_value="82.9181141439206"/>
    </All_Variables>
    </FuseGL_DynamicStatusXML>


    Would look more like:
    <FuseGL_DynamicStatusXML>
    <creation_time> time="19:32:03:4294" date="02-04-2013"</creation_time>
    <Analogue_Inputs>
    <analogue_input> full_port="0.1" fb_index="0" port_index="1" current_voltage="0.9516"</analogue_input>
    </Analogue_Inputs>
    <Digital_Outputs/>
    <All_Variables>
    <FuseGL_Variable> name="autoVariable___[Sensor - Temperature in Fahrenheit[0,1] - TESTER01]" type="Double" is_persistant="True" current_value="82.9181141439206"</FuseGL_Variable>
    </All_Variables>
    </FuseGL_DynamicStatusXML>
    Last edited by waltersaegir; 04-02-2013 at 11:34 PM.

  7. #257
    Newbie
    Join Date
    Dec 2007
    Location
    Orlando, FL
    Posts
    22
    Quote Originally Posted by waltersaegir View Post
    Looking at the XML http output and I think that it would make parsing much easier if the several tag names were terminated by a '>' and then terminated by a '</tagname> to replace the '/>'. If you would change this, it would make coding a lot more straight forward, please.

    So:
    <FuseGL_DynamicStatusXML>
    <creation_time time="19:32:03:4294" date="02-04-2013"/>
    <Analogue_Inputs>
    <analogue_input full_port="0.1" fb_index="0" port_index="1" current_voltage="0.9516"/>
    </Analogue_Inputs>
    <Digital_Outputs/>
    <All_Variables>
    <FuseGL_Variable name="autoVariable___[Sensor - Temperature in Fahrenheit[0,1] - TESTER01]" type="Double" is_persistant="True" current_value="82.9181141439206"/>
    </All_Variables>
    </FuseGL_DynamicStatusXML>


    Would look more like:
    <FuseGL_DynamicStatusXML>
    <creation_time> time="19:32:03:4294" date="02-04-2013"</creation_time>
    <Analogue_Inputs>
    <analogue_input> full_port="0.1" fb_index="0" port_index="1" current_voltage="0.9516"</analogue_input>
    </Analogue_Inputs>
    <Digital_Outputs/>
    <All_Variables>
    <FuseGL_Variable> name="autoVariable___[Sensor - Temperature in Fahrenheit[0,1] - TESTER01]" type="Double" is_persistant="True" current_value="82.9181141439206"</FuseGL_Variable>
    </All_Variables>
    </FuseGL_DynamicStatusXML>

    this:
    Code:
    <creation_time> time="19:32:03:4294" date="02-04-2013"</creation_time>
    actually makes the xml data unparsable. you moved the data out of the element attributes and in to the inner text data. now it's one string "time=\"19:32:03:4294\" date=\"02-04-2013\""

    to make that work, you would need to do this instead:
    Code:
    <creation_time>
        <time>
            19:32:03:4294
        </time>
        <date>
            02-04-2013
        </date>
    </creation_time>
    but that just makes the xml clunky. the way the data is formatted now is actually xml compliant.
    It's really easy to parse the existing format like this:
    Code:
    // assumes you have an XmlDocument called "xml" that contains all of FuseGl_DynamicStatusXML:
    XmlNode creationTime = xml.GetElementByTagName("creation_time");
    String time = creationTime.Attributes["time"].Value;
    String date = creationTime.Attributes["date"].Value;

    parsing the analogue_input node is just as simple:
    Code:
    XmlNode analogueInput = xml.GetElementByTagName("analogue_input");
    float fullPort = analogueInput.Attributes["full_port"].Value;
    int index = analogueInput.Attributes["port_index"].Value;
    float currentVoltage = analogueInput.Attributes["current_voltage"].Value;
    (note, you might have to cast the values)

    "The most likely way for the world to be destroyed, most experts agree, is by accident. That's where we come in; we're computer professionals. We cause accidents." - Nathaniel Borenstein

  8. #258
    Newbie
    Join Date
    Dec 2007
    Location
    Orlando, FL
    Posts
    22
    Quote Originally Posted by 2k1Toaster View Post
    Try

    Code:
    tempSensorPort = fbm.AnalogueInput("0.2");
    My code uses colons to the user code but then changes it internally to the dot.
    now i get a different exception

    this code:
    Code:
                try
                {
                    tempSensorPort = fbm.AnalogueInput("0.2");
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message); // throws "Could not load type 'AnalogueInputInfoReceivedDelegate' from assembly 'FusionBrain_WinUSB, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b514c4b3aaee7aaf'.
    "
                }
    generates this exception
    Code:
    Step into: Stepping over non-user code 'FB_USB_2011.FB_Monitor.AnalogueInput'
    A first chance exception of type 'System.TypeLoadException' occurred in FB_USB_2011.dll
    'fbtestapp.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
    Could not load type 'AnalogueInputInfoReceivedDelegate' from assembly 'FusionBrain_WinUSB, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b514c4b3aaee7aaf'.
    i am still working on my manager class to abstract this since it looks like using FB_Monitor might be more trouble, but if you have any ideas, i'm all ears.

    "The most likely way for the world to be destroyed, most experts agree, is by accident. That's where we come in; we're computer professionals. We cause accidents." - Nathaniel Borenstein

  9. #259
    Constant Bitrate
    Join Date
    May 2006
    Posts
    116
    Quote Originally Posted by
    It's really easy to parse the existing format like this:
    [CODE
    // assumes you have an XmlDocument called "xml" that contains all of FuseGl_DynamicStatusXML:
    XmlNode creationTime = xml.GetElementByTagName("creation_time");
    String time = creationTime.Attributes["time"].Value;
    String date = creationTime.Attributes["date"].Value;
    [/CODE]

    parsing the analogue_input node is just as simple:
    Code:
    XmlNode analogueInput = xml.GetElementByTagName("analogue_input");
    float fullPort = analogueInput.Attributes["full_port"].Value;
    int index = analogueInput.Attributes["port_index"].Value;
    float currentVoltage = analogueInput.Attributes["current_voltage"].Value;
    (note, you might have to cast the values)
    Thanks for the suggestions. I'll play with your ideas and see if I can get the results that I'm looking-for!
    Last edited by waltersaegir; 04-03-2013 at 03:22 AM.

  10. #260
    Fusion Brain Creator 2k1Toaster's Avatar
    Join Date
    Mar 2006
    Location
    Colorado, but Canadian!
    Posts
    10,049
    Quote Originally Posted by waltersaegir View Post
    Thanks for the suggestions. I'll play with your ideas and see if I can get the results that I'm looking-for!
    Is there a reason you aren't using the built in XML parsers in pretty much every language? The output is XML compliant as it is and it should be a 1 or 2 line code solution to parse it unless you are using some microcontroller and assembly!
    Fusion Brain Version 6 Released!
    1.9in x 2.9in -- 47mm x 73mm
    30 Digital Outputs -- Directly drive a relay
    15 Analogue Inputs -- Read sensors like temperature, light, distance, acceleration, and more
    Buy now in the MP3Car.com Store

Similar Threads

  1. Fusion Brain V4 Digital Inputs
    By malcom2073 in forum Fusion Brain
    Replies: 0
    Last Post: 02-14-2009, 12:16 PM
  2. Replies: 41
    Last Post: 01-11-2009, 03:46 PM
  3. Fusion Brain and iBus
    By nemo1 in forum Fusion Brain
    Replies: 7
    Last Post: 12-15-2008, 11:05 AM
  4. Vista won't see the Fusion Brain
    By Ineffigy in forum Fusion Brain
    Replies: 6
    Last Post: 11-26-2008, 07:39 AM
  5. Fusion Brain and its uses!
    By HiJackZX1 in forum Fusion Brain
    Replies: 7
    Last Post: 06-08-2008, 07:41 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •