Покажи Публикации - sgeorgiev
* Виж публикациите на потр. | Виж темите на потр. | Виж прикачените файлове на потр
Страници: [1]
1  Linux секция за напреднали / Хардуерни и софтуерни проблеми / Re: Kak da otvorq Comm Port -: 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.
2  Linux секция за напреднали / Хардуерни и софтуерни проблеми / Re: Kak da otvorq Comm Port -: 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.
3  Linux секция за напреднали / Хардуерни и софтуерни проблеми / 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,
Страници: [1]