2024-07-11
한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina
Efeito: O painel próximo à porta serial e à porta de rede piscará quando o cliente ou servidor enviar uma mensagem. A caixa de texto abaixo aumentará em número ao receber ou enviar dados. O botão de opção do mecanismo de pulsação pode ser ativado e desativado. o intervalo de pulsação pode ser definido e o conteúdo, o botão reset redefine os dados da porta serial e o botão salvar salva os dados da porta serial (groupBox: caixa de prompt, painel, painel, caixa suspensa comboBox, radioButton, botão de opção, checkBox, caixa de seleção múltipla)
arquivo ini:
Crie um arquivo no caminho Debug e crie Setting.ini no arquivo
Leia o arquivo de configuração:
string dirPath = Path.Combine(Application.StartupPath, "Arquivo");
string filePath = Path.Combine(dirPath, "Setting.ini");
Ini = novo IniHelper(filePath);
- namespace SerialportToTCP
- {
- public partial class Form1 : Form
- {
- IniHelper Ini;
- string[] botelvs = new string[] { "1200", "4800", "9600", "13200" };
- public Form1()
- {
- InitializeComponent();
-
- //1 读取配置文件
- string dirPath = Path.Combine(Application.StartupPath, "File");// debug/file
- string filePath = Path.Combine(dirPath, "Setting.ini");// debug / file/setting.ini
- Ini = new IniHelper(filePath); //创建读取对象
-
- // 添加串口
- comboBox1.Items.AddRange(SerialPort.GetPortNames());// 获取所有串口 拼接在下拉框的items中
- comboBox2.Items.AddRange(botelvs);// 添加波特率数组
- comboBox2.Items.Add("自定义");//添加一个
- comboBox3.Items.AddRange(new string[] { "5", "6", "7", "8" });
- comboBox4.Items.AddRange(new string[] { "无", "奇校检", "偶校检" });
- comboBox5.Items.AddRange(new string[] { "无", "1", "2", "1.5" });
-
-
- //2开始处理串口接受数据事件
- //处理串口的数据
- this.serialPort1.DataReceived = SerialPort1_DataReceived;
-
- //3 处理界面显示默认值 也就是从ini文件读取数据
- readSetting();
-
- //4 开始串口通信
- startChuanKou();
-
- //5 开始网口通信
- startTCP();
-
-
- }
- //开始搭建TCP服务器
- TcpListener listen;
-