amakrkr Posted March 7, 2011 Share Posted March 7, 2011 Hello Dear community, i have a "new" project hanging over my head and i am kinda stuck with it. What do i have is a USB dysplay device with a driver (badly documented) and a C++ sample code. I want to use AutoIt to access my device so here is the problem. I dont know how to access dll and how to interact with device (i want to put some random leters and words on the display). Anyway below is code i came up with so far and a portion of dll documentation. I hope someone will help me with this. Kind regards! expandcollapse popup// THIS IS C++ CODE #include <stdio.h> #include <time.h> #include "windows.h" int __cdecl main(int argc, char* argv[]) { HMODULE hm; long (*ou)(); long (*cu)(); long (*wp)(char*,long); long (*ps)(); time_t tm; char ss[64]; SetLastError( 0); hm = LoadLibrary( "usbpd.dll"); printf( " hm = %p, %lu \n",hm,GetLastError()); if ( hm==NULL ) return 1; SetLastError( 0); ou = (long(*)()) GetProcAddress( hm,"OpenUSBpd"); printf( " ou = %p, %lu \n",ou,GetLastError()); SetLastError( 0); cu = (long(*)()) GetProcAddress( hm,"CloseUSBpd"); printf( " cu = %p, %lu \n",cu,GetLastError()); SetLastError( 0); wp = (long(*)(char*,long)) GetProcAddress( hm,"WritePD"); printf( " wp = %p, %lu \n",wp,GetLastError()); SetLastError( 0); ps = (long(*)()) GetProcAddress( hm,"PdState"); printf( " ps = %p, %lu \n",ps,GetLastError()); printf( " OpenUSB = %ld \n", ou()); for (long i=0;i<3;++i) { printf( " ps(1) = %ld \n", ps()); time( &tm); sprintf( ss,"\x1b\x40%s",ctime( &tm)); wp( ss, strlen( ss)); if ( argc>1 ) for (int j=30;j<255;++j) { ss[0] = j; ss[1] = 0; wp( ss,1);} printf( " ps(2) = %ld \n", ps()); } printf( " CloseUSB = %ld \n", cu()); FreeLibrary( hm); return 0; } ----------------- dll documentation ----------------- Public Declare Function OpenUSBpd _ Lib "usbpd.dll" _ () _ As Long ' must be called before calling other functions ' return 0 on success Public Declare Function CloseUSBpd _ Lib "usbpd.dll" _ () _ As Long ' call this function before exiting your program ' return 0 on success Public Declare Function WritePD _ Lib "usbpd.dll" _ (ByVal data As String, ByVal length as Long) _ As Long ' return 0 on sending commands successfully Public Declare Function PdState _ Lib "usbpd.dll" _ () As Long ' return the line display status ' return 0 on being ready ' And my code ... not much so far ... $dll = DllOpen("USBPD.DLL") if @error <> -1 Then DllCall( $dll ,"str","WritePD", "str", "test") EndIf DllClose($dll) Link to comment Share on other sites More sharing options...
jvanegmond Posted March 7, 2011 Share Posted March 7, 2011 $dll = DllOpen("usbpd.dll") ; Open USB DllCall($dll, "long", "OpenUSBpd") ; Write text $message = "OH HAI WORLD KTHXBYE" DllCall($dll, "long", "WritePD", "str", $message, "long", StringLen($message)) ; Close USB DllCall($dll, "long", "CloseUSBpd") DllClose($dll) I wonder how you came up with your code... Try this code above. Add debug as necessary. github.com/jvanegmond Link to comment Share on other sites More sharing options...
JohnOne Posted March 7, 2011 Share Posted March 7, 2011 Theres a kittle clue in your documentation "must be called before calling other functions" AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
amakrkr Posted March 8, 2011 Author Share Posted March 8, 2011 That worked like a charm. Thank you! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now