DrPickles Posted March 4, 2022 Share Posted March 4, 2022 I'm currently working with some usb boards that use HEX to give digital sensor information. when converted to binary and keeping number order it gives position and status. an example would be (11111111111111111111111100000000) Hex:ffffff00. on a lot of examples, hex is converted to base10 then converted to binary. the number is preserved.. but the number is not really the point of the information its the position of the 1 or 0. so I wrote an include. I hope this give back a little to the community that has helped me. Hex_Converter.au3 Link to comment Share on other sites More sharing options...
jchd Posted March 4, 2022 Share Posted March 4, 2022 You're making your life overly difficult! Local $hex = "0123456789abcdef" ConsoleWrite(_HexToBin($hex) & @LF) Local $bin = "0111011011100011110000001" ConsoleWrite(_BinToHex($bin) & @LF) Func _HexToBin($_hex) Return StringFormat("%0" & 4 * StringLen($_hex) & "s", _UintToString(Dec($_hex), 2)) EndFunc ;==>_HexToBin Func _BinToHex($_bin) Return Hex(_StringToUint($_bin, 2)) EndFunc ;==>_BinToHex Func _StringToInt($s, $base) Return DllCall("msvcrt.dll", "int64:cdecl", "_wcstoi64", "wstr", $s, "ptr*", 0, "int", $base)[0] EndFunc ;==>_StringToInt Func _StringToUint($s, $base) Return DllCall("msvcrt.dll", "uint64:cdecl", "_wcstoui64", "wstr", $s, "ptr*", 0, "int", $base)[0] EndFunc ;==>_StringToUint Func _IntToString($i, $base) Return DllCall("msvcrt.dll", "wstr:cdecl", "_i64tow", "int64", $i, "wstr", "", "int", $base)[0] Return $aRes[0] EndFunc ;==>_IntToString Func _UintToString($i, $base) Return DllCall("msvcrt.dll", "wstr:cdecl", "_ui64tow", "uint64", $i, "wstr", "", "int", $base)[0] EndFunc ;==>_UintToString You even have signed conversions for free, as well as signed or unsigned conversions for any base in [2, 36]. vince77 1 This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
vince77 Posted March 4, 2022 Share Posted March 4, 2022 7 hours ago, jchd said: You're making your life overly difficult! Local $hex = "0123456789abcdef" ConsoleWrite(_HexToBin($hex) & @LF) Local $bin = "0111011011100011110000001" ConsoleWrite(_BinToHex($bin) & @LF) Func _HexToBin($_hex) Return StringFormat("%0" & 4 * StringLen($_hex) & "s", _UintToString(Dec($_hex), 2)) EndFunc ;==>_HexToBin Func _BinToHex($_bin) Return Hex(_StringToUint($_bin, 2)) EndFunc ;==>_BinToHex Func _StringToInt($s, $base) Return DllCall("msvcrt.dll", "int64:cdecl", "_wcstoi64", "wstr", $s, "ptr*", 0, "int", $base)[0] EndFunc ;==>_StringToInt Func _StringToUint($s, $base) Return DllCall("msvcrt.dll", "uint64:cdecl", "_wcstoui64", "wstr", $s, "ptr*", 0, "int", $base)[0] EndFunc ;==>_StringToUint Func _IntToString($i, $base) Return DllCall("msvcrt.dll", "wstr:cdecl", "_i64tow", "int64", $i, "wstr", "", "int", $base)[0] Return $aRes[0] EndFunc ;==>_IntToString Func _UintToString($i, $base) Return DllCall("msvcrt.dll", "wstr:cdecl", "_ui64tow", "uint64", $i, "wstr", "", "int", $base)[0] EndFunc ;==>_UintToString You even have signed conversions for free, as well as signed or unsigned conversions for any base in [2, 36]. Exactly, his approach makes it more difficult than it actually is. Link to comment Share on other sites More sharing options...
DrPickles Posted March 4, 2022 Author Share Posted March 4, 2022 when working with GPIO usb boards. i found exceptions that were lost in translation when using hex to dec- dec to bin. the binary HAD to have 32 places with no spaces. anything else would confuse the hardware and give me a bad result. I also had a situation where when the binary was converted to a number it was too big and gave me some errors, so i had to convert the numbers to a string to evaluate. that is why I offered this code, its a strange situation. when dealing with the analog world with sensors i find tiny little issues that happen 1 in every million inputs that throw a wrench in the works. that being said! i will study the above code and see what i can learn from it, as this could be a milliseconds faster and any way to speed up sampling rate is a good thing. Earthshine 1 Link to comment Share on other sites More sharing options...
Earthshine Posted March 4, 2022 Share Posted March 4, 2022 you did the right thing for your circumstances. good work. My resources are limited. You must ask the right questions Link to comment Share on other sites More sharing options...
DrPickles Posted March 4, 2022 Author Share Posted March 4, 2022 I'm working with numato boards. one of the few boards that give code examples using autoit. you would be surprised at the little things that dealing with ephemeral data you have to deal with. its like the bad ol' days of doing analog to digital conversion of video, once you error check and calculate.. its gone with no turning back. sleep() hah never ever! state change is life.. if i had any formal training .. hell i would rule the world pinky! oh yea and i hate GUI programing.. people are soooo unpredictable. Earthshine 1 Link to comment Share on other sites More sharing options...
Earthshine Posted March 4, 2022 Share Posted March 4, 2022 (edited) I wrote a device driver and API for Digiboard back in the nineties. You could have the maximum number of boards which each had like 16 inputs each and I could manage all of the boards and tell you exactly which device you were working with and what you’re doing returning the data. And then another engineer took that and used it in gauging applications. That way the software engineer could simply call the device they cared about and my device driver figured out who to contact and pass data back and fourth. Fun stuff The serial port boards made it easy for us to set up super complex gauging applications for automotive and industrial use manufacturing parts Our gauging apps were used by Saginaw Steering Gear Which makes steering gear components for not only all of General Motors but many others including Ford, Ferrari and others like AMC I believe in the past https://whatis.techtarget.com/definition/digiboard-or-digicard?amp=1 Edited March 4, 2022 by Earthshine My resources are limited. You must ask the right questions Link to comment Share on other sites More sharing options...
DrPickles Posted March 4, 2022 Author Share Posted March 4, 2022 i have some IO that, I swear on a stack of bibles.. the board seems to get saturated and produces output with no input so i got this crazy lag. i have baud rate cranked up to the max of the board.. i wonder if some kind of lag is in the intermediate programing.. i will get it as tight as i can and see how bad the.. fudging of the numbers are.. i haven't had this much fight since i worked on a turboencabulator.. Link to comment Share on other sites More sharing options...
seadoggie01 Posted March 7, 2022 Share Posted March 7, 2022 On 3/4/2022 at 3:04 PM, Earthshine said: Our gauging apps were used by Saginaw Steering Gear Which makes steering gear components for not only all of General Motors but many others including Ford, Ferrari and others like AMC I believe in the past I worked there as an intern, that's crazy. They were rebranded to Delphi and now Nexteer Automotive, but they still make steering components for GM, Ford, and Toyota. I wouldn't be surprised if your device was still in use today "If it ain't broke, don't fix it" gets tossed around there all the time Earthshine 1 All my code provided is Public Domain... but it may not work. Use it, change it, break it, whatever you want. Spoiler My Humble Contributions:Personal Function Documentation - A personal HelpFile for your functionsAcro.au3 UDF - Automating Acrobat ProToDo Finder - Find #ToDo: lines in your scriptsUI-SimpleWrappers UDF - Use UI Automation more Simply-erKeePass UDF - Automate KeePass, a password managerInputBoxes - Simple Input boxes for various variable types Link to comment Share on other sites More sharing options...
Earthshine Posted March 7, 2022 Share Posted March 7, 2022 (edited) Saginaw Steering Gear makes probably the BEST steering gear around IMO, rock solid performance and excellent quality. Dude, with our gauges we could get down to pico level measurements--ensuring the most accurate parts. I bet it is still used as well. Edited March 7, 2022 by Earthshine My resources are limited. You must ask the right questions 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