#include ; digisparkusb autoit3 wrapper by Nicolas RICQUEMAQUE, v1.0, november 2013, GNU GPL3. ; Here is a quick example of the functions, sending and receiving something to the digispark. You may send the "digispark USB echo" sample code to it to test it. ; If compiled, extract send.Exe and receive.exe from script.exe, if not compiled, check if they are in same directory as script If Not DigisparkUSB_Setup(false) Then MsgBox(16,"Error","Missing DigisparkUSB files") Exit 0 EndIf ; Check if a digispark is connected If NOT DigisparkUSB_isconnected() Then MsgBox(16,"Error","No Digispark connected") Exit 0 EndIf ; Sends something to the digispark DigisparkUSB_write('Hello "World" !' & @CR & "See You later...") ; Time for the digispark to process it Sleep(1000) ; Check if we have a reply MsgBox(0,"",DigisparkUSB_read()) Exit 0 ; Now the library.... ; Check that Digispark send.exe and receive.exe files are available; if not, decompress them from the autoit exe script to the script path ; If persistent is set to true, the files won't be erased at the end of the program (if yes, they will be created and deleted everytime ; Returns true if receive.exe and send.exe are available or were exctracted with success Func DigisparkUSB_Setup ($persistent=true) If @Compiled=0 Then return (FileExists(@ScriptDir & "\send.exe")=1 AND FileExists(@ScriptDir & "\receive.exe")=1) FileInstall("receive.exe",@ScriptDir & "\receive.exe",1) FileInstall("send.exe",@ScriptDir & "\send.exe",1) If NOT $persistent Then OnAutoItExitRegister("DigisparkUSB_deleteexes") return (FileExists(@ScriptDir & "\send.exe")=1 AND FileExists(@ScriptDir & "\receive.exe")=1) EndFunc ; function automaticaly called at end of compiled script if DigisparkUSB librairies were set up as "not persistent" Func DigisparkUSB_deleteexes () FileDelete(@ScriptDir & "\receive.exe") FileDelete(@ScriptDir & "\send.exe") EndFunc ; function to check if a digispark is connected to host computer ; return true if connected Func DigisparkUSB_isconnected () return (StringInStr(DigisparkUSB_read(),"No Digispark Found")=0) EndFunc ; function to read the digispark buffer. ; in parameter $chars limit the read to a number of chars (0 by default meaning read everything) ; returns the string read Func DigisparkUSB_read($chars=0) If $chars=0 Then RunWait(@ComSpec&" /c receive.exe >digispark.txt",@ScriptDir,@SW_HIDE) Else RunWait(@ComSpec&" /c receive.exe --chars " & $chars & " >digispark.txt",@ScriptDir,@SW_HIDE) EndIf if @error>0 Then return "" Local $read=FileRead(@ScriptDir&"\digispark.txt") FileDelete(@ScriptDir&"\digispark.txt") return $read EndFunc ; function to read a single line from the digispark buffer ; returns the string read Func DigisparkUSB_readline() RunWait(@ComSpec&" /c receive.exe --read-to-newline >digispark.txt",@ScriptDir,@SW_HIDE) if @error>0 Then return "" Local $read=FileRead(@ScriptDir&"\digispark.txt") FileDelete(@ScriptDir&"\digispark.txt") return $read EndFunc ; function to write a string to the digispark Func DigisparkUSB_write($string) $string=StringReplace($string,@LF,"") ; if contains lines with @CRLF remove @LF $string=StringReplace($string,'"','\"') ; escape " caracters Local $terminatebyCR=false If StringRight($string,1)=@CR Then ; detect if last char is a @CR $terminatebyCR=true $string=StringTrimRight($string,1) EndIf Local $array=StringSplit($string,@CR,2) For $i = 0 to Ubound($array)-1 If $i = Ubound($array)-1 AND NOT $terminatebyCR Then RunWait(@ComSpec&" /c send.exe """ & $array[$i] & """ --no-new-line",@ScriptDir,@SW_HIDE) Else RunWait(@ComSpec&" /c send.exe """ & $array[$i] & """",@ScriptDir,@SW_HIDE) EndIf Next EndFunc