L
LIUYECAI
Unregistered / Unconfirmed
GUEST, unregistred user!
限用通迅构件,MSCOMM, OR SPCOMM:
注: 这是 for dos,or win3.1代码,
通过查询端口状态,然后读取接收数据,并返回 long 数.
long MainWindow::H_position()
{
long position;
int j,
i,
delay,
length,
keycode,
H_exit = 0,
InPut,
slength;
char s[100],
sr[100],
s1[10],
c;
strcpy(sr, "%1PR%");
strcpy(s, "");
do{
InPut=inportb(0x2fd)
}while((InPut &
0x0E)||(!(InPut &
0x20)));
slength = strlen(sr);
for(i=0;i<slength;i++){
if(sr != '%'){
outportb(0x2f8,(int)sr)
H_delay();
}
else{
outportb(0x2f8,0x0d);
H_delay();
outportb(0x2f8,0x0A);
H_delay();
}
}
while(H_exit == 0)
{
while(inportb(0x2fd)&0x01)
{
c = inportb(0x2f8);
switch(c)
{
case 0x0D: break;
case 0x0A: if( strlen(s) <= 6)
{
strcpy(s," ");
break;
}
else
{
H_exit = 1;
break;
}
case '/0': break;
default :
{
sprintf(s1, "%c", c);
strcat(s, s1);
break;
}
}
}
}
if((keycode=strlen(s)) >= 8) //只取后8位
{
delay = strlen(s) - 8;
for(j=0
j < 8
j++) //前移
{
s[j] = s[j+delay];
}
for(j=8
j<keycode
j++) //后面的清成 '/0'
{
s[j] = '/0';
}
}
position=atol(s)
//
return(position)
//返回 long.
}
注: 这是 for dos,or win3.1代码,
通过查询端口状态,然后读取接收数据,并返回 long 数.
long MainWindow::H_position()
{
long position;
int j,
i,
delay,
length,
keycode,
H_exit = 0,
InPut,
slength;
char s[100],
sr[100],
s1[10],
c;
strcpy(sr, "%1PR%");
strcpy(s, "");
do{
InPut=inportb(0x2fd)
}while((InPut &
0x0E)||(!(InPut &
0x20)));
slength = strlen(sr);
for(i=0;i<slength;i++){
if(sr != '%'){
outportb(0x2f8,(int)sr)
H_delay();
}
else{
outportb(0x2f8,0x0d);
H_delay();
outportb(0x2f8,0x0A);
H_delay();
}
}
while(H_exit == 0)
{
while(inportb(0x2fd)&0x01)
{
c = inportb(0x2f8);
switch(c)
{
case 0x0D: break;
case 0x0A: if( strlen(s) <= 6)
{
strcpy(s," ");
break;
}
else
{
H_exit = 1;
break;
}
case '/0': break;
default :
{
sprintf(s1, "%c", c);
strcat(s, s1);
break;
}
}
}
}
if((keycode=strlen(s)) >= 8) //只取后8位
{
delay = strlen(s) - 8;
for(j=0
j < 8
j++) //前移
{
s[j] = s[j+delay];
}
for(j=8
j<keycode
j++) //后面的清成 '/0'
{
s[j] = '/0';
}
}
position=atol(s)
//
return(position)
//返回 long.
}