Page 21 of 33 FirstFirst ... 111213141516171819202122232425262728293031 ... LastLast
Results 201 to 210 of 328

Thread: Fusion Brain Version 6 -- Beta Testing

  1. #201
    Fusion Brain Creator 2k1Toaster's Avatar
    Join Date
    Mar 2006
    Location
    Colorado, but Canadian!
    Posts
    10,049
    Quote Originally Posted by rEegLer View Post
    No timer needed?
    That is a whenever it changes, change it back type code:

    Code:
            public object KeepOutputOn(FB_Monitor.DigitalOutputPort _port)
            {
                _port.Value = 255;
                _port.DigitalOutputStateChangedEvent += delegate(FB_Monitor.DigitalOutputPort event_port)
                                                            {
                                                                if (_port.Value != 255)
                                                                {
                                                                    _port.Value = 255;
                                                                }
                                                            };
                return null;
            }
    This is a just change it every so often even if it is already what you want it to be code:
    Code:
            public object KeepOutputOnWithTimer(FB_Monitor.DigitalOutputPort _port, int how_often_in_milliseconds)
            {
                _port.Value = 255;
                System.Timers.Timer _timer = new System.Timers.Timer();
                _timer.AutoReset = true;
                _timer.Interval = how_often_in_milliseconds;
                _timer.Elapsed += delegate(object sender, System.Timers.ElapsedEventArgs e)
                                      {
                                          _port.Value = 255;
                                      };
                _timer.Start();
                return null;
            }
    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. #202
    Variable Bitrate rEegLer's Avatar
    Join Date
    Jul 2008
    Location
    Mechanicsburg, PA
    Posts
    266
    The first code chuck did not work but the second timer function works great! Thanks! I appreciate your customer service
    Love

  3. #203
    Variable Bitrate rEegLer's Avatar
    Join Date
    Jul 2008
    Location
    Mechanicsburg, PA
    Posts
    266
    You (2k1Toaster) already probably know this but for others, to make a momentary button, I used this C# code:

    Code:
    using System;
    using System.Collections.Generic;
    using System.Threading;
    using FB_USB_2011;
    using FuseGL.GUI.Text;
    using FuseGL.Logic;
    
    namespace Momentary_Output_NS   
    {
        class Momentary_Output_Class
        {
            public object Momentary_Output(FB_Monitor.DigitalOutputPort _port, int how_often_in_milliseconds)
            {
                _port.Value = 255;
                Thread.Sleep(how_often_in_milliseconds);
                _port.Value = 0;
                return null;
            }
        }
    }
    There may be a better way to do it but this works fine for me.

    Then, in the events of the button, I have this little bit:

    Code:
    <onMouseDown action="FuseGL.ExecuteCode" inputArgs="Logic/Momentary_Output.cs;Momentary_Output_NS.Momentary_Output_Class;Momentary_Output;{FB.DigitalOutput(0.0)};{(int)1000};" />
    Love

  4. #204
    Fusion Brain Creator 2k1Toaster's Avatar
    Join Date
    Mar 2006
    Location
    Colorado, but Canadian!
    Posts
    10,049
    Glad it is working for you.

    I do recommend you install Visual Studio 2010 C# Express. It is a free download from Microsoft (requires you to register with a Windows Live account 60 or 90 days after installation to continue using for free, but before that free).

    It has intellisense which is my most favourite thing on the entire planet. You can just start typing and it will automatically popup what it thinks you mean. So you can type "_" and everything that starts with "_" will show up like "_port" in the above example. It will tell you what type it is, what it is (local or global variable or parameter or whatever). Then when you press "." after "_port" it will show you everything you can use and you can browse through the list to find one that is what you are thinking of. It is basically how I learned to code. Just wandering through lists of intellisense options.
    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

  5. #205
    Variable Bitrate rEegLer's Avatar
    Join Date
    Jul 2008
    Location
    Mechanicsburg, PA
    Posts
    266
    That's what I'm using. It's a Godsend for Visual Basic.

    Researching it a bit more, would it be better to use a timer rather than a sleep function because everything does pause while it's 'sleeping'?
    Love

  6. #206
    Fusion Brain Creator 2k1Toaster's Avatar
    Join Date
    Mar 2006
    Location
    Colorado, but Canadian!
    Posts
    10,049
    Quote Originally Posted by rEegLer View Post
    You (2k1Toaster) already probably know this but for others, to make a momentary button, I used this C# code:

    Code:
    using System;
    using System.Collections.Generic;
    using System.Threading;
    using FB_USB_2011;
    using FuseGL.GUI.Text;
    using FuseGL.Logic;
    
    namespace Momentary_Output_NS   
    {
        class Momentary_Output_Class
        {
            public object Momentary_Output(FB_Monitor.DigitalOutputPort _port, int how_often_in_milliseconds)
            {
                _port.Value = 255;
                Thread.Sleep(how_often_in_milliseconds);
                _port.Value = 0;
                return null;
            }
        }
    }
    There may be a better way to do it but this works fine for me.

    Then, in the events of the button, I have this little bit:

    Code:
    <onMouseDown action="FuseGL.ExecuteCode" inputArgs="Logic/Momentary_Output.cs;Momentary_Output_NS.Momentary_Output_Class;Momentary_Output;{FB.DigitalOutput(0.0)};{(int)1000};" />
    That will work, but I caution you on threads. You do not want to suspend (sleep) a user interaction thread. It makes it look like it is freezing. I do not think I multithreaded these external files, so you are running on the same thread as the rest of the program. So when you say "System.Threading.Thread.Sleep(10000)", the entire program will freeze for 10 seconds. No GUI updates, no log updates, no FB communication, nothing.

    You are much better off using events and a timer since that seems to be our favourite threading object.

    Something like this:

    Code:
        class Momentary_Output_Class
        {
            public object Momentary_Output_using_events_that_wont_freeze_the_program(FB_Monitor.DigitalOutputPort _port, int how_long_to_keep_on_in_milliseconds)
            {
                _port.Value = 255;
                System.Timers.Timer _turnOffTimer = new System.Timers.Timer(how_long_to_keep_on_in_milliseconds);
                _turnOffTimer.AutoReset = false; // Notice you DO NOT want it constantly firing...
                _turnOffTimer.Elapsed += delegate(object sender, System.Timers.ElapsedEventArgs e)
                                             {
                                                 _port.Value = 0;
                                             };
                _turnOffTimer.Start();
                return null;
            }
        }
    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

  7. #207
    Fusion Brain Creator 2k1Toaster's Avatar
    Join Date
    Mar 2006
    Location
    Colorado, but Canadian!
    Posts
    10,049
    Quote Originally Posted by rEegLer View Post
    That's what I'm using. It's a Godsend for Visual Basic.

    Researching it a bit more, would it be better to use a timer rather than a sleep function because everything does pause while it's 'sleeping'?
    Indeed. See above.
    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

  8. #208
    Variable Bitrate rEegLer's Avatar
    Join Date
    Jul 2008
    Location
    Mechanicsburg, PA
    Posts
    266
    Again, for the use of others mostly, here is my code for my Steering Wheel controls:

    Code:
    using System;
    using System.Collections.Generic;
    using FB_USB_2011;
    using FuseGL.GUI.Text;
    using FuseGL.Logic;
    using System.Windows.Forms;
    
    namespace FuseGL_doOnAnalogue
    {
        class ShowMessageBoxWithValue
        {
            Dictionary<FB_Monitor.AnalogueInputPort, System.Timers.Timer> allAnaloguePortsToDisplay = new Dictionary<FB_Monitor.AnalogueInputPort, System.Timers.Timer>();
    
            public ShowMessageBoxWithValue()
            {
                
            }
    
            public object RegisterAnalogueInput(FB_Monitor.AnalogueInputPort _port, int how_often_in_milliseconds, object[] extraInputParams)
            {
                if (allAnaloguePortsToDisplay.ContainsKey(_port)) { return true; }
    
                System.Timers.Timer _timer = new System.Timers.Timer();
                _timer.AutoReset = true;
                _timer.Interval = how_often_in_milliseconds;
                _timer.Elapsed += delegate(object sender, System.Timers.ElapsedEventArgs e)
                {
                    if (_port.Port == 1)
                    {
                        if (_port.Value < 0.802)
                        {
                            
                        }
                        else if(_port.Value < 1.183)
                        {
                            FuseGL_AvailableLogic.PressKey('1');
                        }
                        else if (_port.Value < 1.417)
                        {
                            FuseGL_AvailableLogic.PressKey('2');
                        }
                        else if (_port.Value < 1.579)
                        {
                            FuseGL_AvailableLogic.PressKey('3');
                        }
                        else if (_port.Value < 2.030)
                        {
                            FuseGL_AvailableLogic.PressKey('4');
                        }
                        else if (_port.Value < 2.100)
                        {
                            FuseGL_AvailableLogic.PressKey('5');
                        }
                        else if (_port.Value < 2.504)
                        {
                            FuseGL_AvailableLogic.PressKey('6');
                        }
                        else if (_port.Value < 2.681)
                        {
                            FuseGL_AvailableLogic.PressKey('7');
                        }
                        else if (_port.Value < 2.952)
                        {
                            FuseGL_AvailableLogic.PressKey('8');
                        }
                    }
                };
                _timer.Start();
                return true;
            }
        }
    }
    A little bit different then what you posted as an example in that it needed the else if statements instead of just if statements.

    Is there a way to press Numpad numbers instead of just normal numeric numbers? I remember in MDX that this was possible. I believe I tried 'NUM8' instead of '8' and it didn't work. Just curious, not a big deal over all.
    Love

  9. #209
    Fusion Brain Creator 2k1Toaster's Avatar
    Join Date
    Mar 2006
    Location
    Colorado, but Canadian!
    Posts
    10,049
    Get the update then you can use "PressKey_KeyCode" instead of "PressKey". Pass it an integer value {(int)whatever} where whatever is the microsoft virtual keycode value (my implementation listed below for ease).

    Code:
    public enum VirtualKeyCode : ushort
        {
            LBUTTON = 1,
            RBUTTON = 2,
            CANCEL = 3,
            MBUTTON = 4,
            XBUTTON1 = 5,
            XBUTTON2 = 6,
            BACK = 8,
            TAB = 9,
            CLEAR = 12,
            RETURN = 13,
            SHIFT = 16,
            CONTROL = 17,
            MENU = 18,
            PAUSE = 19,
            CAPITAL = 20,
            HANGEUL = 21,
            HANGUL = 21,
            KANA = 21,
            JUNJA = 23,
            FINAL = 24,
            HANJA = 25,
            KANJI = 25,
            ESCAPE = 27,
            CONVERT = 28,
            NONCONVERT = 29,
            ACCEPT = 30,
            MODECHANGE = 31,
            SPACE = 32,
            PRIOR = 33,
            NEXT = 34,
            END = 35,
            HOME = 36,
            LEFT = 37,
            UP = 38,
            RIGHT = 39,
            DOWN = 40,
            SELECT = 41,
            PRINT = 42,
            EXECUTE = 43,
            SNAPSHOT = 44,
            INSERT = 45,
            DELETE = 46,
            HELP = 47,
            VK_0 = 48,
            VK_1 = 49,
            VK_2 = 50,
            VK_3 = 51,
            VK_4 = 52,
            VK_5 = 53,
            VK_6 = 54,
            VK_7 = 55,
            VK_8 = 56,
            VK_9 = 57,
            VK_A = 65,
            VK_B = 66,
            VK_C = 67,
            VK_D = 68,
            VK_E = 69,
            VK_F = 70,
            VK_G = 71,
            VK_H = 72,
            VK_I = 73,
            VK_J = 74,
            VK_K = 75,
            VK_L = 76,
            VK_M = 77,
            VK_N = 78,
            VK_O = 79,
            VK_P = 80,
            VK_Q = 81,
            VK_R = 82,
            VK_S = 83,
            VK_T = 84,
            VK_U = 85,
            VK_V = 86,
            VK_W = 87,
            VK_X = 88,
            VK_Y = 89,
            VK_Z = 90,
            LWIN = 91,
            RWIN = 92,
            APPS = 93,
            SLEEP = 95,
            NUMPAD0 = 96,
            NUMPAD1 = 97,
            NUMPAD2 = 98,
            NUMPAD3 = 99,
            NUMPAD4 = 100,
            NUMPAD5 = 101,
            NUMPAD6 = 102,
            NUMPAD7 = 103,
            NUMPAD8 = 104,
            NUMPAD9 = 105,
            MULTIPLY = 106,
            ADD = 107,
            SEPARATOR = 108,
            SUBTRACT = 109,
            DECIMAL = 110,
            DIVIDE = 111,
            F1 = 112,
            F2 = 113,
            F3 = 114,
            F4 = 115,
            F5 = 116,
            F6 = 117,
            F7 = 118,
            F8 = 119,
            F9 = 120,
            F10 = 121,
            F11 = 122,
            F12 = 123,
            F13 = 124,
            F14 = 125,
            F15 = 126,
            F16 = 127,
            F17 = 128,
            F18 = 129,
            F19 = 130,
            F20 = 131,
            F21 = 132,
            F22 = 133,
            F23 = 134,
            F24 = 135,
            NUMLOCK = 144,
            SCROLL = 145,
            LSHIFT = 160,
            RSHIFT = 161,
            LCONTROL = 162,
            RCONTROL = 163,
            LMENU = 164,
            RMENU = 165,
            BROWSER_BACK = 166,
            BROWSER_FORWARD = 167,
            BROWSER_REFRESH = 168,
            BROWSER_STOP = 169,
            BROWSER_SEARCH = 170,
            BROWSER_FAVORITES = 171,
            BROWSER_HOME = 172,
            VOLUME_MUTE = 173,
            VOLUME_DOWN = 174,
            VOLUME_UP = 175,
            MEDIA_NEXT_TRACK = 176,
            MEDIA_PREV_TRACK = 177,
            MEDIA_STOP = 178,
            MEDIA_PLAY_PAUSE = 179,
            LAUNCH_MAIL = 180,
            LAUNCH_MEDIA_SELECT = 181,
            LAUNCH_APP1 = 182,
            LAUNCH_APP2 = 183,
            OEM_1 = 186,
            OEM_PLUS = 187,
            OEM_COMMA = 188,
            OEM_MINUS = 189,
            OEM_PERIOD = 190,
            OEM_2 = 191,
            OEM_3 = 192,
            OEM_4 = 219,
            OEM_5 = 220,
            OEM_6 = 221,
            OEM_7 = 222,
            OEM_8 = 223,
            OEM_102 = 226,
            PROCESSKEY = 229,
            PACKET = 231,
            ATTN = 246,
            CRSEL = 247,
            EXSEL = 248,
            EREOF = 249,
            PLAY = 250,
            ZOOM = 251,
            NONAME = 252,
            PA1 = 253,
            OEM_CLEAR = 254,
        }
    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

  10. #210
    Variable Bitrate rEegLer's Avatar
    Join Date
    Jul 2008
    Location
    Mechanicsburg, PA
    Posts
    266
    Yup. Works great! Thanks.
    Love

Similar Threads

  1. ** NEW Fusion Brain Version 6, Pre-Order NOW **
    By 2k1Toaster in forum Fusion Brain
    Replies: 259
    Last Post: 04-07-2013, 03:48 PM
  2. Fusion Brain version 4
    By MattFreitag in forum Fusion Brain
    Replies: 7
    Last Post: 08-01-2010, 05:32 PM
  3. Fusion Brain -- Digital Encoder Beta Test
    By 2k1Toaster in forum Fusion Brain
    Replies: 52
    Last Post: 09-18-2009, 03:11 PM
  4. Fusion Brain Version 4 Manual
    By greenman100 in forum FB Documentation and Tutorials
    Replies: 0
    Last Post: 12-19-2008, 03:11 PM
  5. Fusion Brain Version 4 ready for Beta Testers!
    By greenman100 in forum Fusion Brain
    Replies: 15
    Last Post: 11-13-2008, 11:21 PM

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
  •