2024-07-11
한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina
Effet : Le panneau à côté du port série et du port réseau clignote lorsque le client ou le serveur envoie un message. Le nombre de zones de texte ci-dessous augmente lors de la réception ou de l'envoi de données. Le bouton radio du mécanisme de battement de cœur peut être activé et désactivé, ainsi que le bouton radio. l'intervalle de battement de coeur peut être défini. et le contenu, le bouton de réinitialisation réinitialise les données du port série et le bouton Enregistrer enregistre les données du port série (groupBox : boîte d'invite, panneau, panneau, liste déroulante comboBox, radioButton, bouton radio, checkBox, boîte de sélection multiple)
fichier ini :
Créez un fichier dans le chemin Déboguer et créez Setting.ini dans le fichier
Lire le fichier de configuration :
chaîne dirPath = Path.Combine(Application.StartupPath, "Fichier");
chaîne filePath = Path.Combine(dirPath, "Setting.ini");
Ini = nouveau IniHelper(chemin_fichier);
- 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;
-