leapingleon Posted March 14, 2007 Posted March 14, 2007 Hi All I am using the following script to capture all info from my COM port and write it in a text file: $comport=FILEOPEN("COM2", 0) $tmp="C:\Documents and Settings\Administrator.SERVER\Desktop\TEST.txt" While 1 $data = FILEREAD($comport, 1) $output=FILEOPEN($tmp,1) FILEWRITE($output,$data) FILECLOSE($output) Wend However its not feasably to keep it running 24hrs a day as it consumes 50% of my CPU. 1) Is there any way to reduce this by say catching the data only when it comes, as its not a constant data flow. 2) Will this catch ALL the data? say if two messages come to the COM port at once an this script catches the first one, and processes it, will it still catch the second one too? Thanks for your help
lod3n Posted March 14, 2007 Posted March 14, 2007 First of all, I had no idea you could capture stuff from the com port in this way. Nifty. Second, why not something like this:$comport=FILEOPEN("COM2", 0) $tmp="C:\Documents and Settings\Administrator.SERVER\Desktop\TEST.txt" While 1 $data = FILEREAD($comport, 1) if stringLen($data) > 0 then FileWriteLine($tmp,$data) endif Wend [font="Fixedsys"][list][*]All of my AutoIt Example Scripts[*]http://saneasylum.com[/list][/font]
DaleHohm Posted March 14, 2007 Posted March 14, 2007 There is a COM interface that you can use that will allow you to make this event driven. See the phone dialer link in my Sig. Dale 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
leapingleon Posted March 16, 2007 Author Posted March 16, 2007 Thanks Dale, think I am going to try that way, however Im still new to AutoIT, so just say if I am on the wrong track etc. Here is where I am so far: $tmp="C:\Documents and Settings\Administrator.SERVER\Desktop\TEST.txt" $com = ObjCreate ("NETCommOCX.NETComm") $SinkObject = ObjEvent($com,"COMEvent_") With $com .CommPort = 2 .PortOpen = True .Settings = "9600,N,8,1" .InBufferCount = 0 EndWith Func COMEvent_InputData($data) MsgBox(0,"",$data) $output=FILEOPEN($tmp,1) FILEWRITE($output,$data) FILECLOSE($output) EndFunc
DaleHohm Posted March 16, 2007 Posted March 16, 2007 It has been a long time since I've looked at this, but it looks good conceptually. Give it a shot. Dale 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
leapingleon Posted March 16, 2007 Author Posted March 16, 2007 It has been a long time since I've looked at this, but it looks good conceptually. Give it a shot.DaleI was sort of hoping you would see and problem. I ran it and nothing happens. It just seems to popup and then dissapear straight away. My intention was to leave it running continuosly so that it could capture all data sent to COM2. I dont want to use an infinite loop, because that consumes alot of CPU, therefore I was hoping this event driven approach would work better.By the way, I dont get any errors from it, so it seems to work, but because its not running all the time it doesnt capture the data.
DaleHohm Posted March 16, 2007 Posted March 16, 2007 Ah... didn't know youy intended it to be a standalone piece of code. To make it work you need to have an idle loop, e.g. While 1 Sleep(100) Wend Dale 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
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