2024-07-11
한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina
効果: クライアントまたはサーバーがメッセージを送信すると、シリアル ポートとネットワーク ポートの横のパネルが点滅します。ハートビート メカニズムのラジオ ボタンをオンまたはオフにすると、下のテキスト ボックスの数が増加します。ハートビート間隔と内容を設定できます。リセット ボタンはシリアル ポート データをリセットし、保存ボタンはシリアル ポート データを保存します (グループ ボックス: プロンプト ボックス、パネル、パネル、コンボ ボックス ドロップダウン ボックス、ラジオ ボタン、ラジオ ボタン、チェック ボックス、複数選択ボックス)
ini ファイル:
デバッグパスにファイルを作成し、ファイルにSetting.iniを作成します
構成ファイルを読み取ります:
文字列 dirPath = Path.Combine(Application.StartupPath, "File");
文字列 filePath = Path.Combine(dirPath, "Setting.ini");
Ini = 新しい 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;
-