Hallo,
habe ein Projekt bezüglich Optischer Kommunikation. Mein Problem ist, das auf der Senderseite (IO4 Bricklet) die Übertragung nicht funktioniert. Das ganze ist und muss in C geschrieben sein!
Der Compiler erkennt nicht die Funktion um den Port 0 auf High/Low zusetzen. Kann mir jemand da weiter helfen?
Der C-Code an sich müsste passen. Wenn ich anstatt der µC Befehle einfach eine Textausgabe, z.B. "Licht an" machen funktioniert es.
Ich hoffe jemand kann mir weiter helfen...
Gruß Alex
Hier der Code:
#include <stdio.h>
#include <time.h> // Wichtig für Clocks per Sec und Sleep!!!!
#include <unistd.h>
#include "ip_connection.h"
#include "bricklet_io4.h"
#define HOST "localhost"
#define PORT 4223
#define UID "9VU" // Change to your UID
sendByte (char c){
io4_set_configuration(&io, 1<<0, 'o', true);
usleep(600000);
int i = 0;
for (i=0; i<8; i++) {
if (c & (i<<1)) {
io4_set_configuration(&io, 1<<0, 'o', true);
usleep(300000);
}
else {
io4_set_configuration(&io, 1<<0, 'o', false);
usleep(300000);
}
}
io4_set_configuration(&io, 1<<0, 'o', false);
usleep(600000);
}
void send(char *c)
{
while (*c != 0) {
sendByte(*c);
c++;
}
}
int main() {
// Don't use device before ipcon is connected
// Hauptprogramm
// Create IP connection
IPConnection ipcon;
ipcon_create(&ipcon);
// Create device object
IO4 io;
io4_create(&io, UID, &ipcon);
//Connect to brickd
if(ipcon_connect(&ipcon, HOST, PORT) < 0) {
fprintf(stderr, "Could not connect\n");
exit(1);
}
send("B");
printf("Press key to exit\n");
getchar();
ipcon_destroy(&ipcon); // Calls ipcon_disconnect internally
}