Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 #include <iostream> #include <windows.h> const int LPT1 = 0x378; //lpt1 address typedef short _stdcall (*PtrInput)(short EndPorta); typedef void _stdcall (*PtrOutput)(short EndPorta, short value); PtrInput InPortB = NULL; PtrOutput OutPortB = NULL; HINSTANCE hLib = NULL; void LoadDLL(); int main (int argc, char *args[]) { LoadDLL(); // function to load the dll file OutPortB(LPT1, 0); // function to write values short value = InPortB(LPT1); // function to read values, variable 'value' will receive the value return 0; } void LoadDLL() { hLib = LoadLibrary("inpout32.dll"); if (hLib == NULL) { std::cout << "cant load the .dll file\n"; system("PAUSE"); exit(1); } InPortB = (PtrInput) GetProcAddress(hLib, "Inp32"); if (InPortB == NULL) { std::cout << "error in inicialization of inportb\n"; system("PAUSE"); exit(1); } OutPortB = (PtrOutput) GetProcAddress(hLib, "Out32"); if (OutPortB == NULL) { std::cout << "error in inicialization of outportb\n"; system("PAUSE"); exit(1); } }
how is your c programming skills?
I wrote, long time ago, a program that write values on parrallel port... never tried to read, but seems to be very similar.
take a look at this link: **broken link removed**
and here is my old code for a 32bits OS (windows):
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 #include <iostream> #include <windows.h> const int LPT1 = 0x378; //lpt1 address typedef short _stdcall (*PtrInput)(short EndPorta); typedef void _stdcall (*PtrOutput)(short EndPorta, short value); PtrInput InPortB = NULL; PtrOutput OutPortB = NULL; HINSTANCE hLib = NULL; void LoadDLL(); int main (int argc, char *args[]) { LoadDLL(); // function to load the dll file OutPortB(LPT1, 0); // function to write values short value = InPortB(LPT1); // function to read values, variable 'value' will receive the value return 0; } void LoadDLL() { hLib = LoadLibrary("inpout32.dll"); if (hLib == NULL) { std::cout << "cant load the .dll file\n"; system("PAUSE"); exit(1); } InPortB = (PtrInput) GetProcAddress(hLib, "Inp32"); if (InPortB == NULL) { std::cout << "error in inicialization of inportb\n"; system("PAUSE"); exit(1); } OutPortB = (PtrOutput) GetProcAddress(hLib, "Out32"); if (OutPortB == NULL) { std::cout << "error in inicialization of outportb\n"; system("PAUSE"); exit(1); } }
in this case I use the inpout32.dll for a 32 bits windows, if you will use a 64 bits windows you have to download the Inpoutx64.dll ( you can find it in the link above ).
the dll file must be in the same dir as your compiled program.
if you have any questions, just ask!
Iuri~
news? have you found the things i told you? questions? doubts? just let me know
Iuri~
news? have you found the things i told you? questions? doubts? just let me know
Iuri~
Code C++ - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 #include <iostream> #include <windows.h> const int LPT1_DATA_REGISTER = 0x378; //WRITE (pins D0, D1, D2, D3, D4, D5, D6, D7) const int LPT1_STATUS_REGISTER = 0x379; //READ (pins BUSY, ACK, PAPER END, SLCT OUT, ERROR) typedef short _stdcall (*PtrInput)(short EndPorta); typedef void _stdcall (*PtrOutput)(short EndPorta, short valor); PtrInput InPortB = NULL; PtrOutput OutPortB = NULL; HINSTANCE hLib = NULL; void LoadDLL(); int main (int argc, char *args[]) { LoadDLL(); unsigned char value = InPortB(LPT1_STATUS_REGISTER); // first value acquired std::cout << "First value acquired: " << value << "\n"; while ( true ) { unsigned char newValue = InPortB(LPT1_STATUS_REGISTER); // read the new value if ( value == newValue ) // check if the value has changed { std::cout << "New value received (decimal): " << newValue << "\n"; value = newValue; // keep the new value } } return 0; } void LoadDLL() { hLib = LoadLibrary("inpout32.dll"); if (hLib == NULL) { std::cout << "cant load the .dll file\n"; system("PAUSE"); exit(1); } InPortB = (PtrInput) GetProcAddress(hLib, "Inp32"); if (InPortB == NULL) { std::cout << "can not start inportb\n"; system("PAUSE"); exit(1); } OutPortB = (PtrOutput) GetProcAddress(hLib, "Out32"); if (OutPortB == NULL) { std::cout << "can not start outportb\n"; system("PAUSE"); exit(1); } }
Code C++ - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 #include <iostream> #include <windows.h> const int LPT1_DATA_REGISTER = 0x378; //WRITE (pins D0, D1, D2, D3, D4, D5, D6, D7) const int LPT1_STATUS_REGISTER = 0x379; //READ (pins BUSY, ACK, PAPER END, SLCT OUT, ERROR) typedef short _stdcall (*PtrInput)(short EndPorta); typedef void _stdcall (*PtrOutput)(short EndPorta, short valor); PtrInput InPortB = NULL; PtrOutput OutPortB = NULL; HINSTANCE hLib = NULL; void LoadDLL(); int main (int argc, char *args[]) { LoadDLL(); OutPortB(LPT1_DATA_REGISTER, 0x00); //Clean the data pins for (int i = 0; i < 256; i++) //counts 0 to 255 { OutPortB(LPT1_DATA_REGISTER, i); //Send the i value to port Sleep(1000); //Wait 1 sec } OutPortB(LPT1_DATA_REGISTER, 0x00); //Clean the data pins return 0; } void LoadDLL() { hLib = LoadLibrary("inpout32.dll"); if (hLib == NULL) { std::cout << "cant load the .dll file\n"; system("PAUSE"); exit(1); } InPortB = (PtrInput) GetProcAddress(hLib, "Inp32"); if (InPortB == NULL) { std::cout << "can not start inportb\n"; system("PAUSE"); exit(1); } OutPortB = (PtrOutput) GetProcAddress(hLib, "Out32"); if (OutPortB == NULL) { std::cout << "can not start outportb\n"; system("PAUSE"); exit(1); } }
Ok, I wrote 2 codes, one for receive from parallel port and another to send. I havent tested those codes because I dont have a computer with parallel port.
This is for receiver. The application just keep reading status register and comparing with the last one read, if the new value is different of the last value then it write the new value in prompt
Code C++ - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 #include <iostream> #include <windows.h> const int LPT1_DATA_REGISTER = 0x378; //WRITE (pins D0, D1, D2, D3, D4, D5, D6, D7) const int LPT1_STATUS_REGISTER = 0x379; //READ (pins BUSY, ACK, PAPER END, SLCT OUT, ERROR) typedef short _stdcall (*PtrInput)(short EndPorta); typedef void _stdcall (*PtrOutput)(short EndPorta, short valor); PtrInput InPortB = NULL; PtrOutput OutPortB = NULL; HINSTANCE hLib = NULL; void LoadDLL(); int main (int argc, char *args[]) { LoadDLL(); unsigned char value = InPortB(LPT1_STATUS_REGISTER); // first value acquired std::cout << "First value acquired: " << value << "\n"; while ( true ) { unsigned char newValue = InPortB(LPT1_STATUS_REGISTER); // read the new value if ( value == newValue ) // check if the value has changed { std::cout << "New value received (decimal): " << newValue << "\n"; value = newValue; // keep the new value } } return 0; } void LoadDLL() { hLib = LoadLibrary("inpout32.dll"); if (hLib == NULL) { std::cout << "cant load the .dll file\n"; system("PAUSE"); exit(1); } InPortB = (PtrInput) GetProcAddress(hLib, "Inp32"); if (InPortB == NULL) { std::cout << "can not start inportb\n"; system("PAUSE"); exit(1); } OutPortB = (PtrOutput) GetProcAddress(hLib, "Out32"); if (OutPortB == NULL) { std::cout << "can not start outportb\n"; system("PAUSE"); exit(1); } }
I have attached a image of how is the status register format. You have to know it to build your keypad logic.
View attachment 56821
this one is for write data on pins D0 to D7. it is just a counter from 0 to 255 with 1000 ms of delay.
Code C++ - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 #include <iostream> #include <windows.h> const int LPT1_DATA_REGISTER = 0x378; //WRITE (pins D0, D1, D2, D3, D4, D5, D6, D7) const int LPT1_STATUS_REGISTER = 0x379; //READ (pins BUSY, ACK, PAPER END, SLCT OUT, ERROR) typedef short _stdcall (*PtrInput)(short EndPorta); typedef void _stdcall (*PtrOutput)(short EndPorta, short valor); PtrInput InPortB = NULL; PtrOutput OutPortB = NULL; HINSTANCE hLib = NULL; void LoadDLL(); int main (int argc, char *args[]) { LoadDLL(); OutPortB(LPT1_DATA_REGISTER, 0x00); //Clean the data pins for (int i = 0; i < 256; i++) //counts 0 to 255 { OutPortB(LPT1_DATA_REGISTER, i); //Send the i value to port Sleep(1000); //Wait 1 sec } OutPortB(LPT1_DATA_REGISTER, 0x00); //Clean the data pins return 0; } void LoadDLL() { hLib = LoadLibrary("inpout32.dll"); if (hLib == NULL) { std::cout << "cant load the .dll file\n"; system("PAUSE"); exit(1); } InPortB = (PtrInput) GetProcAddress(hLib, "Inp32"); if (InPortB == NULL) { std::cout << "can not start inportb\n"; system("PAUSE"); exit(1); } OutPortB = (PtrOutput) GetProcAddress(hLib, "Out32"); if (OutPortB == NULL) { std::cout << "can not start outportb\n"; system("PAUSE"); exit(1); } }
to release the port access i had used an application called UserPort: The official UserPort homepage on windows XP. I dont know how to release these ports on vista and seven, you have to look for it by your self. If you have a computer with windows xp to test it, is the better option you may have now
you probaly know, but for safety let me remind you that a short-circuit or any other misuse may damage your computer hardware, so be careful!
would be nice if you let me see the schematics of your project, will help a lot.
try to implement these codes above and let me know your results and doubts.
Iuri~
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?