The OpenNET Project / Index page

[ новости /+++ | форум | теги | ]




Версия для распечатки Пред. тема | След. тема
Новые ответы [ Отслеживать ]
Что я делаю не правильно?, !*! Oleg, 30-Окт-05, 16:45  [смотреть все]
В программировании я новичек сильно не пинайте... Работаю с модемом через ком порт Открываю порт, пишу команды все ок, вот только ответы от модема не могу прочитать =(
Вот моя программка

#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <termios.h>

int fd;
struct termios options;
int open_port(void)
{
    /* open the port */
    fd = open("/dev/ttyS0", O_RDWR | O_NOCTTY | O_NDELAY);
    fcntl(fd, F_SETFL, 0);

    /* get the current options */
    tcgetattr(fd, &options);
/*    for (int i=0;i<sizeof(options.c_cc); i++)
{
    printf("Index %d, %d\n", i, options.c_cc[i]);
}
*/

    /* set raw input, 1 second timeout */
    options.c_cflag     |= (CLOCAL | CREAD);
    options.c_lflag         &= ~(ICANON | ECHO | ECHOE | ISIG);
    options.c_oflag     &= ~OPOST;
    options.c_cc[VMIN]  = 0;
    options.c_cc[VTIME] = 10;

    /* set the options */
    tcsetattr(fd, TCSANOW, &options);
    return(fd);
}

main(int argc,char *argv[])
{
char buffer[255]; //Читаем сюда;
char *ch;
int port = open_port();
const char* _end = "\r";
char com[32];
strcpy(com, argv[1]);
strcat(com, _end);
printf("Команда: %s\n", com);
int wr = write(port, com, strlen(com));
printf("Size of com %i\n",strlen(com));
int bytes = read(port,buffer, 4);
printf("Прочитал: %d\n", bytes);
printf ("В буфере: %s\n",buffer);
close(port);
}

Прочитал http://www.opennet.me/docs/RUS/serial_guide/
программа инициализации модема всегда выдает -1 =( хотя при cat /dev/ttyS0  
я вижу что команда проходят и модем отвечает




Партнёры:
PostgresPro
Inferno Solutions
Hosting by Hoster.ru
Хостинг:

Закладки на сайте
Проследить за страницей
Created 1996-2024 by Maxim Chirkov
Добавить, Поддержать, Вебмастеру