עבור לתוכן

כתיבה למפתח המקבילי עם C וXP.

Featured Replies

פורסם

שלום!

אני צריך להוציא מידע למפתח המקבילי. הבעיה היא שבXP אי אפשר ליצא מידע למפתח המקבילי.

קראתי פה http://www.galium.co.il/vbe/lpt_1.htm והבנתי שזה כן אפשרי.

וקראתי גם את זה http://logix4u.net/Legacy_Ports/Parallel_Port/How_Inpout32.dll_works_.html

אך לא הבנתי איך להשתמש בהם.

אני משתמש ב visual express.

תודה לעוזרים

פורסם
  • מחבר

ניסיתי כבר אבל יש לי בעיה בקומפילציה.

הורדתי מהלינק שנתנו שמה את Inpout32 Test plus Wrapper Module (ZIP file, 3K) בתיקייה הזאת יש:

שני קבצים .c

קובץ .h

וקובץ .bat

את קובץ ההאדר שמתי ב C:\Program Files\Microsoft Visual Studio\VC98\Include

ובתיקיית הסיסטם שלי שמתי כבר את קובץ ה DLL.

שאני מקמפל את אחד מקבצי הC יש לי את השגיאה הבאה:

inpout32_test.c

c:\documents and settings\moshe\desktop\inpout32_test\inpout32_test.c(50) : warning C4101: 'hLib' : unreferenced local variable

inpout32_test.c

/** @file inpout32_test.c
@brief Test program for inpout32 DLL.

Find more information about Inpout32 at
[url]http://www.logix4u.net/inpout32.htm[/url]

<br> Copyright (C) 2007 Douglas Beattie Jr
<br> [email]beattidp@ieee.org[/email]
<br> [url]http://www.hytherion.com/beattidp/[/url]

@warning
Be sure to change PPORT_BASE (Port Base address)
accordingly if your LPT port is addressed

@note
Last change: DBJR 12/25/2007 7:38:24 PM
*/

/* Known to build successfully with the following
compilers:

[ gcc-MinGW32 ]
gcc.exe ./inpout32_test.c ./inpout32.c -oTEST -I"."

[ Borland C++ 5.5 ]
BCC32 -I. inpout32_test.c inpout32.c

[ Microsoft Visual C++ v6 ]
CL -I. inpout32_test.c inpout32.c
*/

#include <stdio.h>
#include <conio.h>
#include <windows.h>

#include "inpout32.h" // our non-system header in quotes


#define PPORT_BASE ((short) 0x378) //! < CHANGE THIS IF NEEDED !


// Prototypes for Test functions
static void test_read8(void);
static void test_write(void);
static void test_write_datum(short datum);


int main(void)
{
HINSTANCE hLib;

// Attempt to initialize the interface
if (inpout32_init() != 0) {

fprintf(stderr,
"ERROR: Failed to initialize Inpout32 interface!\n");

exit (-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, 0xAA
test_write_datum(0xAA);

/// One more time, different value, 0x33
test_write_datum(0x33);

/// One more time, different value, 0x55
test_write_datum(0x55);

/* finished - unload library and exit */
inpout32_unload();

return 0;
}

/*
TEST: Read inputs of 8 registers from PORT_BASE address
*/
void test_read8(void) {

short x;
short i;

/* Try to read 0x378..0x37F, LPT1: */

for (i=PPORT_BASE; (i<(PPORT_BASE+8)); i++) {

x = Inp32(i);

printf("Port read (%04X)= %04X\n",i,x);
}

return;
}

/*
TEST: Write constant 0x75 to PORT_BASE (Data register)
*/
void test_write(void) {
short x;
short 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%2X\n" ,i ,x);

/// And read back to verify
x = Inp32(i);
printf("Port read (%04X)= %04X\n",i,x);


/// Set all bits high
x=0xFF;
Out32(i,x);

/// Set bi-directional and read again
Out32(PPORT_BASE+2,0x20); // Activate bi-directional
x = Inp32(i);
printf("Set Input, read (%04X)= %04X\n",i,x);

Out32(PPORT_BASE+2,0x00); // Set Output-only again
x = Inp32(i);
printf("Reset Ouput, read (%04X)= %04X\n",i,x);

return;
}

/*
TEST: Write data from parameter
*/
void test_write_datum(short datum) {
short x;
short i;

i=PPORT_BASE;
x = datum;

/***** Write the data register */
Out32(i,x);

printf("Port write to 0x%X, datum=0x%2X\n" ,i ,x);

/***** And read back to verify */
x = Inp32(i);
printf("Port read (%04X)= %04X\n",i,x);

return;
}

ד"א שורה 50 - HINSTANCE hLib;

מה בעיה?

תודה על התמיכה!

פורסם

זה אזהרה, לא שגיאה, על זה שהגדרת משתנה שאתה לא משתמש בו, אתה יכול לשים הערה על משתנים שאתה לא משתמש בהם, אבל זה בכל מקרה לא שגיאה.

פורסם
  • מחבר

כן אבל אחרי הקומפילציה שאני לוחץ Crtl+F5 זה מראה לי את השגיאות הבאות:

Linking...

inpout32_test.obj : error LNK2001: unresolved external symbol _inpout32_unload

inpout32_test.obj : error LNK2001: unresolved external symbol _inpout32_init

inpout32_test.obj : error LNK2001: unresolved external symbol _Inp32

inpout32_test.obj : error LNK2001: unresolved external symbol _Out32

Debug/inpout32_test.exe : fatal error LNK1120: 4 unresolved externals

Error executing link.exe.

inpout32_test.exe - 5 error(s), 0 warning(s)

פורסם

מה כן, מאיפה לנו לדעת אם אתה לא רושם את זה...

בכל מקרה, אתה בטוח שאתה משתמש בפרוייקט דוגמא שלהם של ה VC ? חסר לך לינק בהגדרות פרוייקט לקובץ LIB שאמור להיות באותה תיקיה.

Just go to project properties -> Configuration properties -> Linker.

Goto to ->General and set the "Additional Library directories" to point to your lib file directory.

Then goto to Linker -> Input and type in your lib file name e.g. mystaticlib.lib in the "Additional Dependencies" field

יכול להיות שאת החלק הראשון אתה לא צריך לעשות (אם זה באותה תיקיה). תחפש איפה הקובץ LIB של ה DLL נמצא.

פורסם
  • מחבר

אני די בטוח רשום שם This contains all the test code separated from the wrapper code.

Known to build with gcc MinGW32, Borland v5.5, and Visual C++ v6.

בכל מקרה מצאתי בתיקייה של הDLL קובץ LIB בשם inpout32.lib שמתי אותו בתיקיית הפרויקט שלי אך עדיין אותה שגיאה

פורסם

הכנסת כמו שרמשתי את ה LIB לתוך הגדרות הפרוייקט ?

פורסם
  • מחבר

איך עושים את זה

פורסם

קוראים שוב את מה שרשמתי.

פורסם
  • מחבר

קראתי תודה!

תראה כנראאה שזה קצת שונה אצלי, project properties -> Configuration properties -> Linker.

אין לי את השורות האלה. נכנסתי ל project-- settings--link

Goto to ->General and set the "Additional Library directories" to point to your lib file directory.

general ו input יש אבל אבל תחת general אין לי שורה בשם Additional Library directories אלא בשם library modules ששם שמתי את שם קובץ הlib אך עדיין ישנה שגיאה (עשיתי גם את שלב 2)

ארכיון

דיון זה הועבר לארכיון ולא ניתן להוסיף בו תגובות חדשות.

דיונים חדשים