Leaderboard
Popular Content
Showing content with the highest reputation on 06/21/2023 in all areas
-
MbTcp - Modbus TCP UDF
marcoauto and one other reacted to kurtykurtyboy for a topic
Here is something that I have been wanting in AutoIt for years but sadly no one had created it yet. Well, I decided to hunker down and do something about it! I present to you, MbTCP - a Modbus TCP/IP UDF. What is Modbus? Modbus is a communications protocol commonly used to communicate with various types of PLC's, sensors, SCADA systems, and many other industrial applications. Modbus TCP is the ethernet variant (as opposed to Modbus RTU which uses a serial connection). This UDF takes care of all the behind-the-scenes legwork and makes it easy to get right to the data. No need to worry about which function codes to use or how to format the data. Modbus typically works on discrete coils and inputs (think BOOL) or 16-bit registers (think INT). However, some devices support 32-bit signed and unsigned integers and 32-bit floating point numbers. This is possible by reading or writing 2 consecutive 16-bit registers and formatting them on both ends. The UDF will take care of all that as well (although maybe not in the most sophisticated ways...š ). Because there is no standard for working with 32-bit numbers, it is necessary to have the option to enable or disable big-endianness. Similarly, not all devices start counting at register 1. Some of them actually start at register 0. The UDF allows you to define these parameters when creating the connection to the device. Available data types for input and holding registers are INT16, UINT16, INT32, UINT32, and FLOAT32. Function List: ; _MbTcp_Connect ......................: Open a connection to a remote device ; _MbTcp_ReadCoils ....................: Read 1 or more output coils (function code 1) ; _MbTcp_ReadDiscreteInputs ...........: Read 1 or more discrete inputs (function code 2) ; _MbTcp_ReadHoldingRegisters .........: Read 1 or more holding registers (function code 3) ; _MbTcp_ReadInputRegisters ...........: Read 1 or more input registers (function code 4) ; _MbTcp_WriteCoils ...................: Write 1 or more output coils (function code 5 and 15) ; _MbTcp_WriteRegisters ...............: Write 1 or more holding registers (function code 6 and 16) ; _MbTcp_Disconnect ...................: Close the connection to a device ; _MbTcp_DisconnectAll ................: Close the connection to all connected devices To get started, follow these easy steps: Create a new connection to the device using _MbTcp_Connect Call any of the available read or write functions That's it. The program will automatically clean up any connections that are left open on exit. You may also manually disconnect from any device if needed. The most basic example of use. Connect to a device and read one holding register starting at register 2. #include "MbTcp.au3" ;connect to device at IP 127.0.0.1 Local $iConnection1 = _MbTcp_Connect("127.0.0.1") If @error Then MsgBox(16, "Error", "Failed to connect to the Modbus device at 127.0.0.1." & @CRLF & "Error Code: " & @error) Exit Else ConsoleWrite("Successfully connected to device at 127.0.0.1" & @CRLF) EndIf ;read 1 holding register Local $iReadData = _MbTcp_ReadHoldingRegisters($iConnection1, 2, 1) If @error Then MsgBox(16, "Error", "Failed to read the Modbus value." & @CRLF & "Error Code: " & @error) Else ConsoleWrite("Value: " & $iReadData & @CRLF) EndIf The next example shows how we can format the data to return an unsigned integer instead of the default signed integer. In the following example, we connect to a device that uses big-endian word order and starts at register 0 instead of 1. Then we read and write a group of registers. I may add more examples here if needed. There are a number of Modbus simulators out there if you want to test locally on your computer. But I really like a tool named Mod_RSsim link. Let me know if you find any issues. I know I will probably end up needing to add a timeout option. MbTcp_20230620.zip2 points -
WebDriver UDF - Help & Support (IV)
ThomasBennett and one other reacted to mLipok for a topic
Today I hit new problem. And found solution here: How to prevent Firefox to auto-check āremember decisionā in certificates choice? _WD_CapabilitiesAdd("prefs", "security.remember_cert_checkbox_default_setting", False)2 points -
Yes, if it can recognize the window, and interact with the buttons. Have a go at creating something code wise, and plenty of folk here will advise on solutions for what you might have trouble with. As they say, we can teach you to fish, rather than fish for you.1 point
-
fraizor, Look at _FileListToArrayRec in the Help file. M231 point
-
In the example above result of $aMatches is definitely not 1. Show me what you run when you got this result.1 point
-
Something like this? #include <Array.au3> $sData = 'echo $? whatever data is here' & @LF & '0' $aMatches = StringRegExp($sData, 'echo \$\?(.+)', 3) _ArrayDisplay($aMatches)1 point
-
Variable Assign - (Moved)
ashraful089 reacted to bogQ for a topic
readability of code should always take priority than code minimality, aldo i really don't like to use Assign or Eval, you can add var names to array and use Werty code to set their value directly from array or var names edit with example: AutoIt3Wrapper_Run_AU3Check needed to allow to run due to undeclared warning #AutoIt3Wrapper_Run_AU3Check=N #include <AutoItConstants.au3> Local $var = 100, $varnames=["var1","var2","var3"] For $x = 0 To UBound($varnames) - 1 Assign($varnames[$x], $var, $ASSIGN_FORCELOCAL) Next ConsoleWrite("var1 = " & $var1 & @CRLF) ConsoleWrite("var2 = " & $var2 & @CRLF) ConsoleWrite("var3 = " & $var3 & @CRLF) #cs ;~ or Local $var = 100, $varnames=["var1","var2","var3","var4","var5","var6","var7","var8","var9","var10"] For $x = 0 To UBound($varnames)-1 Assign($varnames[$x], $var, $ASSIGN_FORCELOCAL) ConsoleWrite($varnames[$x]&" = " & Eval($varnames[$x]) & @CRLF) Next #ce1 point -
New string TRIM() functions
KeeperOfTheReaper reacted to blitzer99 for a topic
My thanks to the guys on my forum topic "Enhancement to string TRIM functions" who provided the inspiration (and a lot of the code) for four new string TRIM() functions: _LTRIM() _RTRIM(), _ALLTRIM() and _TRIM(). These functions trim unwanted characters from the left, right or both ends of a character string. The default characters trimmed are spaces but more than one contiguous character can be trimmed it once. For example back slashes and spaces my be trimmed together. The functions that achieve this result are included in the attached file along with installation instructions, reproduced below. ================================================================== Purpose: Implements new functions _RTRIM(), _LTRIM(), _ALLTRIM(), _TRIM() To implement functions equivalent to the old dBase functions that removed spaces from the, respectively, right, left and both left and right of a character string. The function _TRIM() is equivalent to _RTRIM() and is provided for consistency with the old dBase standard. These four functions remove contiguous characters from the left and/or right of a character string but not those that are within the string. For example _RTRIM("Mary had a little lamb ") will become "Mary had a little lamb" - the spaces inside the string are not removed. Syntax: ResultString = <FunctionName>( string1, string2 ) <FunctionName> as above: _RTRIM(), _LTRIM(), _ALLTRIM(), _TRIM() string1 is the character string to examine. string2 is a list of the characters to be examined for; if omitted it defaults to the standard space character, chr(32). ResultString is the string returned by the function with all characters in string2 trimmed from the left and/or right of string1. If string2 = "%%whs%%" all white space characters will be trimmed from string1. Whitespace includes Chr(9) thru Chr(13) which are HorizontalTab, LineFeed, VerticalTab, FormFeed, and arriageReturn. Whitespace also includes the standard space character. ResultString will be shorter than string1 by an amount equal to the number of characters trimmed from string1. These functions are not case sensitive, e.g. "m" in string2 will trim both "M" and "m" from string1. On any error condition ResultString will be equal to string1. Examples: _RTRIM("Mary had a little lamb ") -> "Mary had a little lamb" _RTRIM("Mary had a little giraffe xyxyxyz", "xyz") -> "Mary had a little giraffe " (note space at end has not been removed). _RTRIM("Mary had a little giraffe xyxyxyz", " xyz") -> "Mary had a little giraffe" (now the same space has been removed because a space is now included in string2). _RTRIM("Mary had a little giraffe xyxbyxyz", "xyz") -> "Mary had a little giraffe xyxb" (only the x, y and z following the "b" will be removed because the "b" is not in string2. To use: 1. Copy this script to the "Include" folder under the AutoIt programs folder. (for example: c:\program files\autoit3\include\myfunctions.au3 ) 2. In your Autoit3 script have following statement: #include <myfunctions.au3> 3. "myfunctions" can be renamed to anything you want. Disclaimer: Thoroughly tested and debugged, but use entirely at your own risk. Usage automatically acknowledges acceptance of this condition. MyFunctions.zip1 point