우분트 컴터로요 온동/습도/co2 센서기에서 시리얼로 rs-232로 통하여서 usb로 해서 pc로 들어오는 센서값을 c언어로 찍어보려하는데요 minicom을 통해서 센서값이 들어오는것은 확인했는데 c언어로 하니깐 값이 안들어와요
씨리얼도 잘 열어서 안열리면 종료하도록 해서 잘 연결이 된듯한데 값을 받지 못하는지 모르겠습니다. 혹시 단순하게 집고 넘어간것이 있는지?ㅠㅠ
그냥 간단히 힌트만 던져주세요
시리얼 속도는 설정하셨는지요?
======================== 조직 : E.L.D(Embedded Linux Developer/Designer) 블로그 : poplinux@tistory.com 카페 : cafe.naver.com/poplinux
임베디드 리눅스 관련 프리렌서 지향
네 했습니다!ㅜ
devband
http://code.google.com/p/picocom/ 로 컴파일해서 접속해 보시고 작성하신 소스 코드와 어떻게 다른지 비교해 보세요.
제가 시리얼 통신쪽은 무뇌아라 ㅠㅠ 소스를 다음과 같이 했는데 무엇이...ㅠ #include #include #include #include #include #include #include
#define TOUCHPORT "/dev/ttyUSB0" #define BAUDRATE B9600 #define BUFSIZE 18 #define TRUE 1 #define FALSE 0 #define U32 unsigned int
#define Debug #define SerialSet void SerialRead();
int main(void) { #ifdef Debug printf("main --> Start !!\n"); printf("SerialRead Call !!\n"); #endif
SerialRead(); return 0; }
void SerialRead() { char buf[BUFSIZE]={0}; int fd=0,r=0; int i=0; #ifdef Debug printf("SerialRead ---> Start!!\n"); printf("TouchPort !!\n"); #endif printf("포트를 열기\n"); fd = open(TOUCHPORT,O_RDWR | O_NOCTTY);
if(fd<0) { perror(TOUCHPORT); exit(-1); } printf("포트를 열기 성공!\n");
#ifdef SerialSet #ifdef Debug printf("SerialSet .. Start !!\n"); #endif
struct termios tio; tcgetattr(fd,&tio); tio.c_cflag = CS8 | CLOCAL | CREAD; tio.c_cflag = IGNPAR | ICRNL; tio.c_cflag = 0; tio.c_cc[VTIME]=0; tio.c_cc[VMIN] =0; tcflush(fd,TCIFLUSH); tcsetattr(fd,TCSANOW,&tio);
#ifdef Debug printf("SerialSet .. End!!\n"); #endif #endif
#ifdef Debug printf("TouchPort descript ==> %d\n",r); #endif
while(1) {
r = read(fd,buf,sizeof(buf));
if(r <=0) { printf("reply\n"); continue; }
for(i=0;i printf("%x",buf[i]); } memset(buf,0,sizeof(buf)); }//while }//end
텍스트 포맷에 대한 자세한 정보
<code>
<blockcode>
<apache>
<applescript>
<autoconf>
<awk>
<bash>
<c>
<cpp>
<css>
<diff>
<drupal5>
<drupal6>
<gdb>
<html>
<html5>
<java>
<javascript>
<ldif>
<lua>
<make>
<mysql>
<perl>
<perl6>
<php>
<pgsql>
<proftpd>
<python>
<reg>
<spec>
<ruby>
<foo>
[foo]
시리얼 속도는 설정하셨는지요?
시리얼 속도는 설정하셨는지요?
========================
조직 : E.L.D(Embedded Linux Developer/Designer)
블로그 : poplinux@tistory.com
카페 : cafe.naver.com/poplinux
임베디드 리눅스 관련 프리렌서 지향
네 했습니다!ㅜ
네 했습니다!ㅜ
devband
picoco - minicom보다 (아주) 작은 터미널
http://code.google.com/p/picocom/
로 컴파일해서 접속해 보시고
작성하신 소스 코드와 어떻게 다른지 비교해 보세요.
확인 해서 받아오는것을 확인 했습니다만...ㅠ
제가 시리얼 통신쪽은 무뇌아라 ㅠㅠ
소스를 다음과 같이 했는데 무엇이...ㅠ
#include
#include
#include
#include
#include
#include
#include
#define TOUCHPORT "/dev/ttyUSB0"
#define BAUDRATE B9600
#define BUFSIZE 18
#define TRUE 1
#define FALSE 0
#define U32 unsigned int
#define Debug
#define SerialSet
void SerialRead();
int main(void)
{
#ifdef Debug
printf("main --> Start !!\n");
printf("SerialRead Call !!\n");
#endif
SerialRead();
return 0;
}
void SerialRead()
{
char buf[BUFSIZE]={0};
int fd=0,r=0;
int i=0;
#ifdef Debug
printf("SerialRead ---> Start!!\n");
printf("TouchPort !!\n");
#endif
printf("포트를 열기\n");
fd = open(TOUCHPORT,O_RDWR | O_NOCTTY);
if(fd<0) {
perror(TOUCHPORT);
exit(-1);
}
printf("포트를 열기 성공!\n");
#ifdef SerialSet
#ifdef Debug
printf("SerialSet .. Start !!\n");
#endif
struct termios tio;
tcgetattr(fd,&tio);
tio.c_cflag = CS8 | CLOCAL | CREAD;
tio.c_cflag = IGNPAR | ICRNL;
tio.c_cflag = 0;
tio.c_cc[VTIME]=0;
tio.c_cc[VMIN] =0;
tcflush(fd,TCIFLUSH);
tcsetattr(fd,TCSANOW,&tio);
#ifdef Debug
printf("SerialSet .. End!!\n");
#endif
#endif
#ifdef Debug
printf("TouchPort descript ==> %d\n",r);
#endif
while(1) {
r = read(fd,buf,sizeof(buf));
if(r <=0)
{
printf("reply\n");
continue;
}
for(i=0;i printf("%x",buf[i]);
}
memset(buf,0,sizeof(buf));
}//while
}//end
devband
댓글 달기