IOWarrior 40 Frage zu ReportID und Value

Dies ist das deutsche Forum für alle Themen um den IO-Warrior. Beiträge bitte nur in Deutsch.

Moderator: Guido Körber

Post Reply
Stefanie Eggenstein

IOWarrior 40 Frage zu ReportID und Value

Post by Stefanie Eggenstein »

Hallo,
ich bin ein Neuling in Sachen IOWarrior.
Hier ist folgender Quelltext:
//
// ioblink.cpp - Blinking LEDs sample
//

#include "stdafx.h"
#include "time.h"
#include "iowkit.h"

// Write simple value
BOOLEAN WriteSimple(IOWKIT_HANDLE devHandle, DWORD value)
{
IOWKIT_REPORT rep;

// Init report
rep.ReportID = 0;
rep.Value = 0xFFFFFFFF;

switch (IowKitGetProductId(devHandle))
{
// Write simple value to IOW40
case IOWKIT_PRODUCT_ID_IOW40:
rep.Bytes[3] = (UCHAR) value;
return IowKitWrite(devHandle, IOW_PIPE_IO_PINS,
(PCHAR) &rep, IOWKIT40_IO_REPORT_SIZE) == IOWKIT40_IO_REPORT_SIZE;

default:
return FALSE;
}
}

int main(int argc, char* argv[])
{
IOWKIT_HANDLE iows[IOWKIT_MAX_DEVICES];
int i, j;
ULONG bits;
int numIows;
IOWKIT_REPORT rep;
WCHAR sn[9];
BOOLEAN rc;
DWORD pid;
IOWKIT_HANDLE devHandle;

// Open device
devHandle = IowKitOpenDevice();
if (devHandle == NULL)
{
printf("Failed to open device\n");
goto out;
}
// Get number of IOWs in system
numIows = IowKitGetNumDevs();
printf("%d IOWs in system\n", numIows);
// Get all IOW handles
for (i = 0; i < numIows; i++)
{
// Get device handle and init object
iows = IowKitGetDeviceHandle(i + 1);
// Get serial number
IowKitGetSerialNumber(iows, sn);
pid = IowKitGetProductId(iows);
printf("%d PID %x, S/N \"%ws\"\n", i + 1, pid, sn);
IowKitSetWriteTimeout(iows, 1000);
}
// Init report
// Report ID 0 is for writing to 32 input/output pins
rep.ReportID = 0;

printf("Blinking LEDs...\n");
//srand(time(NULL));
// Blinking'





bits = 16;
rc = WriteSimple(iows[0], bits);
if (!rc)
printf("Cannot write, err %d\n", GetLastError());


printf("Blinking complete\n");


// Set LEDs off
for (i = 0; i < numIows; i++)
//Write to simple endpoint
WriteSimple(iows, 0xFFFFFFFF);


for(i = 0; i < 10; i++)
{

// Read immediate
rc = IowKitReadImmediate(iows[0], &bits);
printf("%d) ReadImm(): rc=%d bits=%x\n", i, rc, bits);
Sleep(100);
}

// Close device
IowKitCloseDevice(devHandle);
out:

return 0;
}


Mit der Funktion WriteSimple übergebe ich einen bestimmten value (hier:16) an den IOWArrior und je nachdem leuchten die LEDs. Im letzten Teil wird mit rc = IowKitReadImmediate(iows[0], &bits) doch abgefragt,wie die Ports im Moment belegt sind,oder?Aber mir ist aufgefallen, dass die Ausgabe sich nach dem rep.Value richtet und nicht nach dem value, dass ich rein gebe.
Also Bsp:
rep.Value = 0xFFFFFF11
bits = 16
Ausgabe nach Readimmediate:
bits = FFFFFF11
wieso nicht bits = FFFFFF10?
Kann mir bitte jemand weiterhelfen?

Gruß
Kann mir jemand weiterhelfen?
Guido Körber
Site Admin
Posts: 2857
Joined: Tue Nov 25, 2003 10:25 pm
Location: Germany/Berlin
Contact:

Post by Guido Körber »

Der IO-Warrior liest den Logikpegel am Pin als Eingang zurück. Da die LEDs in der Sättigung des Ausgangs betrieben werden bleibt die Spannung am Pin so hoch, dass immer eine 1 erkannt wird. Man könnte natürlich Vorwiderstände verwenden, muss man beim IOW40 an Port3 aber nicht.
Post Reply