hi an alle,
danke fuer die antworten:
@supachris and @ wayoda:
zitat:
<
Die Ausgänge des IOW gehen ja schon auf HIGH wenn nur der Rechner eingeschaltet wird. Da dauert es sicher noch mal 20 -30 sekunden bis Linux gebootet ist und das Steuerprogramm läuft
>
- ich kann die strom-versorgung der 2 chips und der servos
ganz einfach spaeter (nach der initialierung des iowarriors)
einschalten
oder:
die unten stehenden erklaerungen: (softwaere-maessig) mit (**)
bezeichnet.
das erstaunt mich auch aber ......
hier die ersten ergebnisse meiner heutigen versuche
mit ioWarriorWrite_13a.c
Ergebnisse:
- mit den tips von herrn jung
- if(command == n) ersetzt durch switch, case
- report56.ReportID = 0x00;
nach einigen HickHacks:
run ioWarriorWrite_13a.c mit mehreren durchlaeufen:
- 5.versuch: durchlauf: port[0] all bits from 0 to 7
ergebnisse: (**)
-> status after Init & Open & ClearAllPort == status of all Ports == OFF
-> input command 1 == port0 = 0x00000001 = ok
-> input command 2 == port0 = 0x00000010 = ok
-> input command 3 == port0 = 0x00000011 = ok
-> input command 4 == port0 = 0x00000100 = ok
-> input command 5 == port0 = 0x00000101 = ok
-> input command 6 == port0 = 0x00000110 = ok
-> input command 7 == port0 = 0x00000111 = ok
(**)
-> after command 0 == exit & closedDevice == AllPorts == OFF
-> keine haenger, keine fehlermeldungen.
Also in meinen Augen ein guter 1.Erfolg, es funzzt ;-)
Was mir aufgefallen ist (Ungereihmheiten):
(**)
1) wenn ioWarrioWrite_13a.c mehrmals hintereinander aufgerufen wird:
sind die outports auf <OFF> ,
getestet mit port[0] bit 0
was in meinen augen sehr OK ist
2) wenn zwischendurch euer urspruengliche iowkittest.c aufgerufen wird:
sind die outports auf <ON> getestet mit port[0] bit 0
3) in der funktio WritePorts() und in main() after while rufe ich jeweils
folgende statements auf
Code: Select all
res=IowKitWrite(ioHandle, IOW_PIPE_IO_PINS, (PCHAR)&report56, IOWKIT56_IO_REPORT_SIZE);
if(res!=IOWKIT56_IO_REPORT_SIZE)
{
printf("Ein Fehler ist aufgetreten! Bitte erneut versuchen!");
goto out;
}
// usleep(1000000); // wait 1 sec
// Nun alle reports aus dem internen puffer lesen, Taster
// drücken und loslassen sollte auch irgendwann dabei sein
while(IowKitReadImmediate(ioHandle, &bits))
{
gotoxy(5,21);
printf("Read\n");
// Fehler <%x> printf("Bits: %x",bits);
// compile fehler: warning : format '%x' expects type
// unsigned int, but argument 2 has type 'DWORD'
}
folgende ergebnisse:
1) es wird niemals in <while(IowKitReadImmediate(ioHandle, &bits))>
gesprungen.
- "Read" erscheint nicht auf console???
Frage:
1) sind diese beiden statements fuer mein programm ueberhaupt notwendig????
2) mach ich da einen denkfehler??? und bin bloed ;-)
3) falls diese statements notwendig sind:
- wie haengt das alles zusammen???
- wuerde es mich sehr interessieren wie die formatierungs-anweisung
fuer 'DWORD' lauten wuerde??
hab nichts gefunden deswegen das printf mit Read.
auch in keinem lehrbuch.
untenstehend der neueste code.
und fuer hinweise bin ich dankbar.
ps: @herr jung:
- die 'gotos' werden noch rausgenommen.
- wegen den gotoxy(n,n); dafuer ist der consolen-output uebersichtlich
gruss
stephan
Code: Select all
// ioWarriorWrite_13a.c
// --------------------
// compile with :
// gcc -Wall -g -liowkit ioWarriorWrite_13a.c -o ioWarriorWrite_13a
//
// start with : ./ioWarriorWrite_13a
/**************************************************************************/
#include "iowkit.h"
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <fcntl.h>
#include <string.h>
#include <ctype.h>
#include <setjmp.h>
#include <unistd.h>
#include <sys/signal.h>
#include <sys/types.h>
#include <errno.h>
#define _POSIX_SOURCE 1 // POSIX compliant source
#define FALSE 0
#define TRUE 1
typedef unsigned char byte;
int STOP=FALSE;
int command;
int i;
int cnt;
IOWKIT_HANDLE iows[IOWKIT_MAX_DEVICES];
int i, j;
ULONG bits;
int numIows;
unsigned short sn[9];
char snt[9];
ULONG rc;
DWORD pid;
IOWKIT_HANDLE ioHandle;
IOWKIT56_IO_REPORT report56;
ULONG res;
DWORD bits;
ULONG bitsPattern0 = 1; // 0x00000001
ULONG bitsPattern1 = 2; // 0x00000010
ULONG bitsPattern3 = 3; // 0x00000011
ULONG bitsPattern4 = 4; // 0x00000100
ULONG bitsPattern5 = 5; // 0x00000101
ULONG bitsPattern6 = 6; // 0x00000110
ULONG bitsPattern7 = 7; // 0x00000111
ULONG bitsPattern;
/***************************************************************************/
// delay (nnn)
void delay(long millisek)
{
int mikrosek = millisek*1000;
struct timeval timeout;
timeout.tv_sec = mikrosek / 1000000L;
timeout.tv_usec = mikrosek % 1000000L;
select(0, NULL, NULL, NULL, &timeout);
}
void gotoxy(int x, int y) { printf("\033[%d;%dH", y, x); fflush(stdout); }
void clrscr(void) { printf("\033[H\033[J"); fflush(stdout); }
/****************************************************************************/
int initIO_device()
{
gotoxy(5,2);
printf("Starting Initialitions and open Device\n");
ioHandle = IowKitOpenDevice(); // Öffnen der Device
if(ioHandle!=NULL)
{
if(IowKitGetProductId(ioHandle)==IOWKIT_PRODUCT_ID_IOW56)
{
gotoxy(5,3);
printf("IO-Warrior 56 gefunden");
}
}
else
{
printf("IO-Warrior nicht gefunden!");
goto out;
}
gotoxy(5,4);
printf("Version: %s\n",IowKitVersion());
report56.ReportID=0x00; // ermoeglicht write
gotoxy(5,5);
printf("Clear Ports\n");
//clear all ports
for(cnt = 0; cnt <= 7; cnt++)
{
report56.Bytes[cnt] = 0x00000000;
}
gotoxy(5,6);
printf("Clear All Ports Clear is Done\n");
usleep(1000000); // wait 2 secs
out:
return 0;
}
/************************************************************************************/
int setAllPortsOff()
{
gotoxy(5,10);
printf("Clear Ports\n");
report56.ReportID=0x00;
//clear all ports
for(cnt = 0; cnt <= 7; cnt++)
{
report56.Bytes[cnt] = 0x00000000; // old 255; // bin:0x00000000; or dec 0
}
gotoxy(5,11);
printf("Clear All Ports Clear is Done\n");
usleep(1000000); // wait 1 secs
return 0;
}
/************************************************************************************/
int inputCommand()
{
gotoxy(5,7);
printf("Set Bits-Command: \n");
gotoxy(30,7);
scanf("%d",&command);
gotoxy(30,7);
// printf(" ");
bitsPattern = 0; // da nach durchlaeufen ev. noch was drinn
switch(command)
{
case 0:
// exit do nothing
break;
case 1:
bitsPattern = bitsPattern0; // = 0x00000001 = dec 1
break;
case 2:
bitsPattern = bitsPattern1; // = 0x00000010 = dec 2
break;
case 3:
bitsPattern = bitsPattern3; // = 0x00000011 = dec 3
break;
case 4:
bitsPattern = bitsPattern4; // = 0x00000100 = dec 4
break;
case 5:
bitsPattern = bitsPattern5; // = 0x00000101 = dec 5
break;
case 6:
bitsPattern = bitsPattern6; // = 0x00000110 = dec 6
break;
case 7:
bitsPattern = bitsPattern7; // = 0x00000111 = dec 7
break;
case 8:
// nothing
break;
case 9:
// nothing
break;
default:
break;
}
gotoxy(35,8);
printf("Input: Command: %d BitsPattern: %ld\n",command,bitsPattern);
usleep(1000000); // wait 1 sec
gotoxy(5,9);
printf(" ");
setAllPortsOff();
return 0;
}
/************************************************************************************/
int writePorts()
{
// set pipe 0
report56.ReportID=0x00;
// Set port-bits
report56.Bytes[0] = bitsPattern; // port0 write
report56.Bytes[1] = 1; // port1 write
report56.Bytes[2] = 1; // port2 write
report56.Bytes[3] = 1; // port3 write
report56.Bytes[4] = 1; // port4 write (uninteressant)
report56.Bytes[5] = 1; // port5 write (uninteressant)
gotoxy(5,12);
printf("Setzen des Port 0 mit %d\n",report56.Bytes[0]);
gotoxy(5,13);
printf("Setzen des Port 1 mit %d\n",report56.Bytes[1]);
gotoxy(5,14);
printf("Setzen des Port 2 mit %d\n",report56.Bytes[2]);
gotoxy(5,16);
printf("Setzen des Port 3 mit %d\n",report56.Bytes[3]);
gotoxy(5,17);
printf("Setzen des Port 4 mit %d\n",report56.Bytes[4]);
gotoxy(5,18);
printf("Setzen des Port 5 mit %d\n",report56.Bytes[5]);
res=IowKitWrite(ioHandle, IOW_PIPE_IO_PINS, (PCHAR)&report56, IOWKIT56_IO_REPORT_SIZE);
if(res!=IOWKIT56_IO_REPORT_SIZE)
{
printf("Ein Fehler ist aufgetreten! Bitte erneut versuchen!");
goto out;
}
// HERE IMPULS-DAUER -> for tests to control the output-pins setting on 30 secs
usleep(30000000); // wait 30 secs
// set pipe 0
report56.ReportID = 0x00;
// Zurück-Setzen der Portbits
// clear all ports
for(cnt = 0; cnt <= 7; cnt++)
{
report56.Bytes[cnt] = 0x00000000;
}
gotoxy(5,19);
printf("Clear All Ports after Write is Done\n");
res=IowKitWrite(ioHandle, IOW_PIPE_IO_PINS, (PCHAR)&report56, IOWKIT56_IO_REPORT_SIZE);
if(res!=IOWKIT56_IO_REPORT_SIZE)
{
printf("Ein Fehler ist aufgetreten! Bitte erneut versuchen!");
goto out;
}
// usleep(1000000); // wait 1 sec
// Nun alle reports aus dem internen puffer lesen, Taster
// drücken und loslassen sollte auch irgendwann dabei sein
while(IowKitReadImmediate(ioHandle, &bits))
{
gotoxy(5,21);
printf("Read\n");
// Fehler <%x> printf("Bits: %x",bits);
// compile fehler: warning : format '%x' expects type
// unsigned int, but argument 2 has type 'DWORD'
}
out:
return 0;
}
/************************************************************************************/
int main(int argc, char* argv[])
{
clrscr();
gotoxy(5,1);
printf("The IO_WarriorWrite Version 0.13a. (c) 2007 RCI\n");
initIO_device();
do
{
// nowSetting Ports for test only Port 0
inputCommand();
if(command > 0)
{
writePorts();
}
}while(command > 0); // end while
gotoxy(5,20);
printf("Outside while: Bitte Taster betätigen!\n");
usleep(2000000); //2 sekunden zeit zum drücken
// Nun alle reports aus dem internen puffer lesen, Taster
// drücken und loslassen sollte auch irgendwann dabei sein
while(IowKitReadImmediate(ioHandle, &bits))
{
gotoxy(5,21);
printf("Read\n");
// Fehler <%x> printf("Bits: %x",bits);
// compile fehler: warning : format '%x' expects type
// unsigned int, but argument 2 has type 'DWORD'
}
IowKitCloseDevice(ioHandle);
usleep(1000000); // wait 1 sec
gotoxy(5,22);
printf("IO-WarriorDevice is closed and Exit, ....Bye\n");
return 0;
}
/***********************************************************************************************/