📄 bcjq064.txt
字号:
C++ Builder开发者:程序员之家
var how_many_ads = 3;
var now = new Date()
var sec = now.getSeconds()
var ad = sec % how_many_ads;
ad +=1;
首页
| 控件天堂 | 控件使用
| 编程技巧
| 源代码 | 编程工具 |
系统补丁 | 电子书籍 | 技术论坛
| 相关链接
if (ad==1) {document.write(''+'');}
if (ad==2) {document.write(''+'');}
if (ad==3) {document.write(''+'');}
var marqueecontents=''+scroll_text+''
if (document.all)
document.write(''+marqueecontents+'')
function regenerate(){
window.location.reload()
}
function regenerate2(){
if (document.layers){
setTimeout("window.onresize=regenerate",450)
intializemarquee()
}
}
function intializemarquee(){
document.cmarquee01.document.cmarquee02.document.write(marqueecontents)
document.cmarquee01.document.cmarquee02.document.close()
thelength=document.cmarquee01.document.cmarquee02.document.height
scrollit()
}
function scrollit(){
if (document.cmarquee01.document.cmarquee02.top>=thelength*(-1)){
document.cmarquee01.document.cmarquee02.top-=speed
setTimeout("scrollit()",100)
}
else{
document.cmarquee01.document.cmarquee02.top=marqueeheight
scrollit()
}
}
window.onload=regenerate2
当前位置
:
编程技巧
用C++
Builder编程实现串行通信
用C++ Builder来编写串行通信程序, 我们需要用到几个Windows
API函数,而不象在DOS 下那样直接操作串口和中断芯片.这几个函数有OpenFile,
CloseFile, GetCommState, SetCommState等,Microsoft的Visual Basic中有一个OCX控件MSComm32,在VB用它做串行通信设备很方便,
将它装入Builder 3中, 它的Input和Ouput属性是Unknown, 即
Builder 3不认识MSComm32的这两个属性, 我们升级到Borland的C++
Builder 4.0,在 Object Inspector中将不再看到这两个属性,
但它们仍然存在, 这两个属性的类型是 OleVariant,也就是Ole万能变量,使用这种类型的方法如下:
在要发送数据时,我们声明一个发送数据缓冲区,然后重置它的大小,填充它的元素,发送它,例如:
buff[200];//请声明为全局变量 OleVariant TxBuff;//声明一个OleVariant变量
Txbuff=VarArrayCreat(OPENARRAY(int,(0,n)),varByte);//重置它的大小,为0~n,int
为n的类型。 //varByte为TxBuff每一个元素的类型。 for(int
i=0;i
Output=TxBuff;//发送数据,MSComm1为你方在窗体上的一个MSComm32控件。接收数据时请看下面的例子:
int buff[200];//声明一个存储接收数据的缓冲区,全局变量
int ByteNum;//收到的字节数 int BuffPtr;//接收缓冲区的指针,请声明为全局变量,
OleVariant RxBuff;//一个用于接收的OleVariant变量。
if(MSComm1-> InBuffCount>0)RxBuff=Communica1->Input;//如果缓冲区有多于一个字节的数据
ByteNum=RxBuff.ArrayHighBound(1);//将实际读的字节数取出 for(int
i=0;i<=ByteNum;i++){buff[BuffPtr++]=RxBuff.GetElement(i);}//将接收数据读入自己的缓冲区。
在Object Inspector的Event标签中只有一个事件OnComm,
这个事件在MSComm32控件接收到数据时会被调用,但你必须设置TThreshold属性,这是一个门槛,表示收到几个字节就发送通知消息,如果为零,就不发送通知消息,这样你的OnComm函数就不会得到执行,TThreshold是发送门槛,不要忘记Setting。
另外值得注意的是MSComm32的OnComm事件不是很准确,有时会丢失,你不能过分依赖这个事件,否则,经常发生的不是发不出数据,就是接收不到数据,最好的办法是使用一个定时控件,需要的时候就区读MSComm32控件的缓冲区。
if (ad==1) {document.write(''+'');}
if (ad==2) {document.write(''+'');}
if (ad==3) {document.write(''+'');}
C++ Builder开发者®
2000年06月01日 站长:唐朝