Introduction :
This page follows these two previous articles :
Add TTL outputs to your USB Laptop (Part 1, Hardware)
Add TTL outputs to your USB Laptop (Part 2, Software on Linux)
First, add a fake printer :
In order to use this hack on windows, you first have to add a fake printer on your USB port. Choose the printer menu, and select "Add printer". Choose then "Local printer". Windows will ask you for a port number. Select your USB port. Sorry, my windows is in French, so, screenshots are in French too...
We then choose the most basic printer, the "Generic/text only" :
You then have to name your printer. I use the "TTL_OUTPUT" name :
If you print a test page now, you should see your TTL levels changing very fast.
If you are writing your own software :
Our USB/printer adapter now just acts as a printer, named TTL_OUTPUT. You just have to use the win32 printing API. K2000 sample :
#include <windows.h>
#define P_SIZE 6
int main () {
HANDLE hPrinter;
DOC_INFO_1 DocInfo;
DWORD byteNumber;
BYTE patterns[P_SIZE]={0x18,0x24,0x42,0x81,0x42,0x24};
// open the printer
OpenPrinter("TTL_OUTPUT", &hPrinter, NULL);
// Fill the "document"
DocInfo.pDocName = "My outputs";
DocInfo.pOutputFile = NULL;
DocInfo.pDatatype = "RAW";
// K2000 loop
for (int i=0;i<1024;i++) {
// start a document
StartDocPrinter(hPrinter, 1, (LPBYTE)&DocInfo);
// start a page
StartPagePrinter(hPrinter);
// send a byte to the printer.
WritePrinter(hPrinter, &patterns[i%P_SIZE], 1, &byteNumber);
// close the page
EndPagePrinter(hPrinter);
// close the document EndDocPrinter(hPrinter);
}
// close the printer
ClosePrinter(hPrinter);
return 0;
}
The binary is available there : link
K2000.exe on Windows Vista :
Due to the USB timings and the use of the MS Windows spool, you may encounter some latencies. Not for real time use.Tested on Windows XP and Vista. It should work on any Windows greater than Windows 95.
If you use an existing software (DOS printing) :
Most existing software use the original LPT ports. If your software use the basic printer services provided by MS Dos, you can use "net use" to redirect your printer.
First, you will have to share our fake printer :
You then have to redirect lpt1 using "net use" in the console by using "net use lpt1: \\computer_name\printer_name". Adding "/persistent:yes" to this line make the redirection become permanent :
Replace "eeepc-901" (my computer name) by your computer name on the network. You may also give another port (lpt2 or lpt3), and another destination printer (my printer is still TTL_OUTPUT).You can remove this like later by using "net use lpt1: /delete".
If you use an existing software (lO access with inpout32) :
We will have to redirect these ports to our fake printer. Windows forbids direct I/O accesses. There is several solutions for I/O accesses under windows, like inpout32 or porttalk. inpout32 seams to be the most used. It's used by PHDguiding and Guidemaster. If we replace the existing "inpout32.dll" with a new one, we can redirect all these I/O accesses to our fake printer.
The ".def" file must be the same :
EXPORTS
Inp32 @1
Out32 @2
Our dll code will then look like this one :
#include <windows.h>
BOOL APIENTRY DllMain( HINSTANCE h, DWORD call, LPVOID reserved ) {
return TRUE;
}
short _stdcall Inp32(short port) {
return 0;
}
void _stdcall Out32(short port, short data) {
// vars
HANDLE hPrinter;
DOC_INFO_1 docInfo;
DWORD byteNumber;
if(port==0x378) {
// open the printer
OpenPrinter("TTL_OUTPUT", &hPrinter, NULL);
// Fill the "document"
docInfo.pDocName = "My outputs";
docInfo.pOutputFile = NULL;
docInfo.pDatatype = "RAW";
// start a document
StartDocPrinter(hPrinter, 1, (LPBYTE)&docInfo);
// start a page
StartPagePrinter(hPrinter);
// send a byte to the printer
WritePrinter(hPrinter, &data, 1, &byteNumber);
// close the page
EndPagePrinter(hPrinter);
// close the document
EndDocPrinter(hPrinter);
// close the printer
ClosePrinter(hPrinter);
}
}
This dll is just a proof of concept. It should be much cleaner, but it works ! The dll binary is available there : link
Simple demo with PHDguiding :
It should work with any software using inpout32. This hack has been tested on Windows XP and Vista.
Best regards !