Parallel Port Pin setzten

Gast #1351022
Lesenswert?

ups stimmt.

der code kann aber leider nicht kompiliert werden :(
folgende Fehler erscheinen:
1
bt Desktop # cc -o io1 io.c
2
io.c:7: warning: data definition has no type or storage class
3
io.c:7: error: initializer element is not constant
4
io.c:10: error: expected identifier or '(' before 'while'
5
io.c:15: warning: data definition has no type or storage class
6
io.c:15: warning: parameter names (without types) in function declaration
Gast #1351032
Lesenswert?

oh es hat ja main() gefehlt :D

jetzt kommt nur noch folgender Fehler:

io.c:7: error: initializer element is not constant

bei folgendem Code:
1
#include <unistd.h>
2
#include <sys/types.h>
3
#include <sys/stat.h>
4
#include <fcntl.h>
5

6
fd = open("/dev/parport0", O_WRONLY | O_APPEND);
7

8
int main() {
9

10
char on = 0xFF;
11
char off = 0;
12
while (1) {
13
  write(fd, &on, 1);
14
  usleep (233);
15
  write (fd, &off, 1);
16
  sleep (233);
17
} close(fd);
18

19

20
}
Persönliche Seite #1351039
Lesenswert?

Der Code ist auch nicht vollständig, da muss noch eine Funktion 
drumherum, z.B.:
1
#include <unistd.h>
2
#include <sys/types.h>
3
#include <sys/stat.h>
4
#include <fcntl.h>
5
#include <signal.h>
6

7
int want_quit;
8

9
void on_sig_int (int sig) {
10
  want_quit = 1;
11
}
12

13
int main(int argc, char* argv[]) {
14
  fd = open("/dev/parport0", O_WRONLY | O_APPEND);
15
  char on = 0xFF;
16
  char off = 0;
17
  want_quit = 0;
18
  signal (SIGINT, on_sig_quit);
19
  while (want_quit == 0) {
20
    write(fd, &on, 1);
21
    usleep (233);
22
    write (fd, &off, 1);
23
    sleep (233);
24
  }
25
  close(fd);
26
}
Mit dem signal-Handler wird die Schnittstelle auch ordentlich 
geschlossen, wenn man Strg+C drückt. Nicht zwangsweise nötig, aber 
sauberer programmiert.
Gast #1351059
Lesenswert?

Auch dieser Code funktioniert nicht :(

io.c: In function 'main':
io.c:14: error: 'fd' undeclared (first use in this function)
io.c:14: error: (Each undeclared identifier is reported only once
io.c:14: error: for each function it appears in.)
io.c:18: error: 'on_sig_quit' undeclared (first use in this function)
io.c:26:2: warning: no newline at end of file
Gast #1351066
Lesenswert?

Sei so lieb und lerne ein bisschen C.
Das ist nicht böß gemeint, aber die Fehler oben drin sind trivial,
wenn du das Programm später erweitern willst brauchst du das Wissen:
1
#include <unistd.h>
2
#include <sys/types.h>
3
#include <sys/stat.h>
4
#include <fcntl.h>
5
#include <signal.h>
6

7
int want_quit;
8

9
void on_sig_quit (int sig) {
10
  want_quit = 1;
11
}
12

13
int main(int argc, char* argv[]) {
14
  FILE fd = open("/dev/parport0", O_WRONLY | O_APPEND);
15
  char on = 0xFF;
16
  char off = 0;
17
  want_quit = 0;
18
  signal (SIGINT, on_sig_quit);
19
  while (want_quit == 0) {
20
    write(fd, &on, 1);
21
    usleep (233);
22
    write (fd, &off, 1);
23
    sleep (233);
24
  }
25
  close(fd);
26
}
Gast #1351785
Lesenswert?

Rolf Magnus schrieb:
>> Und dann bitte noch sicherheitshalber ein volatile vor want_quit...
>
> Eigentlich sollte es eher vom Typ sig_atomic_t sein. Den gibt's nämlich
> genau für solche Variablen.

Interessanterweise ist sig_atomic_t alleine aber nicht volatile :-)
Also:
1
volatile sig_atomic_t xxx;
Gast #1351809
Lesenswert?

atomic ist ja wohl etwas übertriben, bei einem int gibt es keinen 
ungültigen zwischenwert bei gleichzeitigen zugriff.

volatil habe ich auf einem PC auch noch nie genutzt, ging bis jetzt auch 
immer. könnte aber daran liegen das die schleifen meist etwas mehr 
inhalt hatten und auf dem PC weniger Register vorhanden sind.
Gast #1357552
Lesenswert?

Peter schrieb:
> atomic ist ja wohl etwas übertriben, bei einem int gibt es keinen
> ungültigen zwischenwert bei gleichzeitigen zugriff.

Auch wenn der int nicht korrekt aligned ist auf ner 32bit Maschine?
Gast #1357783
Lesenswert?

Rolf Magnus schrieb:
>> Auch wenn der int nicht korrekt aligned ist auf ner 32bit Maschine?
>
> Wenn er das ist, ist was falsch gelaufen.

Nun ja gibt ja durchaus Architekturen die kein zwingendes Alignment 
voraussetzen

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren