Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 02/08/2014 in all areas

  1. Blinky

    SPI Hardware Interface

    Hi everyone, This is my special pet project. It is an example of how u can use autoit to control external devices. this script is made to comunicate with the MAX335 chip using the SPI protocol via the LPT(printer) port the beauty of the MAX335 chip is that the Clock, Data_In and the Chip_Select pins can be directly connected to the LPT port without any external components, and the 12V and 5V directly from an ATX PC power suply. aditionaly i made a custom GUI with CommandFusion instaled on an Android Tablet that sends TCP commands to an Autoit TCP server that controls three dasy chained MAX335 chips that totals 24 independent NO switches this script works perfectly for me i just finished this project and i think i will make an UDF including more SPI devices $DLLFileAndPath = @ScriptDir & "/inpout32.dll" Global $335_device_number=3 ;number of daisy chained chips Global $335_clock_bit=0 ;bit number for LPT pin 1 in the control Register of the LPT port(where i connected the CLK pin on te MAX335) Global $335_cs_bit=4;bit number for LPT pin 6 in the data Register of the LPT port(where i connected the CS pin on te MAX335) Global $335_data_in_bit=7;bit number for LPT pin 9 in the data Register of the LPT port(where i connected the DI pin on te MAX335) Global $clock_delay=1;this limits the clock speed but it works fine with 0 ;the ini file will be created and will keep the MAX335 pins statuses For $i=0 To $335_device_number*8-1 Step 1 IniWrite("355_buffer.ini","present_data",$i,"0") Next set_max335_output(2,3,1) ; this will activate switch 2 on device 3 on the daisy chain Func set_max335_output($output_no,$device_no,$status) $bit_no=($device_no-1)*8+$output_no-1 ; get the exact bit number of the switch IniWrite("355_buffer.ini","present_data",$bit_no,$status); whrite it to the buffer ;this part is where the SPI protocol begins set_control_bit($335_clock_bit,1); drop CLK set_data_bit($335_cs_bit,0) ;activate CS Sleep($clock_delay) For $i=$335_device_number*8-1 To 0 Step -1; start writing from buffer MostSignificantByte first $data=IniRead("355_buffer.ini","present_data",$i,"0") set_data_bit($335_data_in_bit,$data) ; set data bit value set_control_bit($335_clock_bit,0) ;raise CLK Sleep($clock_delay) set_control_bit($335_clock_bit,1); drop CLK Sleep($clock_delay) Next set_data_bit($335_cs_bit,1);deactivate CS EndFunc Func set_data_bit($bit,$stat=-1) ; it will write the value of the bit in the data reg of the LPT port $y= DllCall($DLLFileAndPath, "int", "Inp32", "int", "0x378") $bits=dec_to_bin($y[0]) If $stat = -1 Then If $bits[$bit]=0 Then $bits[$bit]=1 Else $bits[$bit]=0 EndIf $bcd=bin_to_dec($bits) DllCall( $DLLFileAndPath, "int", "Out32", "int", "0x378", "int", $bcd) Return 1 Else If $bits[$bit]<>$stat Then $bits[$bit]=$stat $bcd=bin_to_dec($bits) DllCall( $DLLFileAndPath, "int", "Out32", "int", "0x378", "int", $bcd) Return 1 Else Return 2 EndIf EndIf EndFunc Func set_control_bit($bit,$stat=-1); it will write the value of the bit in the control reg of the LPT port $y= DllCall($DLLFileAndPath, "int", "Inp32", "int", "0x37a") $bits=dec_to_bin($y[0]) If $stat = -1 Then If $bits[$bit]=0 Then $bits[$bit]=1 Else $bits[$bit]=0 EndIf $bcd=bin_to_dec($bits) DllCall( $DLLFileAndPath, "int", "Out32", "int", "0x37a", "int", $bcd) Return 1 Else If $bits[$bit]<>$stat Then $bits[$bit]=$stat $bcd=bin_to_dec($bits) DllCall( $DLLFileAndPath, "int", "Out32", "int", "0x37a", "int", $bcd) Return 1 Else Return 2 EndIf EndIf EndFunc Func dec_to_bin($dec) Local $bit_array[8] If $dec > 255 Then SetError(1,1,-1) If $dec < 0 Then SetError(2,1,-1) For $i=7 To 0 Step -1 If $dec >= 2^$i Then $bit_array[$i] = 1 $dec=$dec-2^$i Else $bit_array[$i] = 0 EndIf Next Return $bit_array EndFunc Func bin_to_dec($bit_array) If IsArray($bit_array) Then If UBound($bit_array) = 8 Then $dec=0 For $i=7 To 0 Step -1 $dec = $bit_array[$i]*(2^$i)+$dec Next Else SetError(2,1,-1) EndIf Else SetError(1,1,-1) EndIf Return $dec EndFunc
    1 point
  2. guinness

    AutoIt3 Portable

    New version is currently being developed. Coming soon!
    1 point
  3. Have you ever thought of, you know, trying them out yourself to see what they look like? Maybe that would have taken less time.
    1 point
  4. Hey folks, I just explored the new helpfile and found a new Keyword (dunno if its that new, but i never saw it before) called Volatile. It was made especally for CallBack and Com event functions, so I wanted to try that out. the advantage of this Keyword is, that you can run the Dll while you can do other things in autoit (AutoIt wont freeze/pause anymore while the dllcall is executed!) I made up a little example i want to share with you, the c source is compiled in MinGW, you need at least AutoIt 3.3.10.2. Hope you like it, would be interested in some comments Greetz, Spider testLibCallback.zip
    1 point
  5. Yes, but case can make a difference with the way you read variables. $sHitMode = "bounce" $shitmode = "oh god why"
    1 point
  6. There is no point in calling each other names. While I agree with MHz that DB normalization pushed to the extreme is a dogmatic position which is not useful, there must be reasonable reasons to split a massive amount of data into two or more separate tables. One common reason is archiving past data, where querying split tables is a rare need and you know where to search when you have to, e.g. 2011 invoices details. But splitting tables should never make routine usage harder. There are objective serious drawbacks to split tables. First, as in the OP, you don't know where to search and even if you can grab data as in your example with union all, you still don't know where it resides. Updating data is problematic: you have to query every table to locate it or update blindly all tables in the hope the where conditions are deterministic enough. Then you can hardly use foreign keys. Triggers can reveal a nightmare. Self joins or joins accross tables can become accrobatic. Rowids are not enough or you have to reserve specific ranges but in this case you could as well merge everything. Overall SQL becomes much more complex and error-prone. The example you made in post #10 shows how cumbersome the simplest task become. So while it's not an absolute no-no in all cases, there are enough clues that it isn't the natural design in 99% of the use cases. So it isn't bad advice to tell fresh DB users to keep away of such a design. If the context actually calls for split tables, a seasonned user will be well aware of the pro and contra and will know beforehand how to circumvent the issues associated with split tables.
    1 point
  7. Servant, Look at the _GUICtrlListBox_* functions in the Help file - _GetCount & _GetText should be what you need. M23
    1 point
  8. Jos

    InputBox (please help)

    _INetSmtpMail() doesn't support Gmail, just strait forward SMTP. Look for the _InetSmtpMailCom() in Examples for Gmail support. Jos
    1 point
  9. Are we a little Impatient?
    1 point
  10. Melba23

    how to delete a list item?

    MATISZON, Here you go: Func usunlink() $sName = GUICtrlRead($List1) _GUICtrlListBox_DeleteString($List1, _GUICtrlListBox_GetCaretIndex($List1)) MsgBox(0, "DELETE", $sName & " has been deleted") EndFunc M23
    1 point
  11. RyGoTypE

    If Window Exists...

    Nevermind, I figured it out. ; Check if window exists. If NOT WinExists ("DarkWars", "") Then ; BROWSER CHECK: If user doesn't have FireFox, use Internet Explorer. If FileExists(@ProgramFilesDir & "\Mozilla Firefox\firefox.exe") Then Run(@ProgramFilesDir & "\Mozilla Firefox\firefox.exe " & $URL ) ElseIf FileExists(@ProgramFilesDir & "\Internet Explorer\iexplore.exe") Then Run(@ProgramFilesDir & "\Internet Explorer\iexplore.exe " & $URL ) EndIf ElseIf WinExists ("DarkWars", "") Then ; Check if window is active. If Not WinActive("DarkWars") Then WinSetState("DarkWars", "", @SW_SHOW) Endif ; Continue on with script. ; Continue on with script. ; Continue on with script. ; Continue on with script. EndIf
    1 point
×
×
  • Create New...