Автор Тема: Kak da otvorq Comm Port  (Прочетена 1721 пъти)

sgeorgiev

  • Участници
  • ***
  • Публикации: 3
    • Профил
Kak da otvorq Comm Port
« -: Jan 31, 2009, 17:31 »
Zdraveite.

Vyprosa mi e kak se otvarqt Comm  portove pod Linux. Ima li programa v linux podobna na Hiperterminala pod Windows.

Ima li fail v /dev s koito moga da rabotq.

Molq ako razpolagate s nqkoq statiq ili drugi materiali svyrzani s nachina na upotreba na Comm pod Linux daite link.

Blagodarq vi predvaritelno,
Активен

tarator

  • Напреднали
  • *****
  • Публикации: 849
    • Профил
Re: Kak da otvorq Comm Port
« Отговор #1 -: Jan 31, 2009, 18:29 »
COM1 е /dev/ttyS0. Ако използваш някакъв USB конвертор /dev/ttyUSB0.

Аз използвам minicom, може би има по-добри програми, но с тази съм свикнал.
Активен

A gentleman is one who is never rude unintentionally. - Noel Coward

Slevin_

  • Напреднали
  • *****
  • Публикации: 182
    • Профил
Re: Kak da otvorq Comm Port
« Отговор #2 -: Jan 31, 2009, 22:34 »
tarator ти е отогворил. Аз също ползвам minicom.
Ако държиш на GUI, то потърси cutecom.
Активен

"Две неща на този свят са безкрайни - човешката глупост и вселената. За второто не съм съвсем сигурен" А. Айнщайн

sgeorgiev

  • Участници
  • ***
  • Публикации: 3
    • Профил
Re: Kak da otvorq Comm Port
« Отговор #3 -: Feb 05, 2009, 11:42 »
Blagodarq vi za informaciqta.

Opitah da napisha sobstvena programka koqto da otvarq comm kato file, no ne uspah da namerq nachin da setna BITS PER SEC i  stop bita.

Molq ako razpolagate s nqkoi tutorial ili drugi materiali kak stava pishte.
Активен

BULFON

  • Administrator
  • Напреднали
  • *****
  • Публикации: 478
  • Distribution: Fedora
  • Window Manager: Gnome
    • Профил
Re: Kak da otvorq Comm Port
« Отговор #4 -: Feb 05, 2009, 12:11 »
http://www.comptechdoc.org/os/linux/programming/c/linux_pgcserial.html

http://www.faqs.org/docs/Linux-mini/IO-Port-Programming.html

Код
GeSHi (C):
  1. /*
  2.  * example.c: very simple example of port I/O
  3.  *
  4.  * This code does nothing useful, just a port write, a pause,
  5.  * and a port read. Compile with `gcc -O2 -o example example.c',
  6.  * and run as root with `./example'.
  7.  */
  8.  
  9. #include <stdio.h>
  10. #include <unistd.h>
  11. #include <asm/io.h>
  12.  
  13. #define BASEPORT 0x378 /* lp1 */
  14.  
  15. int main()
  16. {
  17.  /* Get access to the ports */
  18.  if (ioperm(BASEPORT, 3, 1)) {perror("ioperm"); exit(1);}
  19.  
  20.  /* Set the data signals (D0-7) of the port to all low (0) */
  21.  outb(0, BASEPORT);
  22.  
  23.  /* Sleep for a while (100 ms) */
  24.  usleep(100000);
  25.  
  26.  /* Read from the status port (BASE+1) and display the result */
  27.  printf("status: %d\n", inb(BASEPORT + 1));
  28.  
  29.  /* We don't need the ports anymore */
  30.  if (ioperm(BASEPORT, 3, 0)) {perror("ioperm"); exit(1);}
  31.  
  32.  exit(0);
  33. }
  34.  
  35. /* end of example.c */
  36.  
  37.  

Последно, но не на последно място:
http://www.google.bg/search?q=linux+com+port+c+program&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a
Активен

фонокартен телефонен апарат

sgeorgiev

  • Участници
  • ***
  • Публикации: 3
    • Профил
Re: Kak da otvorq Comm Port
« Отговор #5 -: Feb 06, 2009, 08:25 »
Blagodarq vi za linkovete. Programata se poluchi mnogo oprostena.

Код:
#include <stdio.h>
#include <sys/types.h>
#include <fcntl.h>
#include <termios.h>
#include <string.h>

void sendCommand(int fd, char *command, char *result, int size)
{
int i = 0;
memset(result, 0, size);
write(fd, command, strlen(command));
char p;
char c;
do
{
p = c;
c = '\0';
int res = read(fd, &c, 1);
if(res > 0)
{
result[i] = c;
i++;
}
}while(p != 'K');
}

int main()
{
long BAUD = B4800;                      // derived baud rate from command line
long DATABITS = CS8;
long STOPBITS = 0;
long PARITYON = 00;
long PARITY = 00;

struct termios newtio;
int fd = open("/dev/ttyUSB0", O_RDWR | O_NOCTTY | O_NONBLOCK);
if(fd < 0)printf("Error!!!\n");

fcntl(fd, F_SETOWN, getpid());

newtio.c_cflag = BAUD | CRTSCTS | DATABITS | STOPBITS | PARITYON | PARITY | CLOCAL | CREAD;
newtio.c_iflag = IGNPAR;
newtio.c_oflag = 0;
newtio.c_lflag = 0;       //ICANON;
newtio.c_cc[VMIN]=1;
newtio.c_cc[VTIME]=1;
tcflush(fd, TCIFLUSH);
tcsetattr(fd,TCSANOW,&newtio);

char result[128];
int i;
for(i=0; i<20; i++)
{
sendCommand(fd, "AON\r", result, sizeof(result));
printf("RESULT: %s\n", result);
sendCommand(fd, "BON\r", result, sizeof(result));
printf("RESULT: %s\n", result);
sendCommand(fd, "CON\r", result, sizeof(result));
printf("RESULT: %s\n", result);
sendCommand(fd, "DON\r", result, sizeof(result));
printf("RESULT: %s\n", result);
sendCommand(fd, "EON\r", result, sizeof(result));
printf("RESULT: %s\n", result);
sendCommand(fd, "FON\r", result, sizeof(result));
printf("RESULT: %s\n", result);
sendCommand(fd, "GON\r", result, sizeof(result));
printf("RESULT: %s\n", result);
sendCommand(fd, "STATE\r", result, sizeof(result));
printf("RESULT: %s\n", result);

sendCommand(fd, "AOFF\r", result, sizeof(result));
printf("RESULT: %s\n", result);
sendCommand(fd, "BOFF\r", result, sizeof(result));
printf("RESULT: %s\n", result);
sendCommand(fd, "COFF\r", result, sizeof(result));
printf("RESULT: %s\n", result);
sendCommand(fd, "DOFF\r", result, sizeof(result));
printf("RESULT: %s\n", result);
sendCommand(fd, "EOFF\r", result, sizeof(result));
printf("RESULT: %s\n", result);
sendCommand(fd, "FOFF\r", result, sizeof(result));
printf("RESULT: %s\n", result);
sendCommand(fd, "GOFF\r", result, sizeof(result));
printf("RESULT: %s\n", result);
sendCommand(fd, "STATE\r", result, sizeof(result));
printf("RESULT: %s\n", result);

sendCommand(fd, "AIN\r", result, sizeof(result));
printf("RESULT: %s\n", result);

sendCommand(fd, "DIN\r", result, sizeof(result));
printf("RESULT: %s\n", result);

sendCommand(fd, "ERROR\r", result, sizeof(result));
printf("RESULT: %s\n", result);
        }
return 0;
}


Publicuvam coda ako nqkoi drug se sblyska s takyv problem nadqvam se da mu pomogne.
Активен

Подобни теми
Заглавие Започната от Отговора Прегледи Последна публикация
port forwarding
Настройка на програми
coldy 1 7651 Последна публикация Nov 23, 2002, 11:15
от coldy
tomcat na 80-ti port?
Хардуерни и софтуерни проблеми
obla4e 5 5061 Последна публикация Oct 21, 2003, 23:40
от obla4e
FTP Port 21
Настройки на софтуер
tores 6 6765 Последна публикация Jun 08, 2004, 21:54
от n_antonov
Пренасочване на ssh port
Настройка на програми
int13 1 5119 Последна публикация Apr 19, 2005, 13:18
от
Port nat
Настройка на програми
runtime 4 4828 Последна публикация Nov 27, 2007, 13:35
от runtime