コード例 #1
0
        // Maybe this should be used in ArduinoCommunicationException to describe the error, in addition to the text descriptions:
        // public enum COMMERROR { VALID = 0, NULL, INVALID, UNVALIDATED, TIMEOUT, PORTBUSY, INVALIDINPUT, PORTERROR, OTHER };

        // The constructor
        public ArduinoBoard(ManagementBaseObject device)
        {
            Console.WriteLine("Creating a new arduino device (in constructor now)");
            _ExpectedResponseCancellation = new CancellationTokenSource();
            mgmtBaseObj        = device;
            Port               = new SerialPort(SerialInterface.GetPortName(device));
            Port.DataReceived += arduinoBoard_DataReceived;

            vid  = SerialInterface.GetVID(device);
            pid  = SerialInterface.GetPID(device);
            type = SerialInterface.GetArduinoType(vid, pid);

            _PackageName        = "NULL";            // to be found
            _ReceivedTwoWayData = new List <byte>();

            _TestDuration = 0;
            _StartDelay   = 0;
            _SamplePeriod = 0;

            _TestStarted = false;

            _ReceivedBytes = new List <byte>();

            // Serial communications use the Windows-1252 (code page 1252) character set.
            Port.Encoding = Encoding.GetEncoding(1252); // Used to use: Encoding.GetEncoding(28591);
        }
コード例 #2
0
ファイル: ArduinoSync.cs プロジェクト: messmerd/GCC_LCA
 // For creating or accessing the single instance of this class
 public static SerialInterface Create()
 {
     if (singleton == null)
     {
         singleton = new SerialInterface();
     }
     return(singleton);
 }
コード例 #3
0
ファイル: Program.cs プロジェクト: messmerd/GCC_LCA
        private static void Application_ApplicationExit(object sender, EventArgs e)
        {
            // This event handler is meant to fix the weird problem with the PnP watcher staying active even after the program closes.
            // There are a few methods similar to this one throughout the code for this program. One of them works and
            // the rest probably don't do anything, but I haven't taken the time see which ones are useless and remove them.

            if (SerialInterface.Create().pnpWatcher != null)
            {
                SerialInterface.Create().pnpWatcher.Stop();
                SerialInterface.Create().pnpWatcher.Dispose();
            }

            // Maybe this fixes the PnP event problem...
            if (Application.MessageLoop)
            {
                // WinForms app
                Application.Exit();
            }
            else
            {
                // Console app
                System.Environment.Exit(1);
            }
        }
コード例 #4
0
ファイル: Form1.cs プロジェクト: messmerd/GCC_LCA
        private string UserDefaultLanguage          = "en";         // The language the user chose to use as a default (not implemented yet)

        // The constructor. This sets up most of what this program does.
        public Main()
        {
            AppDomain currentDomain = AppDomain.CurrentDomain;

            currentDomain.UnhandledException += new UnhandledExceptionEventHandler(Main_UnhandledException);

            // Create the SerialInterface object
            serial = SerialInterface.Create();

            // Subscribe to some events:
            FormClosing               += Main_FormClosing; // Might not be needed anymore
            serial.ArduinoChanged     += Serial_ArduinoChanged;
            serial.ArduinoDataChanged += Serial_ArduinoDataChanged;

            InitializeComponent();

            // Unfocus controls as necessary when the user clicks any of these controls:
            this.MouseDown              += UnfocusControls;
            tabControl.MouseDown        += UnfocusControls;
            menuStrip1.MouseDown        += UnfocusControls;
            StatusPage.MouseDown        += UnfocusControls;
            ConfigPage.MouseDown        += UnfocusControls;
            SensorsPage.MouseDown       += UnfocusControls;
            DataPage.MouseDown          += UnfocusControls;
            panelStartDelay.MouseDown   += UnfocusControls;
            labelConfigSec2.MouseDown   += UnfocusControls;
            labelConfigSec.MouseDown    += UnfocusControls;
            labelConfigMin.MouseDown    += UnfocusControls;
            labelConfigHr.MouseDown     += UnfocusControls;
            labelPackageName.MouseDown  += UnfocusControls;
            labelSamplePeriod.MouseDown += UnfocusControls;
            labelTestDuration.MouseDown += UnfocusControls;
            labelStartDelay.MouseDown   += UnfocusControls;

            // Config Page setup:
            checkBoxSyncTimeDate.Tag                       = false; // Unchecked by default
            textBoxPackageName.TextChanged                += TextBoxPackageName_TextChanged;
            numericUpDownSamplePeriod.ValueChanged        += NumericUpDownSampleRate_ValueChanged;
            numericUpDownTestDurationHours.ValueChanged   += NumericUpDownTestDuration_ValueChanged;
            numericUpDownTestDurationMinutes.ValueChanged += NumericUpDownTestDuration_ValueChanged;
            numericUpDownTestDurationSeconds.ValueChanged += NumericUpDownTestDuration_ValueChanged;
            radioButtonStartDelayNone.CheckedChanged      += RadioButtonStartDelayOption_CheckedChanged;
            radioButtonStartDelayOneMin.CheckedChanged    += RadioButtonStartDelayOption_CheckedChanged;
            radioButtonStartDelayThreeMin.CheckedChanged  += RadioButtonStartDelayOption_CheckedChanged;

            // Languages setup:
            imageComboLanguage.DropDownClosed       += imageComboLanguage_DropDownClosed; // To unhighlight the selection
            imageComboLanguage.KeyDown              += imageComboLanguage_KeyDown;
            imageComboLanguage.SelectedIndexChanged += imageComboLanguage_SelectedIndexChanged;
            LanguageText            = new Dictionary <string, string>();
            AvailableLanguages      = new SortedSet <string>();
            LanguageIcons           = new ImageList();
            LanguageIcons.ImageSize = new Size(imageComboLanguage.ImageList.ImageSize.Height, imageComboLanguage.ImageList.ImageSize.Height);
            CurrentLanguage         = "";
            LoadLanguages();

            Console.WriteLine("\n\n\n");

            // Arduino List setup:
            deviceList = new object[] { "<No Device>" };  // This doesn't work!
            //arduinoList.Items.AddRange(deviceList);
            arduinoListBinding              = new BindingSource();
            arduinoListBinding.DataSource   = serial.LCAArduinos;
            arduinoListBinding.ListChanged += Serial_LCAArduinos_Changed;
            arduinoList.DataSource          = arduinoListBinding;
            arduinoList.DisplayMember       = "displayName";

            // Start watching for USB PnP (Plug and Play) devices to be added/removed/modified:
            serial.StartPnPWatcher();

            // Find LCA Arduinos (our sensor array Arduinos):
            serial.ActivateAllArduinos();

            RefreshControlsEnable();
        }