CLR: .Net / Mono / Boo / Otros CLR > Otros CLR
Código a C++
Meta:
Outport(0x3f8,55);
int valor=Input(0x3f8);
No entiendo lo del 3F8. ¿No será 378?
En cuanto al 55. ¿Qué significa el 55?
El 378 es la dirección.
Puse algo así:
--- Código: C++ --- #include "StdAfx.h"#include "PortInterop.h" PortInterop::PortInterop(void){ Outport(0x378,55); int valor=Input(0x378);}
ME dice esto:
--- Citar --------- Operación Generar iniciada: proyecto: Puerto Paralelo cpp, configuración: Debug Win32 ------
PortInterop.cpp
PortInterop.cpp(6): error C3861: 'Outport': no se encontró el identificador
PortInterop.cpp(8): error C3861: 'Input': no se encontró el identificador
========== Generar: 0 correctos, 1 incorrectos, 0 actualizados, 0 omitidos ==========
--- Fin de la cita ---
En C#, al hacer doble click en el botón, podemos ver el código fuente que es este:
--- Código: C# --- private void button_D0_ON_Click(object sender, EventArgs e) { D0 = 1; opciones(); }
--- Código: C# --- #region Opciones. public void opciones() { int value = 0; if (D0 == 1) { value += (int)Math.Pow(2, 0); LoadNewPict_D0(); } else LoadOldPict_D0(); value += 0; if (D1 == 1) { value += (int)Math.Pow(2, 1); LoadNewPict_D1(); } else LoadOldPict_D1(); value += 0; if (D2 == 1) { value += (int)Math.Pow(2, 2); LoadNewPict_D2(); } else LoadOldPict_D2(); value += 0; if (D3 == 1) { value += (int)Math.Pow(2, 3); LoadNewPict_D3(); } else LoadOldPict_D3(); value += 0; if (D4 == 1) { value += (int)Math.Pow(2, 4); LoadNewPict_D4(); } else LoadOldPict_D4(); value += 0; if (D5 == 1) { value += (int)Math.Pow(2, 5); LoadNewPict_D5(); } else LoadOldPict_D5(); value += 0; if (D6 == 1) { value += (int)Math.Pow(2, 6); LoadNewPict_D6(); } else LoadOldPict_D6(); value += 0; if (D7 == 1) { value += (int)Math.Pow(2, 7); LoadNewPict_D7(); } else LoadOldPict_D7(); value += 0; try { Puerto_paralelo.PortInterop.Output(adress, value); } catch (DllNotFoundException) { Alerta_1(); } } #endregion
EDITO:
Estoy viendo el Test2.c y me sale esto:
--- Citar ---/**************************************************/ /*** ***/ /*** Test2.c -- test interface to inpout32.dll ***/ /*** ( http://www.logix4u.net/inpout32.htm ) ***/ /*** ***/ /*** Copyright (C) 2005, Douglas Beattie Jr. ***/ /*** ***/ /*** ***/ /*** http://www.hytherion.com/beattidp/ ***/ /*** ***/ /**************************************************/ /* Last Update: 2006.05.14 */ /*******************************************************/ /* */ /* Builds with Borland's Command-line C Compiler */ /* (free for public download from Borland.com, at */ /* http://www.borland.com/bcppbuilder/freecompiler ) */ /* */ /* Compile with: */ /* */ /* BCC32 -IC:BORLANDBCC55INCLUDE TEST2.C */ /* */ /* */ /* Be sure to change PPORT_BASE (Port Base address) */ /* accordingly if your LPT port is addressed */ /* elsewhere. */ /* */ /*******************************************************/ #include #include #include /* Definitions in the build of inpout32.dll are: */ /* short _stdcall Inp32(short PortAddress); */ /* void _stdcall Out32(short PortAddress, short data); */ /* prototype (function typedef) for DLL function Inp32: */ typedef short (_stdcall *inpfuncPtr)(short portaddr); typedef void (_stdcall *oupfuncPtr)(short portaddr, short datum); #define PPORT_BASE 0x378 // Prototypes for Test functions void test_read8(void); void test_write(void); void test_write_datum(short datum); /* After successful initialization, these 2 variables will contain function pointers. */ inpfuncPtr inp32fp; oupfuncPtr oup32fp; /* Wrapper functions for the function pointers - call these functions to perform I/O. */ short Inp32 (short portaddr) { return (inp32fp)(portaddr); } void Out32 (short portaddr, short datum) { (oup32fp)(portaddr,datum); } int main(void) { HINSTANCE hLib; short x; int i; /* Load the library */ hLib = LoadLibrary("inpout32.dll"); if (hLib == NULL) { fprintf(stderr,"LoadLibrary Failed.n"); return -1; } /* get the address of the function */ inp32fp = (inpfuncPtr) GetProcAddress(hLib, "Inp32"); if (inp32fp == NULL) { fprintf(stderr,"GetProcAddress for Inp32 Failed.n"); return -1; } oup32fp = (oupfuncPtr) GetProcAddress(hLib, "Out32"); if (oup32fp == NULL) { fprintf(stderr,"GetProcAddress for Oup32 Failed.n"); return -1; } /*******************************************************/ /** IF WE REACHED HERE, INITIALIZED SUCCESSFUL ******/ /*******************************************************/ /* now test the functions */ /***** Read 8 bytes at I/O base address */ test_read8(); /***** Write 0x75 to data register and verify */ test_write(); /***** One more time, different value */ test_write_datum(0xAA); /* finished - unload library and exit */ FreeLibrary(hLib); return 0; } /* TEST: Read inputs of 8 registers from PORT_BASE address */ void test_read8(void) { short x; int i; /* Try to read 0x378..0x37F, LPT1: */ for (i=PPORT_BASE; (i<(PPORT_BASE+8)); i++) { x = Inp32(i); printf("Port read (%04X)= %04Xn",i,x); } } /* TEST: Write constant 0x77 to PORT_BASE (Data register) */ void test_write(void) { short x; int i; /***** Write the data register */ i=PPORT_BASE; x=0x75; /***** Write the data register */ Out32(i,x); printf("Port write to 0x%X, datum=0x%2Xn" ,i ,x); /***** And read back to verify */ x = Inp32(i); printf("Port read (%04X)= %04Xn",i,x); /***** Set all bits high */ x=0xFF; Out32(i,x); /***** Now, set bi-directional and read again */ Out32(PPORT_BASE+2,0x20); // Activate bi-directional x = Inp32(i); printf("Set Input, read (%04X)= %04Xn",i,x); Out32(PPORT_BASE+2,0x00); // Set Output-only again x = Inp32(i); printf("Reset Ouput, read (%04X)= %04Xn",i,x); } /* TEST: Write data from parameter */ void test_write_datum(short datum) { short x; int i; i=PPORT_BASE; x = datum; /***** Write the data register */ Out32(i,x); printf("Port write to 0x%X, datum=0x%2Xn" ,i ,x); /***** And read back to verify */ x = Inp32(i); printf("Port read (%04X)= %04Xn",i,x); }
--- Fin de la cita ---
Voy a investigar el enlace a ver que tal. Recuerda que uso el Visual C++ 2010.
Eternal Idol:
Ah, es .NET y no C++, entonces lo muevo a donde corresponde.
Meta:
Puede descargar el cósigo fuente del C# completo y funcionamuy bien. Se incluye la librería inpout32.dll.
Navegación
[*] Página Anterior
Ir a la versión completa