- 论坛徽章:
- 0
|
串口应用程序问题请教?
大家好,我在PC 虚拟机 linux redhat下编写了串口应用程序代码,用GCC编译顺利通过,什么运行./serial的时候虚拟机没有反应啊。
我又用arm-linux-gcc编译顺利通过,在mini2440开发板上运行./serial,串口仍然没有任何反应。
linux系统下均有相应的设备文件"/dev/ttyS0"
恳请指教,多谢了。
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <signal.h>
#include <string.h>
#include <netdb.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include "serial.h"
#define BUFFER_SIZE 1024
#define com_port_1 1
#define com_port_2 2
int main (void)
{
int len;
int serialfd;
char buff[1024];
serialfd= OpenComPort(com_port_1, 9600, 8, "1", 'N'); //zigbee串口设置的波特率
if (serialfd < 0)
{
printf("Error: Opening Com Port %d\n",com_port_1);
exit (1);
}
else
{
printf("Open Com Port %d Success, Now going to read port\n", com_port_1);
}
while(1)
{
memset(buff,0, BUFFER_SIZE);
len = ReadComPort(serialfd,buff,BUFFER_SIZE);
if(len > 0)//read success
{
buff[len]='\0';
printf("Read %d numbers from com_port_%d buff=%s\n",len,com_port_1,buff);
WriteComPort(serialfd,buff,BUFFER_SIZE);
}
}
/* end of while */
close(serialfd);
}
|
|