n9mfk9 Posted August 21, 2006 Share Posted August 21, 2006 hi all I have this code i like to convert to autoit Use functions ToVariant() and FromVariant(); others serve as helpers only. */ function ToVariant (x) { if (x == null); else if (typeof(x) == "object") { if (x.getDate) { // cross-frame-safe determination of Date object return ToVBDate_((x - vbDateBase_)/86400000); // msec per day } else if (x.sort) { // cross-frame-safe determination of Array object return ToVBArray_(x); } else return x.valueOf(); } else return x; } function FromVariant (v) { switch (typeof(v)) { case "date": return new Date(v); case "unknown": // VBArray var a = (new VBArray(v)).toArray(); for (var i=0; i < a.length; i++) a = FromVariant(a); return a; default: return v; } } Array.prototype.getVariantAt = function (i) { return ToVariant(this); } // GetVariantAt is slower than Array.prototype.getVariantAt, // but enables "cross-frame calling" function GetVariantAt (arr, i) { return ToVariant(arr); } //--> </SCRIPT><script language="VBScript"> <!-- Dim vbDateBase_ vbDateBase_ = CDate(0) function ToVBDate_ (d) ToVBDate_ = CDate(d) end function function ToVBArray_ (arr) Dim ubound, a(), i ubound = arr.length - 1 Redim a(ubound) for i=0 to ubound ' a(i) = arr.getVariantAt(i) a(i) = GetVariantAt(arr, i) ' slower, but enables "cross-frame calling" next ToVBArray_ = a end function --> </SCRIPT> <object classid="clsid:53867031-6B4D-4F7D-B089-5DFEC731F5FA" id="NETComm1"> <param name="Settings" value="9600, N, 8, 1"> <param name="CommPort" value="1"> <param name="Handshaking" value="0"> <param name="InputBufferSize" value="0"> <param name="InputLength" value="0"> <param name="InputMode" value="0"> <param name="NullDiscard" value="0"> <param name="OutputBufferSize" value="1024"> <param name="ParityReplace" value="?"> <param name="OnCommReceiveThreshold" value="0"> <param name="RTSEnable" value="-1"> <param name="OnCommSendThreshold" value="0"> <param name="DTREnable" value="-1"> </object> <form name=serialdata> <table> <tr> <td> Input</td> <td><input type=text name=read_data></td> <td></td> </tr> <tr> <td>Output</td> <td><input type=text name=write_data></td> <td><input type=button onclick="port_write()" value="Send"></td> </tr> </table> <br> <br> <table> <tr> <td>COM port</td> <td><input type=text name=port value="1"></td> </tr> <tr> <td>Settings</td> <td><input type=text name=settings value="9600, N, 8, 1"></td> </tr> <tr> <td></td> <td> <input type=button onclick="port_start()" value="Start"> <input type=button onclick="port_stop()" value="Stop"> </td> </tr> </table> </form> <script language="javascript" id="test"> <!-- function port_start() { NETComm1.CommPort = document.serialdata.port.value; NETComm1.Settings = document.serialdata.settings.value; NETComm1.RThreshold = 1; NETComm1.PortOpen = true; } function port_stop() { NETComm1.PortOpen = false; } function port_write() { NETComm1.Output = document.serialdata.write_data.value; } //--> </script> <script for="NETComm1" event="OnComm()" language="Javascript"> <!-- if(NETComm1.InBufferCount == 0) { // } else { document.serialdata.read_data.value = NETComm1.InputData; } </script> </BODY> </HTML> here the cdre i have startwed $netcomm1 = ObjCreate ("NETCommOCX.NETComm") $output= "Fr0;" With $netcomm1 .Settings = "9600,N,8,1" .commPort = 4 .Handshaking= 0 .InBufferSize = 1024 .InputLen = 0 .InputMode= 0 .NullDiscard= 0 .OutBufferSize= 1024 .ParityReplace="?" ;rem .OnmReceiveThreshold= 0 .RTSEnable= -1 ; .OnmSendThreshold= 0 .DTREnable= -1 ;.PortOpen = true ;.output =$output .InputData EndWith Call("start") call("write") Call("stop") Func Start() with $netcomm1 .CommPort = 4 .Settings = "9600,N,8,1" .RThreshold = 1 .PortOpen = true endwith EndFunc Func Stop() With $netcomm1 .portopen = FALSE endwith EndFunc Func write() $netcomm1.output = $output EndFunc dim $read ;msgbox(0,"", $read) ;ObjEvent($test iam not shure how to convert the oncomm event to autoit thanks beau Link to comment Share on other sites More sharing options...
DaleHohm Posted August 21, 2006 Share Posted August 21, 2006 (edited) Assuming by "oncomm" you mean NetComm, see the phone dialer post in my sig for an example. Dale Edited August 21, 2006 by DaleHohm Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model Automate input type=file (Related) Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded Better Better? IE.au3 issues with Vista - Workarounds SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead? Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble 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