using System;
|
using System.Drawing;
|
using System.Collections;
|
using System.ComponentModel;
|
using System.Data;
|
using System.Text;
|
using System.IO;
|
using System.Diagnostics;
|
using System.IO.Ports;
|
|
namespace TProduct.Common
|
{
|
//COM端口
|
public class ComPortHelper
|
{
|
public ComPortHelper() { }
|
|
//波特率列表
|
public Int32[] BaudRatesList = {
|
100,300,600,1200,2400,4800,9600,14400,19200,
|
38400,56000,57600,115200,128000,256000
|
};
|
|
|
|
//设置当前电脑有哪个串口可用的Combox控件
|
//public static bool InitialDispContrl(System.Windows.Forms.ComboBox ctrl)
|
//{
|
// ctrl.Items.AddRange(System.IO.Ports.SerialPort.GetPortNames());
|
// if (ctrl.Items.Count == 0)
|
// {
|
// MessageBox.Show("没有COM端口");
|
// return false;
|
// }
|
// ctrl.SelectedIndex = 0;
|
// return true;
|
//}
|
|
//public static bool InitialDispContrl(DevExpress.XtraEditors.ComboBoxEdit ctrl)
|
//{
|
// ctrl.Properties.Items.AddRange(System.IO.Ports.SerialPort.GetPortNames());
|
// if (ctrl.Properties.Items.Count == 0)
|
// {
|
// MessageBox.Show("没有COM端口");
|
// return false;
|
// }
|
// ctrl.SelectedIndex = 0;
|
// return true;
|
//}
|
//public static bool InitialDispContrl(DevExpress.XtraEditors.ComboBoxEdit ctrl,string defaultComName)
|
//{
|
// var list = System.IO.Ports.SerialPort.GetPortNames();
|
// if (list == null || list.Length == 0)
|
// {
|
// MessageBox.Show("没有COM端口");
|
// return false;
|
// }
|
// ctrl.Properties.Items.AddRange(list);
|
// if (ctrl.Properties.Items.Count == 0)
|
// {
|
// MessageBox.Show("没有COM端口");
|
// return false;
|
// }
|
// if (string.IsNullOrEmpty(defaultComName))
|
// {
|
// ctrl.SelectedIndex = 0;
|
// return true;
|
// }
|
// for (int i = 0; i < list.Length; i++)
|
// {
|
// if (list[i] == defaultComName)
|
// {
|
// ctrl.SelectedIndex = i;
|
// return true;
|
// }
|
// }
|
// ctrl.SelectedIndex = 0;
|
// return true;
|
//}
|
|
public static string[] GetPortNames()
|
{
|
return System.IO.Ports.SerialPort.GetPortNames();
|
}
|
|
|
}
|
}
|