PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : ASURI IR TRANSRESIVER daten auf pc empfangen



--linuxuser--
08.01.2006, 17:42
hi leute!
======

ich ich habe mir den asuro roboter gekauft nun bin ich vor einiger zeit draufgekommen(durch hilfe dieses forums) dass der sender meines ir transresivers nicht funkt und bis der usb transresiver vom conrad kommt wollte ich noch ein programm schreiben dass signale von meinem ir transresiver entgegennimmt und auf dem bildschirm ausgibt!(das funkt auch schon mit minicom immer waenn ich mit der fernbedienung auf eine taste druecke kommt was an bei minicom!) hier mal mein programm:


/*ledController whith FERNBEDIENUNG!
*(C) by linuxuser
*e-mail: unix4ever@gmx.net
*/

#include <sys/ioctl.h>
#include <sys/kd.h>
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>

#define INDEVICE "/dev/ttyS0"
#define OUTDEVICE "/dev/tty1"

#define BLOCKSIZE 8

int main(void){
int readBytes;
int input;
int output;

char buffer[BLOCKSIZE];

/*open the input device*/
input = open(INDEVICE, O_RDONLY|O_NOCTTY|O_NONBLOCK);

/*open the output device*/
output = open(OUTDEVICE, O_WRONLY);

if(input == -1 || output == -1){
fprintf(stderr, "ERROR konnte die Devices nicht oeffnen");
return 1;
}/*end if*/

while(1){
printf("hallo\n");
readBytes = read(input, buffer, BLOCKSIZE);
perror("Fehler ");
printf("%s,%d, - %d\n", buffer, buffer, readBytes);
}

return 0;
}/*end main*/
aber irgendwie funkt es nicht so richtig als ausgabe bekomme ich(diese natuerlich oefter da O_NONBLOCK und endlosschleife):


hallo
Fehler : Resource temporarily unavailable
,-1080603244, - -1

koennte mir vielleicht einer sagen was ich falsch mache/vergesse?
DANKE das waere super
mfg
linuxuser

MSSputnik
08.01.2006, 18:03
Hallo,

hast du schon überprüft, ob du schreibrechte auf das Output Device hast?

Ausserdem ließt du von ttyS0 und schreibts auf tty1.
Kann es sein, das es das Output Device (COM2) gar nicht an deinem Computer gibt?

Martin

--linuxuser--
08.01.2006, 18:17
tschuldigung das tty1 brauch ich gar nicht(erst spaeter dann!)
so sollte es sein:


/*ledController whith FERNBEDIENUNG!
*(C) by linuxuser
*e-mail: unix4ever@gmx.net
*/

#include <sys/ioctl.h>
#include <sys/kd.h>
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>

#define INDEVICE "/dev/ttyS0"

#define BLOCKSIZE 8

int main(void){
int readBytes;
int input;

char buffer[BLOCKSIZE];

/*open the input device*/
input = open(INDEVICE, O_RDONLY|O_NOCTTY|O_NONBLOCK);

if(input == -1){
fprintf(stderr, "ERROR konnte die Devices nicht oeffnen");
return 1;
}/*end if*/

while(1){
printf("hallo\n");
readBytes = read(input, buffer, BLOCKSIZE);
perror("Fehler ");
printf("%s,%d, - %d\n", buffer, buffer, readBytes);
}

return 0;
}/*end main*/


und /dev/ttS0 also COM1 habe ich!

stochri
08.01.2006, 18:46
Vielleicht kannst Du da was finden:
https://www.roboternetz.de/phpBB2/viewtopic.php?p=145553#145553
Gruss,
stochri

--linuxuser--
10.01.2006, 15:04
hi leute! ich habs jetzt hinbekommen...



/* A SIMPLE LED CONTROLER
* you are able to change the led
* state with a FERNBEDIEHNUNG
* (C) 2006 --linuxuser--
* e-mail: unix4ever@gmx.at
* Version 1.0
*/

#include <sys/ioctl.h>
#include <sys/kd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <termios.h>
#include <ctype.h>
#include <assert.h>

#define OUTPUT "/dev/tty1"
#define INPUT "/dev/ttyS0"

#define ENDLOS 1
#define FAIL 0
#define SUCC 1

#define BAUDRATE B2400

/*lights*/
#define NOLIGHT 0x0
#define ALLLIGHT 0X7
#define RLIGHT 0X1
#define MLIGHT 0x4
#define LLIGHT 0x2

/*keys on the "FERNBEDIENUNG"*/
#define FBDK_OFF 0xFE06
#define FBDK_CD 0x4015FE33


int setLight(int output, const unsigned int state){
/*a very primitive method*/
if(ioctl(output, KDSETLED, state)){
fprintf(stderr, "KONNTE LICHT NICHT EINSCHALTEN!!!\n");
return FAIL;
}/*end if*/

return SUCC;
}/*end if*/

int main(void){
int states[5] = {NOLIGHT, ALLLIGHT, RLIGHT, MLIGHT, LLIGHT}; /*all implemented states*/
int recived_bytes; /*how many bytes have recived?*/
unsigned int inputByte = 0; /*the byte comes in from the COM1 port*/
unsigned int buffer = 0;
int output; /*the keyboard*/
int input; /*COM1*/
struct termios newtio; /*settings for the RS-232 "CONSOL"*/
int i = 0;

/*open the input*/
input = open(INPUT, O_RDWR | O_NOCTTY | O_NDELAY);
if(input == -1){
fprintf(stderr, "Fehler beim oeffnen der Seriellen schnittstelle: %s!\n", INPUT);
}/*end if*/

/*open the output*/
output = open(OUTPUT, O_WRONLY);
if(output == -1){
fprintf(stderr, "FEHLER bein oeffnen des outputS: %s!\n", OUTPUT);
return 0;
}/*end if*/

/*configure the RS-232 port*/
fcntl(input, F_SETFL, FNDELAY);
newtio.c_cflag = BAUDRATE | CS8 | CLOCAL | CREAD ;
newtio.c_iflag = IGNPAR | ICRNL ;
newtio.c_oflag = 0;
newtio.c_lflag &= ~(ICANON);

/*set configuration*/
tcflush(input, TCIOFLUSH);
tcsetattr(input, TCSANOW, &newtio);

/*start the main loop*/
while(ENDLOS){
system("clear");
/*read the input*/
recived_bytes = read(input, &inputByte, 4);
/*put the input out on the consol*/
printf("(c)Rainer Sickinger\nGelesenesBytes: 0x%x\n", inputByte);
if(buffer != inputByte){
setLight(output, states[i]);
i++;
if(i == 4) i = 0;
}/*end if*/
buffer = inputByte;
sleep(1);
}/*end while*/

/*close the file deskriptorz*/
close(input);
close(output);

return 0;
}/*end main*/


DANKE nochmal!

--linuxuser--
10.01.2006, 15:05
hi leute! ich habs jetzt hinbekommen...



/* A SIMPLE LED CONTROLER
* you are able to change the led
* state with a FERNBEDIEHNUNG
* (C) 2006 --linuxuser--
* e-mail: unix4ever@gmx.at
* Version 1.0
*/

#include <sys/ioctl.h>
#include <sys/kd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <termios.h>
#include <ctype.h>
#include <assert.h>

#define OUTPUT "/dev/tty1"
#define INPUT "/dev/ttyS0"

#define ENDLOS 1
#define FAIL 0
#define SUCC 1

#define BAUDRATE B2400

/*lights*/
#define NOLIGHT 0x0
#define ALLLIGHT 0X7
#define RLIGHT 0X1
#define MLIGHT 0x4
#define LLIGHT 0x2

/*keys on the "FERNBEDIENUNG"*/
#define FBDK_OFF 0xFE06
#define FBDK_CD 0x4015FE33


int setLight(int output, const unsigned int state){
/*a very primitive method*/
if(ioctl(output, KDSETLED, state)){
fprintf(stderr, "KONNTE LICHT NICHT EINSCHALTEN!!!\n");
return FAIL;
}/*end if*/

return SUCC;
}/*end if*/

int main(void){
int states[5] = {NOLIGHT, ALLLIGHT, RLIGHT, MLIGHT, LLIGHT}; /*all implemented states*/
int recived_bytes; /*how many bytes have recived?*/
unsigned int inputByte = 0; /*the byte comes in from the COM1 port*/
unsigned int buffer = 0;
int output; /*the keyboard*/
int input; /*COM1*/
struct termios newtio; /*settings for the RS-232 "CONSOL"*/
int i = 0;

/*open the input*/
input = open(INPUT, O_RDWR | O_NOCTTY | O_NDELAY);
if(input == -1){
fprintf(stderr, "Fehler beim oeffnen der Seriellen schnittstelle: %s!\n", INPUT);
}/*end if*/

/*open the output*/
output = open(OUTPUT, O_WRONLY);
if(output == -1){
fprintf(stderr, "FEHLER bein oeffnen des outputS: %s!\n", OUTPUT);
return 0;
}/*end if*/

/*configure the RS-232 port*/
fcntl(input, F_SETFL, FNDELAY);
newtio.c_cflag = BAUDRATE | CS8 | CLOCAL | CREAD ;
newtio.c_iflag = IGNPAR | ICRNL ;
newtio.c_oflag = 0;
newtio.c_lflag &= ~(ICANON);

/*set configuration*/
tcflush(input, TCIOFLUSH);
tcsetattr(input, TCSANOW, &newtio);

/*start the main loop*/
while(ENDLOS){
system("clear");
/*read the input*/
recived_bytes = read(input, &inputByte, 4);
/*put the input out on the consol*/
printf("(c)Rainer Sickinger\nGelesenesBytes: 0x%x\n", inputByte);
if(buffer != inputByte){
setLight(output, states[i]);
i++;
if(i == 4) i = 0;
}/*end if*/
buffer = inputByte;
sleep(1);
}/*end while*/

/*close the file deskriptorz*/
close(input);
close(output);

return 0;
}/*end main*/


DANKE nochmal!

stochri
10.01.2006, 17:17
Hallo -linuxuser-,
warum hast Du es noch mal geschrieben, hat sich was geändert ?

Gruss,
stochri

--linuxuser--
10.01.2006, 18:31
O TSCHULDIGUNG ich habe wohl statt auf EDIT auf ZITAT gedrueckt!