当前位置:[北京同好会]>[编程]>[串口控件和验证程序]

 

串口小控件SimpleCom

一直在用一个叫cport的串口控件,效果很好。但不是自己编的总有点不甘心。试着写了一个简单的串口处理控件,能执行普通的收发工作,高级的功能像流量控制、异常处理等就不打算费心了。顺便练习了一下编写元件属性编辑器等。

主要参考了CBB所带的API说明和网上的文章。不过串口编程这个问题的有关文档属于我见过的最为晦涩的一类,真奇怪为什么不能用一种大多数人都能听懂的语言来描述。

2006-8-12

class PACKAGE TSimpleCom : public TComponent

NFL sports jerseys are a abundant means for any fan to appearance cheap nfl jerseys their abutment for their respected team .cheap nfl jerseys As you attending at the altered available, you ability admiration what some cheap nfl jerseys of your alternatives are as you aswell cheap nfl jerseys activate the seek for one that is cheap nfl jerseys acceptable for you.Typically, 2013 super bowl jerseys you will exchange that NFL sports jerseys cheap nike nfl jerseys are advised as replicas of the official bold jersey your respected players wear. They are fabricated of a college superior nylon allowing the derma beneath them to breathe easily. Best of all,cheap nfl jerseys the faculty superior versions ravens jerseys will endure a continued time acknowledgment to the added material. Over the years,49ers jerseys these jerseys accept become cheap nfl jerseys absolute accepted acknowledgment to the cheap nfl jerseys able followings the teams have. Most break at home admirers like to action the jersey of their respected player, while they acclamation at the bold on nfl jerseys cheap the big screen. Those that do Cheap Nike NFL jerseys accomplish it to the big game, they adore accepting their on to appearance the aggregation they cheap nfl jerseys are admitting and they tend to attending ablaze in a affiliate marketer of hundreds cutting the absolute above mentioned jersey When you are searching at the altered NFL sports jerseys, you will apprehension that they accept a altered appearance 2013 super bowl jerseys depending on gender.cheap authentic jerseys The ones advised nfl jerseys cheap for men are about abutting cut to the close and aggregate cheap jerseys china out in the accept areas Women will exchange a added airy close band that gives them added nfl jerseys china comfort Their options cheap nfl jerseys can be bigger in the chest breadth and smaller in the amateur and sides. There are cheap jerseys china even some risque jersey sources cheap nfl jerseys of the added adventuresome women to wear.

主要功能:

设置串口参数

发送单字节,发送多字节

512字节接收缓存。接收时向主窗口发送消息。

调用:


bool setup(void)
打开串口设置对话框设置串口参数,成功返回true。如果当时串口已打开或未设置则返回false。

bool sendbyte(unsigned char c)
发送一个字节c。如果串口未打开返回false,否则true。

bool readbyte(unsigned char & c)
读一个字节。如果端口未打开或者没有新的字节返回false,否则true。

bool sendcmd(unsigned char *cmd,int num)
发送保存在cmd[]中的num个字节。如果串口未打开或num大于255返回false,否则true。

__property HWND hmainform = { write=Fhmainform }
设定接收消息的窗口

__property bool connect = { read=Fconnect, write=Setconnect };
写:连接或断开端口。读:端口连接状态


bool readcmd(unsigned char *cmd,int &num)
将目前缓存中的所有字节读出,共num个。如果端口未打开或者没有新的字节返回false,否则true。

void set_txfeedback(bool fb)
发送线程消息反馈标志。置位反馈TSC_TXCMD和发送字节数。

void set_rxfeedback(bool fb)
接收线程消息反馈标志。置位每次接收到字符均反馈TSC_RXCHAR和接收字节数;否则当缓存内增加128个字符后再反馈。

消息处理

//simple feedback via message:
#define WM_TSIMPLECOMMESSAGE (WM_APP + 406)
#define TSC_RXCHAR 1 //BYTE ARRIVED
#define TSC_RXERR 2 //error in receiving
#define TSC_EVERR 3 //other Event (not EVCHAR & EVERR) occur
#define TSC_ERREV 4 //Event EV_ERR
#define TSC_TXCMD 5 //finish sending cmd
#define TSC_TXERR 6 //error in sending

Error Codes
W:L

TSC_RXERR:
1)"RX may Overflow"
2)"not read 128 bytes"
3)"not read 128 bytes"
4)"readfile return not error_io_pending"
5)"not read n bytes"
6)"not read n bytes"
7)"readfile return not error_io_pending"
8)"GetResult Return False"
9)"WaitCommEvent Non-pending Error"
10)"WaitCommEvent Return immediatly"
11)"Buffer Overflow"

TSC_ERREV:Errors
DWORD errormask[]={1,CE_RXOVER,2,CE_OVERRUN,4,CE_RXPARITY,8,CE_FRAME,2048,CE_DNS,
256,CE_TXFULL,512,CE_PTO,16,CE_BREAK,32768,CE_MODE,1024,CE_IOE,4096,CE_OOP};

TSC_EVERR:mask
DWORD eventmask[]={1,EV_RXCHAR,2,EV_RXFLAG,4,EV_TXEMPTY,8,EV_CTS,16,EV_DSR,32,EV_RLSD,
64,EV_BREAK,128,EV_ERR,256,EV_RING};

TSC_TXERR:
1)"0 Byte Sent"
2)"Sending Timeout"
3)"Sending returned but Error"
4)"Sending Non-pending Error"
5)"Sending Return Immediately"