Leaderboard
Popular Content
Showing content with the highest reputation on 04/20/2015 in all areas
-
Pool provides multiple AutoIt processes with an infrastructure for exchanging messages, data, and remote-control instructions, on a single machine or on a local area network. It is modelled partly on HTCondor, but also incorporates user-defined messages (UDM), LANchat, mails, data Container shipping management, and remote power control and remote execution. That last feature means one process can send lines of AutoIt script to another process, and run it there (including batch control and synchronisation). Consider it my take on inter-process communication (IPC). Pool incorporates many contributions (a few are included in the bundle, other tiny snippets are part of the main script), from other forum members without whom this project simply would never even have been conceivable. In particular, I hereby want to acknowledge the excellent work of Zatorg, wraithdu, W0uter, Ward, ValeryVal, spudw2k, trancexx, This-is-Me, Nomad, Nine, Manadar, LazyCat, Lakes, Kip, Kealper, Jos, Greencan, FredAI, evilertoaster, dragan, Chimp, and AdamUL. Some codes merely helped to clarify my novice understanding of various IPC issues, others have been gratefully integrated. Three contributors need special mention: Kip & Zatorg for event-driven TCP, and trancexx for MailSlot; together these form the backbone of everything else. The only reason I still dare to publish this under my own name is because I did add over ten thousand lines of code myself. Nevertheless, Pool may serve as a showcase for how various members' example scripts can be combined into a comprehensive environment. Many, many thanks to everyone involved! Pool is designed to be simple to use. Only a few functions are public, and of those, you really only need to study these four control UDFs: _Pool_Send_Command(): Pool's Command & Control Centre (see list of commands below) _Pool_Send_UserDefinedMsg(): define your own outgoing msgs _Pool_Receive_UserDefinedMsg(): process your own incoming msgs _Pool_Send_ExeQcall(): send one or more AutoIt instructions to target's Exe-Queue (ExeQ) and these ones for data transfers: _Pool_Container_Create(): associate shipping Container with data _Pool_Container_Destroy(): release Container memory and all associated Sharing relations _Pool_Container_CreateShare(): associate destination with Container _Pool_Container_DestroyShare(): dissolve sharing association for destination To get an idea of what _Pool_Send_Command() can do, here's the list of commands: Pool is big. It has got many dozens of fixed and dynamic user-defined settings to create specific applications with (see #Region Globals). Please take the time to read the extensive Remarks section at the top of the main script (Pool.au3), including the warnings and limitations. Furthermore, I've provided two example environments in the subdir Examples in the bundle: CLNtest (messages and remote execution) and CLNmaster + CLNslave (data Container shipping). If you run these on a single machine, you'll need to start PostOffice_Solo; on multiple machines, one should start first with PostOffice_Server, the rest with PostOffice_Client, once the Server is initialised. See the readme.txt in the Examples subdir for additional help. Another example (multi-processing a la Condor) is shipped with release 2.4+ of Eigen4AutoIt. Since this is an Example script, you can find a number of interesting design ideas in Pool: Pool.v0.7.7z Pool bundle, second beta release, version 0.7 IMPORTANT CAVEAT This is an experimental beta release. Some parts of Pool have never been tested, others only in the simplest possible setting (the largest network I ever tested comprised one desktop and three laptops (one with busted radio) on a crappy Wifi router; I've never tested it on a cabled network). The (W)LAN part still has many issues and may not be able to handle more than a few machines. There's no callstack error handler. Event-driven TCP remains glitchy, and some of my MailSlots keep malfunctioning. I also lack access to Windows 8.* test environments. In addition, many issues you may encounter will be due to specific timings/event sequencing (which makes it hard to debug) and/or your specific infrastructure. That means that, most likely, I cannot recreate your Pool bugs (even with your scripts), so I cannot fix them either. Therefore, I will not be offering bug support for users at this point; there's still far too much I need to fix in my own environment to worry about yours, I'm sorry (also, I've been working on this for four months flat, and need a break from it). However, I am of course open to suggestions, remarks, criticism, and kind words (preferably the latter ). Finally, I will be exceptionally busy with work for the foreseeable future, so it may take me more time than in the past to respond to your posts. Have fun playing in the Pool.1 point
-
Although serial ports are disappearing, they can still be useful. Here is a COMMs UDF. It provides an easy way to use serial ports without the restrictions and problems some methods have. USB to serial is ok, binary data is ok. This UDF requires my comMG.dll which can be in either the script folder or the Windows folder by default, or in the path specified using the function _CommSetDllPath. Note the following shortcomings: the dll link below is 32 bit so it will not work with a 64 bit apps, but there is a 64 bit version in my post around 25th March 2018 for people to try. The strings and character functions are all AnsiChar. Functions in the UDF are _CommVersion _CommListPorts _CommSetPort _CommPortConnection _CommClearOutputBuffer _CommClearInputBuffer _CommGetInputcount _CommGetOutputcount _CommSendString _CommGetString _CommGetLine _CommReadByte _CommReadChar _CommSendByte _CommSendBreak; not tested!!!!!!!!!! _CommCloseport _CommSwitch _CommReadByteArray _CommSendByteArray _CommsetTimeouts _CommSetXonXoffProperties _CommSetRTS (NB these will not work if Hardware handshaking is selected because _CommSetDTR then these lines are controlled by the data being sent.) _CommSetDllPath _CommGetLineStates -------------------------------------------------------------------------------------------------------------------------------- Go to Download Page For Commgv2 Download includes the dll and udf. Most recent changes 28th March 2014 - dll V2.83 Correct error setting 6 data bits as 7. 11th March 2014 dll V2.82 Allow data bits of 4 to 8 instead of only 7 and 8. 19th August 2013 dll v2.81 removes some unwanted eroor message popups. Might not remove popups for some Windows versions. 27th September 2012 Correct error closing port. New version of UDF if V2.90, new dll is commg.dll V2.79. Thanks to tfabris. 18th January 2012 Corrected typo in UDF V 2.87, and uploaded as V2.88 Increased max baud allowed by the dll from 200000 to 256000. New version now V2.78 17th January 2012 Modified thesleep addition to _CommGetLine so that reading data is not slowed down. 14th January 2012 Corrected _CommReadByte in UDF. Added sleep(20) to while loop in _CommGetLine to reduce CPU usage 20th December 2011 UDF version 2.86. - Changed function GetByte so it returned the error string given by the dll. Dll version 2.77 - removed an unwanted erro message dialogue from GetByte function. (Thanks funkey) 4th December 2011 New dll and example versions. Dll function SetPort corrected because it was not using the parameters passed for DTR and RTS. The example was setting flow control incorrectly: the settings for hardware handshaking and XON./XOFF were reversed. 25th August 2011 corrected function _CommClosePort. Example corrected for setting parity and flow 22nd December 2013 (thanks to MichaelXMike) mgrefcommg CommgExample.au31 point
-
Hi guys/girls! I'm gonna share this UDF I made today. It allows you to easily create TCP servers and set actions depending on three events: OnConnect, OnDisconnect and OnReceive. It is also multi client (you can set the clients limit) and you can also bind a Console-based executable to the socket (similar to -e parameter in NetCat). This feature is useful if you want to use some Console UDF to create your TCP server and don't want to mix it with the TCP functions. Also, as it runs on background just firing events, it won't pause your script while listening/receiving, so you can do anything else (stop and restart the server, allow the user to click buttons or just wait on an infinite loop) that your callbacks will be called once the event is fired. It's also very easy to use. See this examples: Example #1: A basic server By running this (then connecting to the server using Netcat), you will receive a message box telling you when some user connects or disconnects (the socket ID and his IP address is passed as parameter to your callback function) and also when the user sends something over the TCP socket (the data sent is passed as parameter). #cs Download netcat at https://eternallybored.org/misc/netcat/ Execute this script Run in CMD: nc -vv 127.0.0.1 8081 #ce #include "TCPServer.au3" ; First we set the callback functions for the three events (none of them is mandatory) _TCPServer_OnConnect("connected") _TCPServer_OnDisconnect("disconnect") _TCPServer_OnReceive("received") ; And some parameters _TCPServer_DebugMode(True) _TCPServer_SetMaxClients(10) ; Finally we start the server at port 8081 at any interface _TCPServer_Start(8081) Func connected($iSocket, $sIP) MsgBox(0, "Client connected", "Client " & $sIP & " connected!") _TCPServer_Broadcast('new client connected guys', $iSocket) _TCPServer_Send($iSocket, "Hey! Write something ;)" & @CRLF) _TCPServer_SetParam($iSocket, "will write") EndFunc ;==>connected Func disconnect($iSocket, $sIP) MsgBox(0, "Client disconnected", "Client " & $sIP & " disconnected from socket " & $iSocket) EndFunc ;==>disconnect Func received($iSocket, $sIP, $sData, $sPar) MsgBox(0, "Data received from " & $sIP, $sData & @CRLF & "Parameter: " & $sPar) _TCPServer_Send($iSocket, "You wrote: " & $sData) _TCPServer_SetParam($iSocket, 'will write again') EndFunc ;==>received While 1 Sleep(100) WEnd Example #2: A basic HTTP server (just one page, as it is just an example) In this example, we run this code and point our browser to the address mentioned on the comments. A basic "It works!" page is show. #cs Run this script Point your browser to http://localhost:8081/ #ce #include "TCPServer.au3" _TCPServer_OnReceive("received") _TCPServer_DebugMode(True) _TCPServer_SetMaxClients(10) _TCPServer_Start(8081) Func received($iSocket, $sIP, $sData, $sParam) _TCPServer_Send($iSocket, "HTTP/1.0 200 OK" & @CRLF & _ "Content-Type: text/html" & @CRLF & @CRLF & _ "<h1>It works!</h1>" & @CRLF & _ "<p>This is the default web page for this server.</p>" & @CRLF & _ "<p>However this server is just a 26-lines example.</p>") _TCPServer_Close($iSocket) EndFunc ;==>received While 1 Sleep(100) WEnd Example #3: A telnet-like server (Command Prompt bound to the socket after password requesting) By running this example and connecting with Netcat, we will be asked for a password, which is 12345 as we set on the script. If the password is correct, we will see the Command Prompt live-updated (try running a ping to some server, for example). #cs Download netcat at https://eternallybored.org/misc/netcat/ Execute this script Run in CMD: nc -vv 127.0.0.1 8081 #ce #include "TCPServer.au3" Global $sPassword = "12345" ; input server password here _TCPServer_OnConnect("connected") _TCPServer_OnDisconnect("disconnect") _TCPServer_OnReceive("received") _TCPServer_DebugMode(True) _TCPServer_SetMaxClients(10) _TCPServer_Start(8081) Func connected($iSocket, $sIP) _TCPServer_Send($iSocket, "Welcome! Please input password: ") _TCPServer_SetParam($iSocket, 'login') EndFunc ;==>connected Func disconnect($iSocket, $sIP) MsgBox(0, "Client disconnected", "Client " & $sIP & " disconnected from socket " & $iSocket) EndFunc ;==>disconnect Func received($iSocket, $sIP, $sData, $sParam) If $sParam = "login" Then If $sData <> $sPassword Then _TCPServer_Send($iSocket, "Wrong password. Try again: ") Return Else _TCPServer_SetParam($iSocket, 'command') _TCPServer_BindAppToSocket($iSocket, 'cmd.exe') EndIf ElseIf $sParam = "command" Then _TCPServer_SendToBound($iSocket, $sData) EndIf EndFunc ;==>received While 1 Sleep(100) WEnd The limit is your imagination? Well, no sure. We have this limit: You can't create more than one server with this UDF in the same script. However, you can pause and resume (read 'stop and start again') your server at any time in your script, without having to reset the server settings. And of course you can have many clients (or just one, it's your choice!) in the same server. Or run multiple instances.Functions list: _TCPServer_Start _TCPServer_Stop _TCPServer_Close _TCPServer_Send _TCPServer_Broadcast _TCPServer_SetParam _TCPServer_BindAppToSocket _TCPServer_SendToBound _TCPServer_UnBindAppToSocket _TCPServer_GetMaxClients _TCPServer_IsServerActive _TCPServer_ListClients _TCPServer_OnConnect _TCPServer_OnDisconnect _TCPServer_OnReceive _TCPServer_SetMaxClients _TCPServer_DebugMode _TCPServer_AutoTrim _TCPServer_SocketToIP _TCPServer_SocketToConnID _TCPServer_ConnIDToSocket Help file and more examples included! Latest version: 1.0.0.1 Download: TCPServer UDF.rar Changelog 1.0 - First release - 18/04/20151.0.0.1 - Bug fix __TCPServer_Accept internal function / help file recompiled - 26/04/2015Perhaps you will need to uncompress the file first, so the help file will work. Fork this on Github: http://github.com/jesobreira/TCPServerUDF TCPServer UDF.rar1 point
-
Walrus, If CheatEngine returns 167 then it is simply removing the top word: ConsoleWrite(Hex(6029479) & ' ' & Hex(BitAND(6029479, 0x0000FFFF)) & ' ' & (10 * 16) + 7 & @LF) which gives: 005C00A7 000000A7 167 So it seems that you misunderstand the "convert option" and there is no problem with AutoIt at all. And my question was actually: Why are you using CheatEngine? M231 point
-
Help to make an auto login bot for gmail
SorryButImaNewbie reacted to Danp2 for a topic
You definitely don't want _FFFormOptionSelect in this case. Try this: _FFSetValue ("email@address.com", "email", "id") _FFSetValue ("yourpass", "pass", "id") _FFFormSubmit()1 point -
Always the useful, RTFC you rule!!!1 point
-
StringExplode behavior after upgrading from 3.3.10.2 to 3.3.12.0
VenusProject2 reacted to Malkey for a topic
Looking at the function _StringExplode in String.au3 in the include directory you will see Return StringSplit($sString, $sDelimiter, $STR_NOCOUNT) where $STR_NOCOUNT = 2 Previous versions of AutoIt has Return StringSplit($sString, $sDelimiter, 3) where 3 = 1+ 2 = $STR_ENTIRESPLIT (1) + $STR_NOCOUNT (2) My advice is to use StringSplit($sTest, @CRLF, 3) in your script instead of _StringExplode($sTest,@CR) This appears to be an introduced bug into the _StringExplode function. The extra lines are introduced because each character in the delimiter string in _StringExplode will mark where to split the string. And @CRLF is two characters.1 point -
Sorry my mistake. This slightly modified version of _Excel_RangeFind by water will give you the required information. What I have done is add an extra column to the output containing the excel formatted output in the last column. ; #FUNCTION# ==================================================================================================================== ; Author ........: water ; Modified.......: Bowmore ; =============================================================================================================================== Func _Excel_RangeFindEx($oWorkbook, $sSearch, $vRange = Default, $iLookIn = Default, $iLookAt = Default, $bMatchcase = Default) If Not IsObj($oWorkbook) Or ObjName($oWorkbook, 1) <> "_Workbook" Then Return SetError(1, 0, 0) If StringStripWS($sSearch, 3) = "" Then Return SetError(2, 0, 0) If $iLookIn = Default Then $iLookIn = $xlValues If $iLookAt = Default Then $iLookAt = $xlPart If $bMatchcase = Default Then $bMatchcase = False Local $oMatch, $sFirst = "", $bSearchWorkbook = False, $oSheet If $vRange = Default Then $bSearchWorkbook = True $oSheet = $oWorkbook.Sheets(1) $vRange = $oSheet.UsedRange ElseIf IsString($vRange) Then $vRange = $oWorkbook.Parent.Range($vRange) If @error Then Return SetError(3, @error, 0) EndIf Local $aResult[100][7], $iIndex = 0, $iIndexSheets = 1 ;<==== changed [6] to [7] While 1 $oMatch = $vRange.Find($sSearch, Default, $iLookIn, $iLookAt, Default, Default, $bMatchcase) If @error Then Return SetError(4, @error, 0) If IsObj($oMatch) Then $sFirst = $oMatch.Address While 1 $aResult[$iIndex][0] = $oMatch.Worksheet.Name $aResult[$iIndex][1] = $oMatch.Name.Name $aResult[$iIndex][2] = $oMatch.Address $aResult[$iIndex][3] = $oMatch.Value $aResult[$iIndex][4] = $oMatch.Formula $aResult[$iIndex][5] = $oMatch.Comment.Text $aResult[$iIndex][6] = $oMatch.Text ;<==== Added .text column $oMatch = $vRange.Findnext($oMatch) If Not IsObj($oMatch) Or $sFirst = $oMatch.Address Then ExitLoop $iIndex = $iIndex + 1 If Mod($iIndex, 100) = 0 Then ReDim $aResult[UBound($aResult, 1) + 100][7] ;<==== changed [6] to [7] WEnd EndIf If Not $bSearchWorkbook Then ExitLoop $iIndexSheets = $iIndexSheets + 1 $sFirst = "" $oSheet = $oWorkbook.Sheets($iIndexSheets) If @error Then ExitLoop $vRange = $oSheet.UsedRange WEnd ReDim $aResult[$iIndex + 1][7] ;<==== changed [6] to [7] Return $aResult EndFunc ;==>_Excel_RangeFind1 point
-
stormdead, just use winHTTP UDF This should get you started #include <WinHttp.au3> #include <Array.au3> Global $sRetur[2] $gOpen = _WinHttpOpen('Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Firefox/31.0') ;_WinHttpSetTimeouts($gOpen, 1000, 4500, 4500, 4500) $gConnect = _WinHttpConnect($gOpen, "autoitscript.com") $gRequest = _WinHttpOpenRequest($gConnect, "GET","/forum/topic/169692-how-can-i-use-iedocgetobj-to-get-responseheader/", 'HTTP/1.1') ;_WinHttpSetOption($h_openRequest, $WINHTTP_OPTION_DISABLE_FEATURE, $WINHTTP_DISABLE_COOKIES) ;$rData Then _WinHttpSetOption($gRequest, $WINHTTP_OPTION_DISABLE_FEATURE, $WINHTTP_DISABLE_REDIRECTS) ;_WinHttpAddRequestHeaders($gRequest, "Accept: image/jpeg, application/x-ms-application, image/gif, application/xaml+xml, image/pjpeg, */*") _WinHttpAddRequestHeaders($gRequest, "Accept: */*") _WinHttpAddRequestHeaders($gRequest, "Host: http://www.autoitscript.com") _WinHttpAddRequestHeaders($gRequest, "Connection: keep-alive") _WinHttpAddRequestHeaders($gRequest, "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8") ;_WinHttpAddRequestHeaders($gRequest, "Content-Type: application/x-www-form-urlencoded") ;_WinHttpAddRequestHeaders($gRequest, "Cache-Control: no-cache") _WinHttpAddRequestHeaders($gRequest, "Referer: http://www.autoitscript.com/forum/") _WinHttpAddRequestHeaders($gRequest, "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3") _WinHttpAddRequestHeaders($gRequest, "Accept-Language: en-US,en;q=0.8,en-US;q=0.6,en;q=0.4") ;_WinHttpAddRequestHeaders($gRequest, "Accept-Encoding: */q=0") ;_WinHttpAddRequestHeaders($gRequest, "Cookie: Cookie=cookievalue") _WinHttpSendRequest($gRequest) _WinHttpReceiveResponse($gRequest) If _WinHttpQueryDataAvailable($gRequest) Then $sRetur[0] = _WinHttpQueryHeaders($gRequest) While 1 $chunk = _WinHttpReadData($gRequest) If @error Then ExitLoop $sRetur[1] &= $chunk Sleep(100) WEnd EndIf _ArrayDisplay($sRetur) Exit1 point
-
Fighting what seems a losing battle at the moment. Hacker vs me and I'm lost
meows reacted to jvanegmond for a topic
Windows Firewall can do this out of the box if you go to advanced settings, but I presume you know that. When an attacker has arbitrary code execution on your machine, you're going to fight a losing battle. Keep them out in the first place on the network level. So if you're doing this kind of stuff, I honestly suggest buying a hardware firewall (with decent IDS if you have the money) and letting that manage your DMZ. If it's just a hobby, look at owned stuff a few years old.1 point -
Teensy Serial Communication
Alexxander reacted to JRSmile for a topic
Hi there, long time not seen. attached you find a little example on how to communicate with a teensy 3.0 via serial com port (USB emulated). the code uses the udf from Martin Gibson which is perfect for this kind of stuff. if you run the example the correct com port is chosen by the driver description and then a connection is opened to the teensy to send text to the device. on the arduino side the text is converted to a {ENTER} delimited string and written to the EEPROM of the device so no other components are necessary. when sending an empty string via the Teensy-Read() Function the device spits back the stored string via serial into the application. this is it. of course this is a POC and has its limitations so currently the buffer size is limited to a 50xChar string. but i find this easy enough to publish. ps: you need the arduino environment 1.0.4, teensydurino in the newest version from pjrc.com, and a teensy to make this work. autoit code: #include "CommMG.au3" $tset = _ComGetPortNames() for $i = 0 to UBound($tset,0) -1 if $tset[$i][1] = "USB Serial (Communication Class, Abstract Control Model)" Then $port = StringTrimLeft($tset[$i][0],3) EndIf Next Teensy_Write("Hallo Welt!",$port) ConsoleWrite(Teensy_Read($port)) Func Teensy_Write($text,$port) Local $result _CommSetport($port, $result, 115200, 8, 'none', 1, 1) _CommSendString($text & @LF) ConsoleWrite(_CommGetString()) _Commcloseport(True) EndFunc ;==>Teensy_Read Func Teensy_Read($port) Local $result _CommSetport($port, $result, 115200, 8, 'none', 1, 1) _CommSendString(@LF) ConsoleWrite(_CommGetString()) _Commcloseport(True) EndFunc ;==>Teensy_Read arduino code: // // EEPROM utility functions with usage example // // This example defines some utility functions // to write byte arrays, integers and strings // to eeprom and read them back. // // Some usage examples are provided. #include <EEPROM.h> // // Absolute min and max eeprom addresses. // Actual values are hardware-dependent. // // These values can be changed e.g. to protect // eeprom cells outside this range. // const int EEPROM_MIN_ADDR = 0; const int EEPROM_MAX_ADDR = 511; // // Initialize eeprom memory with // the specified byte. // Default value is 0xFF. // void eeprom_erase_all(byte b = 0xFF) { int i; for (i = EEPROM_MIN_ADDR; i <= EEPROM_MAX_ADDR; i++) { EEPROM.write(i, b); } } // // Dump eeprom memory contents over serial port. // For each byte, address and value are written. // void eeprom_serial_dump_column() { // counter int i; // byte read from eeprom byte b; // buffer used by sprintf char buf[10]; for (i = EEPROM_MIN_ADDR; i <= EEPROM_MAX_ADDR; i++) { b = EEPROM.read(i); sprintf(buf, "%03X: %02X", i, b); Serial.println(buf); } } // // Dump eeprom memory contents over serial port in tabular form. // Each printed row shows the value of bytesPerRow bytes // (by default 16). // void eeprom_serial_dump_table(int bytesPerRow = 16) { // address counter int i; // row bytes counter int j; // byte read from eeprom byte b; // temporary buffer for sprintf char buf[10]; // initialize row counter j = 0; // go from first to last eeprom address for (i = EEPROM_MIN_ADDR; i <= EEPROM_MAX_ADDR; i++) { // if this is the first byte of the row, // start row by printing the byte address if (j == 0) { sprintf(buf, "%03X: ", i); Serial.print(buf); } // read current byte from eeprom b = EEPROM.read(i); // write byte in hex form sprintf(buf, "%02X ", b); // increment row counter j++; // if this is the last byte of the row, // reset row counter and use println() // to start a new line if (j == bytesPerRow) { j = 0; Serial.println(buf); } // else just print the hex value with print() else { Serial.print(buf); } } } // // Returns true if the address is between the // minimum and maximum allowed values, // false otherwise. // // This function is used by the other, higher-level functions // to prevent bugs and runtime errors due to invalid addresses. // boolean eeprom_is_addr_ok(int addr) { return ((addr >= EEPROM_MIN_ADDR) && (addr <= EEPROM_MAX_ADDR)); } // // Writes a sequence of bytes to eeprom starting at the specified address. // Returns true if the whole array is successfully written. // Returns false if the start or end addresses aren't between // the minimum and maximum allowed values. // When returning false, nothing gets written to eeprom. // boolean eeprom_write_bytes(int startAddr, const byte* array, int numBytes) { // counter int i; // both first byte and last byte addresses must fall within // the allowed range if (!eeprom_is_addr_ok(startAddr) || !eeprom_is_addr_ok(startAddr + numBytes)) { return false; } for (i = 0; i < numBytes; i++) { EEPROM.write(startAddr + i, array[i]); } return true; } // // Reads the specified number of bytes from the specified address into the provided buffer. // Returns true if all the bytes are successfully read. // Returns false if the star or end addresses aren't between // the minimum and maximum allowed values. // When returning false, the provided array is untouched. // // Note: the caller must ensure that array[] has enough space // to store at most numBytes bytes. // boolean eeprom_read_bytes(int startAddr, byte array[], int numBytes) { int i; // both first byte and last byte addresses must fall within // the allowed range if (!eeprom_is_addr_ok(startAddr) || !eeprom_is_addr_ok(startAddr + numBytes)) { return false; } for (i = 0; i < numBytes; i++) { array[i] = EEPROM.read(startAddr + i); } return true; } // // Writes an int variable at the specified address. // Returns true if the variable value is successfully written. // Returns false if the specified address is outside the // allowed range or too close to the maximum value // to store all of the bytes (an int variable requires // more than one byte). // boolean eeprom_write_int(int addr, int value) { byte *ptr; ptr = (byte*)&value; return eeprom_write_bytes(addr, ptr, sizeof(value)); } // // Reads an integer value at the specified address. // Returns true if the variable is successfully read. // Returns false if the specified address is outside the // allowed range or too close to the maximum vlaue // to hold all of the bytes (an int variable requires // more than one byte). // boolean eeprom_read_int(int addr, int* value) { return eeprom_read_bytes(addr, (byte*)value, sizeof(int)); } // // Writes a string starting at the specified address. // Returns true if the whole string is successfully written. // Returns false if the address of one or more bytes // fall outside the allowed range. // If false is returned, nothing gets written to the eeprom. // boolean eeprom_write_string(int addr, const char* string) { // actual number of bytes to be written int numBytes; // we'll need to write the string contents // plus the string terminator byte (0x00) numBytes = strlen(string) + 1; return eeprom_write_bytes(addr, (const byte*)string, numBytes); } // // Reads a string starting from the specified address. // Returns true if at least one byte (even only the // string terminator one) is read. // Returns false if the start address falls outside // or declare buffer size os zero. // the allowed range. // The reading might stop for several reasons: // - no more space in the provided buffer // - last eeprom address reached // - string terminator byte (0x00) encountered. // The last condition is what should normally occur. // boolean eeprom_read_string(int addr, char* buffer, int bufSize) { // byte read from eeprom byte ch; // number of bytes read so far int bytesRead; // check start address if (!eeprom_is_addr_ok(addr)) { return false; } // how can we store bytes in an empty buffer ? if (bufSize == 0) { return false; } // is there is room for the string terminator only, // no reason to go further if (bufSize == 1) { buffer[0] = 0; return true; } // initialize byte counter bytesRead = 0; // read next byte from eeprom ch = EEPROM.read(addr + bytesRead); // store it into the user buffer buffer[bytesRead] = ch; // increment byte counter bytesRead++; // stop conditions: // - the character just read is the string terminator one (0x00) // - we have filled the user buffer // - we have reached the last eeprom address while ( (ch != 0x00) && (bytesRead < bufSize) && ((addr + bytesRead) <= EEPROM_MAX_ADDR) ) { // if no stop condition is met, read the next byte from eeprom ch = EEPROM.read(addr + bytesRead); // store it into the user buffer buffer[bytesRead] = ch; // increment byte counter bytesRead++; } // make sure the user buffer has a string terminator // (0x00) as its last byte if ((ch != 0x00) && (bytesRead >= 1)) { buffer[bytesRead - 1] = 0; } return true; } // // SETUP // const int BUFSIZE = 50; char buf[BUFSIZE]; String name = ""; boolean nameEntered = false; void setup() { int i; delay(5000); Serial.begin(115200); //strcpy(buf, "Arduino eeprom utility functions."); //Serial.println("Saving string to eeprom..."); //eeprom_write_string(100, buf); Serial.println("Reading string from eeprom..."); eeprom_read_string(100, buf, BUFSIZE); Serial.print("String read: '"); Serial.print(buf); Serial.println("'"); } // // LOOP // void loop() { // If new data has been entered, // read each character into the name variable. while (Serial.available()) { char readChar = (char)Serial.read(); // If the next character is a linefeed (enter) // the name is complete. Exit the while() loop. if (readChar == '\n') { nameEntered = true; continue; } // If the character wasn't enter, add it to the name string. name += readChar; } // If a name has been entered (followed by \n) // print "Hello name!" if (nameEntered) { if (name != ""){ name.toCharArray(buf,50); //strcpy(buf, name); eeprom_write_string(100, buf); Serial.print("String: '"); Serial.print(name); Serial.println("' saved to EEPROM!"); } else { eeprom_read_string(100, buf, BUFSIZE); Serial.print("String read: '"); Serial.print(buf); Serial.println("'"); } // Once the name has been printed, erase it and start over. name = ""; nameEntered = false; } }1 point -
WAnt to Activate a Program Minimised to System Tray
SorryButImaNewbie reacted to DW1 for a topic
For something simpler, if you know the window title: WinSetState('WINTITLE', '', @SW_RESTORE)1 point