| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1376 人关注过本帖
标题:红外手持器发送字符串和接收字符串
只看楼主 加入收藏
anle82
Rank: 1
等 级:新手上路
帖 子:19
专家分:0
注 册:2007-8-6
收藏
 问题点数:0 回复次数:5 
红外手持器发送字符串和接收字符串

用2个红外手持器发送字符串和接收字符串并返回发送状态,我做了一个字符收发,但不知道该如何写字符串的收发。

#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include <dos.h>
#include <time.h>
#include <io.h>
#include <fcntl.h>
#include <process.h>
#include <stdio.h>
#include <infrared.h>
#include <htlcd.h>
#include <htxlcd.h>
#include <commplus.h>
#include <htproces.h>
#include <barcode.h>
#include <htosex.h>

main()
{
unsigned char ascch, auxb, auxstat,workmode,commport,send,akey,str[7];

unsigned int baudrate,inRx,i;



printf("打开红外电源:\r\n");
IRPowerCtrl(_IRPowON); //红外电源控制 122
SetIRMFreq(38000); //设制红外调制频率 38k 122
getch();
printf("打开红外输出:\r\n");
SetIROutput(0);

do {
} while (!kbhit()); //kbhit()用来检测键盘是否有按键,有则返回-1,没有则返回0
printf("设置红外输出:\r\n");
SetIROutput(2);
do {
} while (!kbhit());
getch();

GetCommMode(&workmode, &commport, &baudrate); //取当前通讯串口、通讯方式和波特率 107
SetCommMode(3, 1, 1200); //设置通讯串口、通讯方式和波特率 107
EnableRx(0);

printf("请输入一些字符串并发送: \r\n");

send = 0;

do {
if (kbhit())
{
akey=getch();
if (akey !=auxb){
if (!send)
send = 1;

PutAuxByte(akey);
printf("%c\r\n",akey);

}
}
if (ExistAuxBGot(&auxb,&auxstat))
{ if (send)
printf("\r\n");
send = 0;
printf("%c\n",auxb);

}

} while (akey !=27);
IRPowerCtrl(_IRPowOFF); //红外电源控制 122
SetIRMFreq(0); //设制红外调制频率 0 122
DisableRx(); //禁止串行口接收任何数据
SetCommMode(workmode, commport, baudrate);
return 0;
}

这个代码该如何修改实现字符串收发,谢谢了

搜索更多相关主题的帖子: include 字符 红外 收发 process 
2007-08-06 21:12
Knocker
Rank: 8Rank: 8
等 级:贵宾
威 望:47
帖 子:10454
专家分:603
注 册:2004-6-1
收藏
得分:0 

#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include <dos.h>
#include <time.h>
#include <io.h>
#include <fcntl.h>
#include <process.h>
#include <stdio.h>
#include <infrared.h>
#include <htlcd.h>
#include <htxlcd.h>
#include <commplus.h>
#include <htproces.h>
#include <barcode.h>
#include <htosex.h>
void MyPutAuxByte(char * String);
main()
{
unsigned char ascch, auxb, auxstat,workmode,commport,send,akey,str[7];

unsigned int baudrate,inRx,i;



printf("打开红外电源:\r\n");
IRPowerCtrl(_IRPowON); //红外电源控制 122
SetIRMFreq(38000); //设制红外调制频率 38k 122
getch();
printf("打开红外输出:\r\n");
SetIROutput(0);

do {
} while (!kbhit()); //kbhit()用来检测键盘是否有按键,有则返回-1,没有则返回0
printf("设置红外输出:\r\n");
SetIROutput(2);
do {
} while (!kbhit());
getch();

GetCommMode(&workmode, &commport, &baudrate); //取当前通讯串口、通讯方式和波特率 107
SetCommMode(3, 1, 1200); //设置通讯串口、通讯方式和波特率 107
EnableRx(0);

printf("请输入一些字符串并发送: \r\n");

gets(String);

MyPutAuxByte(String);

IRPowerCtrl(_IRPowOFF); //红外电源控制 122
SetIRMFreq(0); //设制红外调制频率 0 122
DisableRx(); //禁止串行口接收任何数据
SetCommMode(workmode, commport, baudrate);
return 0;
}
void MyPutAuxByte(char * String)
{

unsigned char send=0,auxb, auxstat;
while(String)
{

if ((unsigned char)*String !=auxb)
{
if (!send)
send = 1;
PutAuxByte((unsigned char)*String);
printf("%c\r\n",(unsigned char)*String);

}
if (ExistAuxBGot(&auxb,&auxstat)) //猜不到这个函数的用途,就照搬了
{
if (send)
printf("\r\n");
send = 0;
printf("%c\n",auxb);
}

String++;
}

}


试试吧

[此贴子已经被作者于2007-8-7 9:16:00编辑过]


九洲方除百尺冰,映秀又遭蛮牛耕。汽笛嘶鸣国旗半,哀伤尽处是重生。     -老K
治国就是治吏。礼义廉耻,国之四维。四维不张,国之不国。   -毛泽东
2007-08-07 09:11
anle82
Rank: 1
等 级:新手上路
帖 子:19
专家分:0
注 册:2007-8-6
收藏
得分:0 
回复:(anle82)红外手持器发送字符串和接收字符串

#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include <dos.h>
#include <time.h>
#include <io.h>
#include <fcntl.h>
#include <process.h>
#include <stdio.h>
#include <infrared.h>
#include <htlcd.h>
#include <htxlcd.h>
#include <commplus.h>
#include <htproces.h>
#include <barcode.h>
#include <htosex.h>

main()
{
unsigned char ascch, auxb, auxstat,workmode,commport,send,akey,*str;

unsigned int baudrate,inRx,i;

printf("打开红外电源:\r\n");
IRPowerCtrl(_IRPowON); //红外电源控制 122
SetIRMFreq(38000); //设制红外调制频率 38k 122
getch();
printf("打开红外输出:\r\n");
SetIROutput(0);

do {
} while (!kbhit()); //kbhit()用来检测键盘是否有按键,有则返回-1,没有则返回0
printf("设置红外输出:\r\n");
SetIROutput(2);
do {
} while (!kbhit());
getch();

GetCommMode(&workmode, &commport, &baudrate); //取当前通讯串口、通讯方式和波特率 107
SetCommMode(3, 1, 1200); //设置通讯串口、通讯方式和波特率 107
EnableRx(0);

printf("请输入一些字符串: \n");



loop:
gets(str);
printf("按确定键发送:\n");
do
{
if (kbhit())
{
str[i] = getch();
printf("\n");
for(i=0; i<=15; i++)
{ PutAuxByte(str[i]);
}
str[15] = '@';
PutAuxByte(str[i]);
goto loop; }
if (ExistAuxBGot(&auxb,&auxstat)) //取得字符接收状态并读取已接收到的字符
{ if (send)

printf("%s\n",auxb);
}

} while (str[i] !=27);
IRPowerCtrl(_IRPowOFF); //红外电源控制 122
SetIRMFreq(0); //设制红外调制频率 0 122
DisableRx(); //禁止串行口接收任何数据
SetCommMode(workmode, commport, baudrate);
return 0;
}

上面这段代码:这种情况能不能不用goto?
要在if (ExistAuxBGot(&auxb,&auxstat))
{ if (send)

printf("%s\n",auxb);
}
里面添加一个返回接收状态给发送端?


2007-08-07 11:03
Knocker
Rank: 8Rank: 8
等 级:贵宾
威 望:47
帖 子:10454
专家分:603
注 册:2004-6-1
收藏
得分:0 
没调试环境,不能给你写代码
象你这样加goto肯定是不行的,
[QUOTE]if (ExistAuxBGot(&auxb,&auxstat)) //取得字符接收状态并读取已接收到的字符
{ if (send)

printf("%s\n",auxb);
}[/QUOTE]这些代码被搁置了

把发送单个字符与接收单个字符分别写成函数就成了

九洲方除百尺冰,映秀又遭蛮牛耕。汽笛嘶鸣国旗半,哀伤尽处是重生。     -老K
治国就是治吏。礼义廉耻,国之四维。四维不张,国之不国。   -毛泽东
2007-08-07 11:14
anle82
Rank: 1
等 级:新手上路
帖 子:19
专家分:0
注 册:2007-8-6
收藏
得分:0 
发送和接收字符串
以下是引用anle82在2007-8-7 11:03:30的发言:

#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include <dos.h>
#include <time.h>
#include <io.h>
#include <fcntl.h>
#include <process.h>
#include <stdio.h>
#include <infrared.h>
#include <htlcd.h>
#include <htxlcd.h>
#include <commplus.h>
#include <htproces.h>
#include <barcode.h>
#include <htosex.h>

main()
{
unsigned char ascch, auxb, auxstat,workmode,commport,send,akey,*str;

unsigned int baudrate,inRx,i;

printf("打开红外电源:\r\n");
IRPowerCtrl(_IRPowON); //红外电源控制 122
SetIRMFreq(38000); //设制红外调制频率 38k 122
getch();
printf("打开红外输出:\r\n");
SetIROutput(0);

do {
} while (!kbhit()); //kbhit()用来检测键盘是否有按键,有则返回-1,没有则返回0
printf("设置红外输出:\r\n");
SetIROutput(2);
do {
} while (!kbhit());
getch();

GetCommMode(&workmode, &commport, &baudrate); //取当前通讯串口、通讯方式和波特率 107
SetCommMode(3, 1, 1200); //设置通讯串口、通讯方式和波特率 107
EnableRx(0);

printf("请输入一些字符串: \n");



loop: gets(str);
printf("按确定键发送:\n");
do
{
if (kbhit())
{
str[i] = getch();
printf("\n");
for(i=0; i<=15; i++)
{ PutAuxByte(str[i]);
}
str[15] = '@';
PutAuxByte(str[i]);
goto loop; }
if (ExistAuxBGot(&auxb,&auxstat)) //取得字符接收状态并读取已接收到的字符
{ if (send)

printf("%s\n",auxb);
}

} while (str[i] !=27);
IRPowerCtrl(_IRPowOFF); //红外电源控制 122
SetIRMFreq(0); //设制红外调制频率 0 122
DisableRx(); //禁止串行口接收任何数据
SetCommMode(workmode, commport, baudrate);
return 0;
}

//上面代码可以实现2个红外手持器发送和接收字符串

//上面这段代码:这种情况能不能不用goto?
要在if (ExistAuxBGot(&auxb,&auxstat))
{ if (send)

printf("%s\n",auxb);
}
里面添加一个用"ok"表示返回接收状态给发送端?

[此贴子已经被作者于2007-8-7 17:35:55编辑过]


2007-08-07 11:23
anle82
Rank: 1
等 级:新手上路
帖 子:19
专家分:0
注 册:2007-8-6
收藏
得分:0 
回复:(Knocker)没调试环境,不能给你写代码象你这样...
你能加我QQ:472427580,谢了

2007-08-07 17:41
快速回复:红外手持器发送字符串和接收字符串
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012272 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved