看驱动程序的接口啊
一般是是open(“口名”)
用C/C++写一扒游个小程序读取串口接收到贺此销的数据你太幸运了,刚好我有一个,你在禅游vc++6.0下测试一下。
/* serrecv.c */
/* Receives and saves a file over a serial port */
/* Last modified: Septemeber 21, 2005 */
/* [goman89] */
#include
#include
#include
/* Function to print out usage information */
void usage(void)
/* Function to set up the serial port settings with the specified baud rate,
no parity, and one stop bit */
void set_up_serial_port(HANDLE h, long baud)
/* Function to receive and save file from serial port */
void get_file_from_serial_port(HANDLE h, char *file_name, unsigned long file_length)
int main(int argc, char **argv)
{
HANDLE serial_port/* Handle to the serial port */
long baud_rate = 9600/* Baud rate */
char port_name[] = "COM1:"/* Name of serial port */
unsigned long file_size/* Size of file to receive in bytes */
unsigned long bytes_received/* Bytes received from serial port */
unsigned long file_name_size/* Size of file name in bytes */
char file_name[256]/* Name of file to receive */
/* Check mand line */
if (argc == 3)
{
/* Read in baud rate */
if (argv[1][1] != 'b' || sscanf(argv[2], "%ld", &baud_rate) != 1)
{
usage
exit(0)
}
}
else if (argc != 1)
{
usage
exit(0)
}
/* Open up a handle to the serial port */
serial_port = CreateFile(port_name, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0)
/* Make sure port was opened */
if (serial_port == INVALID_HANDLE_VALUE)
{
fprintf(stderr, "Error opening port\n")
CloseHandle(serial_port)
exit(0)
}
/* Set up the serial port */
set_up_serial_port(serial_port, baud_rate)
/* Receive file name size from serial port */
ReadFile(serial_port, (void *)&file_name_size, sizeof(unsigned long), &bytes_received, NULL)
if (bytes_received != sizeof(unsigned long))
{
fprintf(stderr, "Error getting file name size.\n")
CloseHandle(serial_port)
exit(0)
}
/* Receive file name from serial port */
ReadFile(serial_port, (void *)file_name, file_name_size, &bytes_received, NULL)
if (bytes_received != file_name_size)
{
fprintf(stderr, "Error retrieving file name.\n")
CloseHandle(serial_port)
exit(0)
}
/* Append NULL terminator to end of string */
file_name[bytes_received] = '\0'
/* Receive file size from serial port */
ReadFile(serial_port, (void *)&file_size, sizeof(unsigned long), &bytes_received, NULL)
if (bytes_received != sizeof(unsigned long))
{
fprintf(stderr, "Error getting file size.\n")
CloseHandle(serial_port)
exit(0)
}
/* Get the file from the serial port */
get_file_from_serial_port(serial_port, file_name, file_size)
/* Print out success information */
printf("\n%lu bytes successfully received and saved as %s\n", file_size, file_name)
/* Close handle */
CloseHandle(serial_port)
return 0
}
void usage(void)
{
fprintf(stderr, "Usage:\n")
fprintf(stderr, "\tserrecv [-b baud rate]\n")
fprintf(stderr, "\tDefault baud rate is 9600\n")
fprintf(stderr, "tSupported baud rates: 1200, 2400, 4800, 9600, 14400, 19200\n")
return
}
void set_up_serial_port(HANDLE h, long baud)
{
DCB properties/* Properties of serial port */
/* Get the properties */
GetmState(h, &properties)
/* Set the baud rate */
switch(baud)
{
case 1200:
properties.BaudRate = CBR_1200
break
case 2400:
properties.BaudRate = CBR_2400
break
case 4800:
properties.BaudRate = CBR_4800
break
case 9600:
properties.BaudRate = CBR_9600
break
case 14400:
properties.BaudRate = CBR_14400
break
case 19200:
properties.BaudRate = CBR_19200
break
case 38400:
properties.BaudRate = CBR_38400
break
default:
fprintf(stderr, "Invalid baud rate: %ld\n", baud)
usage
exit(0)
break
}
/* Set the other properties */
properties.Parity = NOPARITY
properties.ByteSize = 8
properties.StopBits = ONESTOPBIT
SetmState(h, &properties)
return
}
void get_file_from_serial_port(HANDLE h, char *file_name, unsigned long file_length)
{
FILE *data_file/* File to create */
unsigned long bytes_left = file_length/* Bytes left to receive */
unsigned long bytes_received_total = 0/* Total bytes received */
unsigned long bytes_to_receive/* Number of bytes to receive */
unsigned long bytes_received/* Number of bytes receive */
char buffer[200]/* Buffer to store data */
/* Open the file */
data_file = fopen(file_name, "wb")
/* Quit if file couldn't be opened */
if (data_file == NULL)
{
fprintf(stderr, "Could not create file %s\n", file_name)
CloseHandle(h)
exit(0)
}
while (1)
{
/* Determine how many bytes to read */
if (bytes_left == 0)
{
break
}
else if (bytes_left <200)
{
bytes_to_receive = bytes_left
}
else
{
bytes_to_receive = 200
}
/* Receive data over serial cable */
ReadFile(h, (void *)buffer, bytes_to_receive, &bytes_received, NULL)
if (bytes_received != bytes_to_receive)
{
fprintf(stderr, "Error reading file.\n")
CloseHandle(h)
exit(0)
}
/* Save buffer to file */
fwrite((void *)buffer, 1, bytes_received, data_file)
/* Decrement number of bytes left */
bytes_left -= bytes_received
/* Increment number of bytes received */
bytes_received_total += bytes_received
/* Print out progress */
printf("\r%5lu bytes received.", bytes_received_total)
}
fclose(data_file)
return
}
C语言变成实现串口收发数据#include
#include
int main(void)
{
FILE *fp
char temp
char buf[100]
if((fp = fopen("3","r")) == NULL)
puts("this way doesn't work!\n")
else
puts("this way works!\n")
while(1)
{
temp = 0
fscanf(fp,"%c",&temp)
if(temp != 0)
putchar(temp)
else
Sleep(100)
}
fclose(fp)
return 0
}
以前弄的,好久没看了,不知到对不对。
还有下面这段:
#include
#include
HANDLE h
int main(void)
{
h=CreateFile(TEXT("COM3"),//COM1口
GENERIC_READ|GENERIC_WRITE, //允许读和写
0, //独方式
NULL,
OPEN_EXISTING, //打开而不是创建
0, //同步方式
NULL)
if(h==(HANDLE)-1)
{
printf("打开COM失败!\n")
return FALSE
}
else
{
printf("COM打开成功!\n")
}
Setupm(h,1024,1024) //输入缓冲区和输出缓冲区大小都是1024
COMMTIMEOUTS TimeOuts
//设读超时
TimeOuts.ReadIntervalTimeout=1000
TimeOuts.ReadTotalTimeoutMultiplier=500
TimeOuts.ReadTotalTimeoutConstant=5000
//设定写超时
TimeOuts.WriteTotalTimeoutMultiplier=500
TimeOuts.WriteTotalTimeoutConstant=2000
SetmTimeouts(h,&TimeOuts) //设置超时
DCB dcb
GetmState(h,&dcb)
dcb.BaudRate=9600 //波特率为9600
dcb.ByteSize=8 //每个字节有8位
dcb.Parity=NOPARITY //无奇偶校验位
dcb.StopBits=ONE5STOPBITS //两个停止位
SetmState(h,&dcb)
DWORD wCount//读取的节数
BOOL bReadStat
while(1)
{
Purgem(h,PURGE_TXCLEAR|PURGE_RXCLEAR) //清缓冲区
char str[9]={0}
printf("%s\n",str)
bReadStat=ReadFile(h,str,9,&wCount,NULL)
if(!bReadStat)
{
printf("
怎么通过串口读取51单片机某个地址的数据?请用C语言写出来。*
授人以鱼,不如授人以渔
*
首先,你要明确在C语中读取内存址是基于指针。
3.比如读取内存地址0x22中的数据
C语言中对于内存的访是基于指,这个毋庸置疑,具体 *** 如下
unsigned int *p= (unsigned int*)0x22 ;//定义针,并且使指针指向了0x22这个 内存地址;
那么*p就是最终你要读取的数据了。
4.至于如何通过串口显示到电脑我就不多了(这不是难点),据你都知道了,写到串口 缓冲区,在串口调试助手下就可以看到。
5.虽然没有贴出具体代码,但这里面的思想可以让你解决
标签:作文经典 上一篇:描写毛毛虫的词语 描写毛毛虫行动的词语 下一篇:成语误用褒贬的例子 褒贬误用的成语Linux下如何使用c/c++实现检测新增串口,并读取串口号
Linux下面有设文件
串口装好驱动后 会显示在dev下
然后对这个
C语言中如何对串口进行 *** 作C语言会有 *** 作串口的库函数的,按照串口库数标识实现调
电脑上的串口号是什么意思串口叫做串行接口,也串行通信接口,按电气标准及协议来分包括RS-232-C、RS-422、RS485、USB等。 RS-232-C、RS-422与RS-485标准对接口的电气特性做出规定,不涉及接插件、电缆或协议。USB是近几年发展起来的新型接口标准,主要应用于速数据传输域。 RS-232-C:也称标准串口,是目前最常用的一种串行通讯接口。它是在1970年由美国电子工业协会(EIA)联合贝尔系统、 调制解调器厂家及计算机终端生产厂共同制定的用于串行通讯的标 准。它的名是“数据终端设备(DTE)和数据通讯设备(DCE)之间 行二进制数据交换接口技术标准”。传统的RS-232-C接口标准有22根线,采用标准25芯D型插头座。后来的PC上使用简化了的9芯D插座。现在应用中25芯插头已很少采用。现在的电脑般有两个串行口:COM1和COM2,你到计算机后面能看到9针D形接口就是了。现在有很多手数据线或者物流接收器都采用COM
如何用C语言写一个读、写串口的程序?大致过程就是
配置串口通信,包串口号、波特、验位、停止位这些信息;
打开串口,和打开文件一样,在Linux是这样,Windows下没试过,估计也差不多;
发送数据,即写串口,就跟写文件类似;
读取
编写单片机串口收发数据的完整程序(C语言编写)我用的新唐芯片,8051内核,跟51差不多,望采纳
void UART_Initial (void)
{
P02_Quasi_Mode//Setting UART pin as Quasi mode for tran *** it
P16_Quasi_Mode//Setting UART pin as Quasi mode for tran *** it
SCON_1 = 0x50//UART1 Mode1,REN_1=1,TI_1=1
T3CON = 0x08//T3PS2=0,T3PS1=0,T3PS0=0(Prescale=1), UART1 in MODE 1
clr_BRCK
RH3 = HIBYTE(65536 - (1000000/u32Baudrate)-1)/*16 MHz */
RL3 = LOBYTE(65536 - (1000000/u32Baudrate)-1)/*16 MHz */
set_TR3//Trigger Timer3
}
以上是初始化的
void Send_Data_To_UART1(UINT8 c)
{
TI_1 = 0
SBUF_1 = c
while(TI_1==0)
}
这个是发送
void UART_isr (void) interrupt 4 //
怎样在WINDOWS下用C语言编写串口接收数据程序#include
#include
int main(void)
{
FILE *fp
char temp
char buf[100]
if((fp = fopen("3","r")) == NULL)
puts("this way doesn't work!\n")
else
puts("this way works!\n")
while(1)
{
temp = 0
fscanf(fp,"%c",&temp)
if(temp != 0)
putchar(temp)
else
Sleep(100)
}
fclose(fp)
return 0
}
以前的,好久看,不知到对不对。
还下面这段:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include
#include
HANDLE h
int main(void)
{
h=CreateFile(TEXT("COM3"),//COM1口
GENERIC_READ|GENERIC_WRITE, //允许读和写
0, //独占方式
NULL,
OPEN_EXISTING, //打开而不是建
0, //同步式
NULL)
if(h==(HANDLE)-1)
{
printf("打开COM失败!\n")
return FALSE
}
else
{
printf("COM打开成功!\n")
}
Setupm(h,1024,1024)//输入缓冲区和输出缓冲区的大小都是1024
COMMTIMEOUTS TimeOuts
//定读超时
TimeOuts.ReadIntervalTimeout=1000
TimeOuts.ReadTotalTimeoutMultiplier=500
TimeOuts.ReadTotalTimeoutConstant=5000
//设定写超时
TimeOuts.WriteTotalTimeoutMultiplier=500
TimeOuts.WriteTotalTimeoutConstant=2000
SetmTimeouts(h,&TimeOuts)//设置超时
DCB dcb
GetmState(h,&dcb)
dcb.BaudRate=9600//波特率为9600
dcb.ByteSize=8//每个字节有8位
dcb.Parity=NOPARITY//无奇偶校验位
dcb.StopBits=ONE5STOPBITS//两个停止位
SetmState(h,&dcb)
DWORD wCount//读取的字节
BOOL bReadStat
while(1)
{
Purgem(h,PURGE_TXCLEAR|PURGE_RXCLEAR)//清空缓冲区
char str[9]={0}
printf("%s\n",str)
bReadStat=ReadFile(h,str,9,&wCount,NULL)
if(!bReadStat)
{
printf("读串口
标签:作文经典 上一篇:描写毛毛虫的词语 描写毛毛虫行动的词语 下一篇:成语误用褒贬的例子 褒贬误用的成语C#串口读写搭物段程序方法知誉具体如下:
PortDataSend.cs 发送蚂返Class
using System
using System.Collections.Generic
using System.Text
namespace IOCPTest.BaseC
...{
public class PortDataSend
...{
Declare#region Declare
private long mCount = 0
private int mDataLength = 0
private byte[] BS = null
#endregion Declare
PortDataSend#region PortDataSend
public PortDataSend()
...{
}
public PortDataSend(byte[] pBS, int pDataLength)
...{
BS = pBS
mDataLength = pDataLength
}
#endregion PortDataSend
DataSend#region DataSend
public void DataSend()
...{
try
...{
if (BS == null)
...{
return
}
if (mDataLength == 0)
...{
mDataLength = BS.Length
}
if (mDataLength == 0)
...{
return
}
mDataLength = mDataLength + 2
byte[] BST = new byte[mDataLength]
BST[BST.Length - 2] = 0x00
BST[BST.Length - 1] = 0x03
for (int i = 0i <BS.Lengthi++)
...{
BST[i] = BS[i]
BST[BST.Length - 2] = (byte)(BST[BST.Length - 2] ^ BS[i])
}
IOCPTest.BaseC.GlobeValues.SP.Write(BST, 0, BST.Length)
mCount++
mDataLength = 0
}
catch
...{
}
}
#endregion DataSend
mCount#region mCount
public long GetCount
...{
get
...{
return mCount
}
}
#endregion mCount
DataSendTest3#region DataSendTest3
public void DataSendTest3()
...{
try
...{
byte[] BSTest
string[] mBSStr = Convert.ToString("01 02 03 01 00 3A 02 03 31 31 31 31 31 31 31 31 31 31 31 31 2C 00 01 2C 00 64 3B 32 32 32 32 32 32 32 32 32 32 32 32 2C 00 01 2C 00 64 3B 33 33 33 33 33 33 33 33 33 33 33 33 2C 00 01 2C 00 64 3B").Split(' ')
BSTest = new byte[mBSStr.Length]
for (int i = 0i <BSTest.Lengthi++)
...{
BSTest[i] = (byte)Convert.ToInt32(mBSStr[i], 16)
}
BS = BSTest
DataSend()
}
catch
...{
}
}
#endregion DataSendTest3
}
}
PortDataReceived.cs 接收Class
using System
using System.Collections.Generic
using System.Text
namespace IOCPTest.BaseC
...{
class PortDataReceived
...{
Declare#region Declare
private long mCount = 0
private int mDataEnd = 0
private byte[] BR = new byte[2048]
private byte[] BRTmp = new byte[2048]
private byte mSOH = 0x01 //通讯特殊字符定义:通讯字头
private byte mSTX = 0x02 //通讯特殊字符定义:数据开始
private byte mETX = 0x03 //通讯特殊字符定义:通讯结束
#endregion Declare
PortDataReceived#region PortDataReceived
public PortDataReceived()
...{
}
#endregion PortDataReceived
Listen#region Listen
public byte[] Listen()
...{
try
...{
byte[] BR = ReceiveData()
return BR
}
catch (NullReferenceException NullEx)
...{
throw NullEx
}
catch (Exception ex)
...{
throw ex
}
}
#endregion Listen
ReceiveData#region ReceiveData
public byte[] ReceiveData()
...{
try
...{
int mStartCount = 0
int mSOHPos = 0
int mSTXPos = 0
int mETXPos = 0
int mCmdLength = 0
System.DateTime DT = System.DateTime.Now
byte[] Data = null
BRTmp = new byte[2048]
while((System.DateTime.Now.Ticks - DT.Ticks) <IOCPTest.BaseC.GlobeValues.PortTimeOut)
...{
try
...{
mStartCount = 0
//System.Threading.Thread.Sleep(IOCPTest.BaseC.GlobeValues.PortDelay)
mStartCount = IOCPTest.BaseC.GlobeValues.SP.Read(BRTmp, 0, 2048)
for (int i = 0i <mStartCounti++)
...{
BR[i + mDataEnd] = BRTmp[i]
}
mDataEnd = mDataEnd + mStartCount
}
catch
...{
}
if (mStartCount >0)
...{
DT = System.DateTime.Now
}
//寻找并且校验SOH、STX、ETX的位置
for (int i = 0i <BR.Length - 6i++)
...{
if((BR[i] == mSOH) &&(BR[i+6] == mSTX))
...{
mSOHPos = i
mSTXPos = i+6
mCmdLength = (int)BR[i+4] * 256 + (int)BR[i+5]
mETXPos = mSTXPos + mCmdLength + 2
if (BR[mETXPos] == mETX)
...{
Data = new byte[mSTXPos + mCmdLength + 1 - mSOHPos]
for (int j = 0j <mSTXPos + mCmdLength + 1 - mSOHPosj++)
...{
Data[j] = BR[mSOHPos + j]
}
for (int j = 0j <(mDataEnd - (mSTXPos + mCmdLength + 1))j++)
...{
BR[j] = BR[(mSTXPos + mCmdLength + 1) + j]
}
for (int j = (mDataEnd - (mSTXPos + mCmdLength + 1))j <2048j++)
...{
BR[j] = 0x00
}
mDataEnd = mDataEnd - (mSTXPos + mCmdLength + 1)
IOCPTest.BaseC.GlobeValues.DataBuffer.Add(Data)
mCount++
return Data
}
}
}
}
return null
}
catch (NullReferenceException NullEx)
...{
throw NullEx
}
catch (Exception ex)
...{
throw ex
}
}
#endregion ReceiveData
ReceiveDataNonReturn#region ReceiveDataNonReturn
public void ReceiveDataNonReturn()
...{
try
...{
ReceiveData()
}
catch
...{
}
}
#endregion ReceiveData
ReceiveDataThread#region ReceiveDataThread
public void ReceiveDataThread()
...{
try
...{
while (true)
...{
try
...{
ReceiveData()
}
catch
...{
}
}
}
catch
...{
}
}
#endregion ReceiveData
mCount#region mCount
public long GetCount
...{
get
...{
return mCount
}
}
#endregion mCount
}
}
DataProcessingIOCP.cs 处理Class
using System
using System.Collections.Generic
using System.Text
namespace IOCPTest.BaseC
...{
public class DataProcessingIOCP
...{
Declare#region Declare
private long mCount = 0
#endregion Declare
DataProcessingIOCP#region DataProcessingIOCP
public DataProcessingIOCP()
...{
}
#endregion DataProcessingIOCP
DataProcessing#region DataProcessing
public void DataProcessing()
...{
try
...{
int mCurrentBuffer = 0
while (true)
...{
byte[] RD = null
提取正待处理的数据#region 提取正待处理的数据
if (IOCPTest.BaseC.GlobeValues.DataBuffer != null)
...{
if (IOCPTest.BaseC.GlobeValues.DataBuffer.Count >0)
...{
if (mCurrentBuffer <0)
...{
mCurrentBuffer = 0
}
RD = (byte[])IOCPTest.BaseC.GlobeValues.DataBuffer[mCurrentBuffer]
mCurrentBuffer++
}
else
...{
continue
}
}
else
...{
continue
}
#endregion 提取正待处理的数据
数据处理#region 数据处理
switch (RD[3]) //指令处理
...{
case 0x01:
ReadData_0X01(RD)
break
case 0x02:
ReadData_0X02(RD)
break
}
#endregion 数据处理
处理结束,删除已经处理了的数据#region 处理结束,删除已经处理了的数据
if (IOCPTest.BaseC.GlobeValues.DataBuffer != null)
...{
if (IOCPTest.BaseC.GlobeValues.DataBuffer.Count >0)
...{
IOCPTest.BaseC.GlobeValues.DataBuffer.Remove(RD)
}
}
mCurrentBuffer--
if (mCurrentBuffer <0)
...{
mCurrentBuffer = 0
}
#endregion 处理结束,删除已经处理了的数据
mCount++
}
}
catch
...{
}
}
#endregion DataProcessing
mCount#region mCount
public long GetCount
...{
get
...{
return mCount
}
}
#endregion mCount
ReadData_0X01#region ReadData_0X01
private void ReadData_0X01(byte[] pRD)
...{
try
...{
try
...{
if (pRD[3] != 0x01)
...{
return
}
string[] mSampleCode = new string[pRD[7]]
int[] mTesterType = new int[pRD[7]]
int[] mLoadCapacity = new int[pRD[7]]
for (int i = 0i <pRD[7]i++)
...{
for (int j = 0j <12j++)
...{
mSampleCode[i] = mSampleCode[i] + Convert.ToString(Convert.ToChar(pRD[8 + j + i * 19]))
}
mTesterType[i] = pRD[i * 19 + 21] * 255 + pRD[i * 19 + 22]
mLoadCapacity[i] = pRD[i * 19 + 24] * 255 + pRD[i * 19 + 25]
}
return
}
catch (Exception Ex)
...{
throw Ex
}
}
catch
...{
}
}
#endregion ReadData_0X01
ReadData_0X02#region ReadData_0X02
private void ReadData_0X02(byte[] pRD)
...{
try
...{
try
...{
if (pRD[3] != 0x02)
...{
return
}
int[] mData = new int[pRD[7]]
string mSampleCode = ""
for (int i = 0i <12i++)
...{
mSampleCode = mSampleCode + Convert.ToString(Convert.ToChar(pRD[8 + i]))
}
for (int i = 0i <mData.Lengthi++)
...{
mData[i] = pRD[i * 2 + 20] * 255 + pRD[i * 2 + 21]
}
}
catch (Exception Ex)
...{
throw Ex
}
}
catch
...{
}
}
#endregion ReadData_0X02
ReadData_0X02_Request#region ReadData_0X02_Request
private void ReadData_0X02_Request(byte[] pRD)
...{
try
...{
try
...{
if (pRD[3] != 0x02)
...{
return
}
int[] mData = new int[pRD[7]]
string mSampleCode = ""
for (int i = 0i <12i++)
...{
mSampleCode = mSampleCode + Convert.ToString(Convert.ToChar(pRD[8 + i]))
}
for (int i = 0i <mData.Lengthi++)
...{
mData[i] = pRD[i * 2 + 20] * 255 + pRD[i * 2 + 21]
}
}
catch (Exception Ex)
...{
throw Ex
}
}
catch
...{
}
}
#endregion ReadData_0X02_Request
}
}
MSComm控件提供了两种处理通信的方式:一种为事件驱动方式,该方式相当于一般程序设计中的中断方式。当串口发生事件或错误时,MSComm控件会产生OnComm事件,用户程序可以捕获该事件进行相应处理。另一种为查询方式,在用户程序中设计定时或不定时查询MSComm控件的某些属性是否发生变化,从而确定相应处理。在程序空闲时间较多时可以采用该方式。 常用属性和方法 利用MSComm控件实现计算机通信的关键是理解并正确设置MSComm控件众多属性和方法。以下是MSComm控件的常用属性和方法:●Commport:设置或返回串口号。
●Settings:以字符串的形式设置或返回串口通信参数。
●Portopen:设置或返回串口状态。
●InputMode:设置或返回接收数据的类型。
●Inputlen:设置或返回一次从接收缓冲区中读取字节数。
●InBufferSize:设置或返回接收缓冲区的大小,缺省值为1024字节。
●InBufferCount:设置或返回接收缓冲区中等待计算机接收的字符数。
●Input:从接收缓冲区中读取数销数谈据并清空该缓冲区,该属性设计时无效,运行时只读。
●OutBufferSize:设置或返回发送缓冲区的大小,缺省值为512字节。
●OutBufferCount:设置或返回发送缓冲区中等待计算机发送的字符数。
●Output:向发送缓冲区发送数据,该属性设计时无效,运行时只读。
●Rthreshold:该属性为一阀值。当接收缓冲区中字符数达到该值时,MSComm控件设置Commevent属性为ComEvReceive,并产生OnComm事件。用户可在OnComm事件处理程序中进行相应处理。若Rthreshold属性设置为0,则不产生OnComm事件。例如用户希望接收缓冲区中达到一个字符就接收一个字符,可将Rthreshold设置为1。这样接收缓冲区中接收到一个字符,就产生一次OnComm事件。
●Sthreshold:该属性亦为一阀值。当发送缓冲区中字符数小于该值时,MSComm控件设置Commevent属性为ComEvSend,并产生OnComm事件。若Sthreshold属性设置为0,则不产生OnComm事件。要特别注意的是仅当发送缓冲区中字符数小于该值的瞬间才产生OnComm事件,其后就不再产生OnComm事件。例如Sthreshold设置为3,仅当发送缓冲区中字符数从3降为2时,MSComm控件设置Commevent属性为ComEvSend,同时产生OnComm事件,如发送缓冲区中字符始终为2,则不会再产生OnComm事件。这就避免了发送缓冲区中数据未发送完就反复发生OnComm事件。
●CommEvent:这是一个非常重要的属性。该属性设计时无效毕锋,运行时只读。一旦串口发生通信事件或产生错误,依据产生的事件和错误,MSComm控件为CommEvent属性赋不同的代码,同时产生OnComm事件。用户程序就可在OnComm事件处理程序中针对不同的代码,进行相应的处理。 CommEvent通信事件代码 常数 含义
1 ComEvReceive 接受亏碰到Rthreshold个字符。该事件将持续产生,直到用Input属性从接受缓冲区中读取并删除字符。
2 ComEvSend 发送缓冲区中数据少于Sthreshold个,说明串口已经发送了一些数据,程序可以用Output属性继续发送数据。
3 ComEvCTS Clear To Send信号线状态发生变化。
4 ComEvDSR Data Set Ready信号线状态从1变到0。
5 ComEvCD Carrier Detect信号线状态发生变化。
6 ComEvRing 检测到振铃信号。
7 ComEvEOF 接受到文件结束符。
CommEvent通信错误代码 常数 含义
1001 ComEvntBreak 接受到一个中断信号。
1002 ComEvntCTSTO Clear To Send信号超时。
1003 ComEvntDSRTO Data Set Ready信号超时。
1004 ComEvntFrame 帧错误。
1006 ComEvntOverrun 串口超速。
1007 ComEvntCDTO 载波检测超时。
1008 ComEvntRxOver 接受缓冲区溢出,缓冲区中已没有空间。
1009 ComEvntRxParity 奇偶校验错。
1010 ComEvntTxFull 发送缓冲区溢出,缓冲区中已没有空间。
1011 ComEvntDCB 检索串口的设备控制块时发生错误。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)