hi,
entschuldigt wenn ich euch schon wieder nerve.
bei mir gehts jetzt um die programmierung eines ersten c-testprogramms
unter linux fuer den iowarrior56.
ich habe gestern im forum, alles durchforstet was fuer eine c-programm
relevant ist.
da ich im forum keine progs speziell fuer linux gefunden habe (nur windows-prog)
habe ich das untenstehende c-prog geschrieben, es kann compiliert werden,
ist aber noch nicht getestet.
werde das heute machen.
Funktion des Programms:
- setzen der bits in einem port (input)
- iowarrior-simpleWrite
- zuruecksetzen aller ports auf <0>
Was ich herausgefunden habe:
1) es werden alle ports (also port0 bis port6) == 7 bytes == 56 bits auf einmal gesetzt
2) das schreiben (write) auf die ports erfolgt fortlaufend beginnend mit port0 bis port6
Grundlagen:
1) in meiner anwendung wird nur geschrieben (ouput)
es ist keine rueckmeldung des iowarrior erforderlich.
2) da ich insgesammt 32 output-bits benoetige,
werden nur port0 bis port3 benutzt. also 4 bytes.
Dazu einige Fragen:
1) um die ports zu testen, wuerde ich gerne eine led-reihe
an die entsprechenden ports anschliessen.
ist das problemlos moeglich?
2) ist das programm ueberhaupt korrekt:
3) im posting "IO-Warrior Ports einzeln ansteuern...
(32 Bit/ULONG)" vom 4.11.2006 von CCrueger
== taucht folgende bemerkung auf:
<Wenn du alle Porte beschreiben willst, muss du die funktion ändern
oder gleich mit IowKitWrite() arbeiten.
da kannst du dann report.Byte[0] bis report.Byte[3] selber setzten,
wenn du alle Ports bewchreiben willst.>
- heisst dass nun: dass report.Byte[0] den Port 0 bis report.Byte[3] den port 3
anspricht
- kann ich da also wenn ich report.Byte[0] anspreche auch gleichzeit die bits setzen?
- beispiel: ULONG bitsPattern0 = 0x10101010
- ich waere froh, wenn ich von Ihnen ein kleines Code-schnippsel bekommen
koennte.
die diese funktion kurz umreist
4) oder waere es sinnvoller das schreiben aller 6 ports wie folgt vorzunehmen:
(port5 port4 port3 port2 port1
-> ULONG bitPorts = 0x 00000000 00000000 10101010 01010101 11110000
port0)
00001111
- port3 - port0 werden von mir benutzt.
(die aufteilung in 8bit seqmente dient nur zur uebersichtlichkeit)
so, das waers fuers erste.
ueber jede hilfe, hinweise, tips und korrekturen wuerde ich mich sehr freuen.
ich brauch im grunde genommen nur einen grundstock, damit ich in den naechsten
tagen das programm weiter entwickeln und testen kann.
hier nun der c-code:
Code: Select all
//=========================================================================//
// ioWarriorWrite_10.c
// --------------------------------
// compile with :
// gcc -Wall -g -liowkit ioWarriorWrite_10.c -o ioWarriorWrite_10
//
// start with : ./ioWarriorWrite_10
//
//****************************************************************************/
#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;
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 devHandle;
IOWKIT56_IO_REPORT report56;
ULONG bitsPattern0 = 0x00000001;
ULONG bitsPattern1 = 0x00000010;
ULONG bitsPattern2 = 0x00000100;
ULONG bitsPattern3 = 0x00000011;
ULONG bitsPattern4 = 0x00000111;
ULONG bitsPattern5 = 0x00000110;
ULONG bitsPattern6 = 0x00000101;
ULONG bitsPattern;
/***************************************************************************/
// from conio.h
// 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); }
/******************************************************************************/
// Write simple value
BOOLEAN WriteSimple(IOWKIT_HANDLE devHandle, DWORD value)
{
// Init report
switch(IowKitGetProductId(devHandle))
{
// Write simple value to IOW56
case IOWKIT_PRODUCT_ID_IOW56:
memset(&report56, 0xff, sizeof(report56));
report56.ReportID = 0;
report56.Bytes[6] = (UCHAR) value;
return IowKitWrite(devHandle, IOW_PIPE_IO_PINS,
(PCHAR) &report56, IOWKIT56_IO_REPORT_SIZE) ==
IOWKIT56_IO_REPORT_SIZE;
default:
return FALSE;
}
}
int initIO_device()
{
devHandle = IowKitOpenDevice();
if(devHandle == NULL)
{
printf("Failed to open device\n");
goto out;
}
else
{
gotoxy(5,2);
printf("Open Device is Done\n");
}
// Get number of IOWs in system
numIows = IowKitGetNumDevs();
gotoxy(5,3);
printf("%d IOWs in system\n", numIows);
// Get all IOW handles
for(i = 0; i < numIows; i++)
{
// Get device handle and init object
iows[i] = IowKitGetDeviceHandle(i + 1);
// Get serial number
IowKitGetSerialNumber(iows[i], sn);
pid = IowKitGetProductId(iows[i]);
for(j = 0; j < 9; j++)
{
snt[j] = sn[j];
// printf("%d PID %x, S/N \"%s\"\n", i + 1, (unsigned int) pid, snt);
}
IowKitSetWriteTimeout(iows[i], 1000);
}
gotoxy(5,4);
printf("Initialitions is Done\n");
out:
return(0);
}
void setAllPortsOff()
{
gotoxy(5,8);
printf("Set all Ports off\n");
for(i = 0; i < numIows; i++)
{
// Write to simple endpoint
WriteSimple(iows[i], 0xFFFFFFFF);
usleep(20000);
}
usleep(1000000);
gotoxy(5,8);
printf(" ");
}
int writePorts()
{
gotoxy(5,9);
printf("Write Port\n");
report56.ReportID=0;
// Setzen der Portbits
report56.Bytes[3] = 4;
gotoxy(5,10);
printf("Setzen des Port 3 mit %d\n", report56.Bytes[3]);
// Write to simple endpoint
// only 1 devices
// set manuell the bitPattern 0 to 7
rc = WriteSimple(iows[0], bitsPattern);
usleep(20000);
// Sleep for 250ms
usleep(250000);
gotoxy(5,11);
printf("Set_Bits complete\n");
usleep(1000000);
gotoxy(5,9);
printf(" ");
gotoxy(5,10);
printf(" ");
gotoxy(5,11);
printf(" ");
return 0;
}
int inputCommand()
{
gotoxy(5,6);
printf("Set Bits-Command: \n");
gotoxy(30,6);
scanf("%d",&command);
gotoxy(30,6);
printf(" ");
if(command==0) IowKitCloseDevice(devHandle);
if(command==1) bitsPattern = bitsPattern0; // = 0x00000001
if(command==2) bitsPattern = bitsPattern1; // = 0x00000010
if(command==3) bitsPattern = bitsPattern2; // = 0x00000100
if(command==4) bitsPattern = bitsPattern3; // = 0x00000011
if(command==5) bitsPattern = bitsPattern4; // = 0x00000111
if(command==6) bitsPattern = bitsPattern5; // = 0x00000110
if(command==7) bitsPattern = bitsPattern6; // = 0x00000101
// if(command==8)
// if(command==9)
gotoxy(5,7);
printf(" %ld\n",bitsPattern);
setAllPortsOff();
return 0;
}
int main(int argc, char* argv[])
{
clrscr();
gotoxy(5,1);
printf("The IO_WarriorWrite Version 0.10. \n");
// Open ioWarrior-Device
initIO_device();
do
{
inputCommand();
writePorts();
}while(command > 0);
// Close device
// IowKitCloseDevice(devHandle);
// out:
gotoxy(5,15);
printf("IO-Warrior56 Device is closed, and Exit, Bye...\n");
return 0;
}
/*******************************************************************************/