Esempio n. 1
0
        public Form1()
        {
            InitializeComponent();
            // Initialize the serial port list
            IntPtr lpCount    = Marshal.AllocCoTaskMem(sizeof(uint));
            IntPtr lpPortList = UserNativeFunction.SerialPort_Proc(SPM_GETPORTNAMES, lpCount, IntPtr.Zero);
            int    count      = Marshal.ReadInt32(lpCount);

            if (count != 0)
            {
                IntPtr com = lpPortList;
                for (uint i = 0; i < count; i++)
                {
                    cb_serialport.Items.Add(Marshal.PtrToStringAuto(Marshal.ReadIntPtr(com)));
                    com = (IntPtr)(com.ToInt64() + Marshal.SizeOf(com));
                }
                cb_serialport.SelectedItem = 0;
            }
        }
Esempio n. 2
0
        public Main()
        {
            InitializeComponent();
            BTN_CLOSE_SERIAL_PORT.Enabled = false;
            // Initialize the serial port list
            IntPtr lpCount    = Marshal.AllocCoTaskMem(sizeof(uint));
            IntPtr lpPortList = UserNativeFunction.SerialPort_Proc(SPM_GETPORTNAMES, lpCount, IntPtr.Zero);
            int    count      = Marshal.ReadInt32(lpCount);

            if (count != 0)
            {
                IntPtr com = lpPortList;
                for (uint i = 0; i < count; i++)
                {
                    CB_CHOSE_SERIAL_PORT.Items.Add(Marshal.PtrToStringAuto(Marshal.ReadIntPtr(com)));
                    com = (IntPtr)(com.ToInt64() + Marshal.SizeOf(com));
                }
                CB_CHOSE_SERIAL_PORT.SelectedItem = 0;
            }
            op.Height = tabPage1.Height;
            op.Width  = tabPage1.Width - 210;
            op.Show();
        }