BTool.DeviceForm.DeviceFormInit C# (CSharp) Method

DeviceFormInit() public method

public DeviceFormInit ( ) : bool
return bool
        public bool DeviceFormInit()
        {
            bool flag = false;
            if (commSelectForm.ShowDialog() == DialogResult.OK)
            {
                commMgr.PortName = commSelectForm.cbPorts.Text;
                commMgr.BaudRate = commSelectForm.cbBaud.Text;
                commMgr.DataBits = commSelectForm.cbDataBits.Text;
                commMgr.Parity = commSelectForm.cbParity.Text;
                commMgr.StopBits = commSelectForm.cbStopBits.Text;
                commMgr.HandShake = (Handshake)commSelectForm.cbFlow.SelectedIndex;
                commMgr.CurrentTransmissionType = CommManager.TransmissionType.Hex;
                commMgr.DisplayMsgCallback = new DisplayMsgDelegate(DisplayMsg);

                if (commMgr.OpenPort())
                {
                    Text = commSelectForm.cbPorts.Text;

                    devInfo.DevName = commMgr.PortName;
                    devInfo.ConnectStatus = "None";
                    devInfo.ComPortInfo.BaudRate = commMgr.BaudRate;
                    devInfo.ComPortInfo.ComPort = commMgr.PortName;
                    devInfo.ComPortInfo.Flow = commSelectForm.cbFlow.Text;
                    devInfo.ComPortInfo.DataBits = commMgr.DataBits;
                    devInfo.ComPortInfo.Parity = commMgr.Parity;
                    devInfo.ComPortInfo.StopBits = commMgr.StopBits;

                    commMgr.RxDataInd = new CommManager.FP_ReceiveDataInd(RxDataHandler);

                    processRxProc = new Thread(new ThreadStart(ProcessRxProc));
                    processRxProc.Name = "ProcessRxProcThread";
                    processRxProc.Start();
                    while (!processRxProc.IsAlive)
                    { }
                    flag = true;
                }
                else
                {
                    string msg = string.Format("Failed Connecting To {0}\n", commSelectForm.cbPorts.SelectedItem);
                    msgBox.UserMsgBox(SharedObjects.MainWin, MsgBox.MsgTypes.Error, msg);
                    DisplayMsg(SharedAppObjs.MsgType.Error, msg);
                }
            }
            return flag;
        }

Usage Example

Example #1
0
        private void AddDeviceForm()
        {
            if (InvokeRequired)
            {
                try
                {
                    Invoke((Delegate)new AddDeviceFormDelegate(AddDeviceForm));
                }
                catch { }
            }
            else
            {
                m_mutex.WaitOne();
                DeviceForm deviceForm = new DeviceForm();
                if (deviceForm == null)
                    return;
                deviceForm.BDAddressNotify += new EventHandler(DeviceBDAddressNotify);
                deviceForm.ConnectionNotify += new EventHandler(DeviceConnectionNotify);
                deviceForm.DisconnectionNotify += new EventHandler(DeviceDisconnectionNotify);
                deviceForm.ChangeActiveRoot += new EventHandler(DeviceChangeActiveRoot);
                deviceForm.CloseActiveDevice += new EventHandler(DeviceCloseActiveDevice);

                if (deviceForm.DeviceFormInit())
                {
                    deviceForm.TopLevel = false;
                    deviceForm.Parent = plDevice;
                    deviceForm.Dock = DockStyle.Fill;
                    foreach (Control control in plDevice.Controls)
                    {
                        if (control.GetType().BaseType == typeof(Form))
                        {
                            Form form = (Form)control;
                            if (form.Visible)
                            {
                                form.Hide();
                                break;
                            }
                        }
                    }
                    deviceForm.Show();
                    AddToTreeDeviceInfo(deviceForm.devInfo, deviceForm);
                    comPortTreeForm.ClearSelectedNode();
                    deviceForm.SendGAPDeviceInit();
                }
                else
                    deviceForm.DeviceFormClose(false);

                m_mutex.ReleaseMutex();
            }
        }