2024-07-11
한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina
효과: 클라이언트 또는 서버가 메시지를 보낼 때 직렬 포트 및 네트워크 포트 옆에 있는 패널이 깜박입니다. 데이터를 받거나 보낼 때 아래 텍스트 상자의 수가 증가합니다. 하트비트 메커니즘 라디오 버튼을 켜거나 끌 수 있습니다. 하트비트 간격과 내용을 설정할 수 있으며 재설정 버튼은 직렬 포트 데이터를 재설정하고 저장 버튼은 직렬 포트 데이터를 저장합니다(groupBox: 프롬프트 상자, 패널, 패널, 콤보 상자 드롭다운 상자, radioButton, 라디오 버튼, checkBox, 다중 선택 상자)
ini 파일:
Debug 경로에 파일을 생성하고 파일에 Setting.ini를 생성합니다.
구성 파일 읽기:
문자열 dirPath = Path.Combine(Application.StartupPath, "파일");
문자열 파일 경로 = Path.Combine(dirPath, "Setting.ini");
Ini = new IniHelper(파일 경로);
- 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;
-