C#的SerialPort使用,动态创建串口连接,短信猫通信
2010-07-19 11:11
573 查看
using System;
using System.Collections.Generic;
using System.Text;
using System.IO.Ports;
/// <summary>
/// 启动短信猫服务
/// </summary>
/// <param name="baudRate">波特率</param>
/// <returns>0;串口初始化成功;-1:串口初始化失败</returns>
public int initPorts(int baudRate)
{
string[] portList = System.IO.Ports.SerialPort.GetPortNames(); //系统串口字符串集合
foreach (string port in portList)
{
SerialPort newPort = new SerialPort();
newPort.PortName = port;
newPort.BaudRate = baudRate;
newPort.ReadTimeout = 600;
newPort.WriteTimeout = 600;
newPort.ReceivedBytesThreshold = 10; //接收缓冲区有10字节以上的数据时才触发回调事件
newPort.Handshake = Handshake.RequestToSend; //设置通信双方的握手协议
//串口监听器,监听收到的数据,ReceiveMessage为一个回调函数
// newPort.DataReceived += new SerialDataReceivedEventHandler(ReceiveMessage);
this.RegPorts.Add(newPort);
newPort.Open();
}
return 0;
}
using System.Collections.Generic;
using System.Text;
using System.IO.Ports;
/// <summary>
/// 启动短信猫服务
/// </summary>
/// <param name="baudRate">波特率</param>
/// <returns>0;串口初始化成功;-1:串口初始化失败</returns>
public int initPorts(int baudRate)
{
string[] portList = System.IO.Ports.SerialPort.GetPortNames(); //系统串口字符串集合
foreach (string port in portList)
{
SerialPort newPort = new SerialPort();
newPort.PortName = port;
newPort.BaudRate = baudRate;
newPort.ReadTimeout = 600;
newPort.WriteTimeout = 600;
newPort.ReceivedBytesThreshold = 10; //接收缓冲区有10字节以上的数据时才触发回调事件
newPort.Handshake = Handshake.RequestToSend; //设置通信双方的握手协议
//串口监听器,监听收到的数据,ReceiveMessage为一个回调函数
// newPort.DataReceived += new SerialDataReceivedEventHandler(ReceiveMessage);
this.RegPorts.Add(newPort);
newPort.Open();
}
return 0;
}
相关文章推荐
- c# SerialPort控件串口通信
- C# SerialPort控件串口通信
- c# SerialPort控件串口通信
- C# serialPort 串口接收中this.Invoke的使用
- [收藏]使用VMWare串口连接Windbg 官方文档说明 Examples: Debugging over a Virtual Serial Port
- [收藏]使用VMWare串口连接Windbg 官方文档说明 Examples: Debugging over a Virtual Serial Port
- c# SerialPort控件串口通信
- serialPort基本属性与使用(串口)——C#
- [.Net码农]C#动态创建和动态使用程序集、类、方法、字段等(二)
- C语言PIC32 serial bootloader和C#语言bootloader PC端串口通信程序
- c#中serialPort1_DataReceived串口接收事件处理
- C#串口采集短信GSM chart图表使用示例 保存数据到access数据库和每日.txt文件并实时显示各参数曲线
- C#serial Port串口处理~
- 使用CSerialPort类编写串口通信程序的问题
- 创建C#串口通信程序详解
- C#中使用委托创建事件实现两个窗体间通信
- 怎样使用C# 制作串口连接软件
- QT 使用串口类出现“undefined reference to QSerialPort::QSerialPort(QObject*)错误
- AE+C#如何创建和使用.sde连接
- C# Serialport(小插头) 控件 与 axMSComm(小电话)上传COM口 重量信息的使用