AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

[Solved] COM Assistance Request
Goto page 1, 2, 3  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
TodWulff



Joined: 29 Dec 2007
Posts: 99

PostPosted: Sun Mar 16, 2008 3:29 am    Post subject: [Solved] COM Assistance Request Reply with quote

OK, I have been reading and reading and just can't get my gray matter wrapped abound a couple of concepts related to the use of COM objects from within the AHK environment.

Before I get to a couple of initial queries, let me make an observation:

It appears that the CoHelper.ahk code located on the wiki's CoHelper Page is woefully outdated. If it is too much work to maintain a couple of different instances of the source, would it not be better to link to a single source file? This caused me some grief (an hour or so of my life...) as I had presumed that the wiki would have latest version along with some primer guidance that one could reference to get a bit up to speed. I was wrong on both counts. I hope that this will get resolved soon, so others don't stumble around in the dark woods without at least a flashlight...

[EDIT]OK, before the flame throwers get broken out, yes, I fixed the link on the Wiki - kinda forgot what a wiki was all about, for a minute... Rolling Eyes Embarassed [/EDIT]

Ok, on to my struggles, now that I've found some batteries Smile:

First, as it relates to a COM wrapper, I see basically 2 different wrappers - 1st is CoHelper.ahk, and 2nd is COM.ahk. I guess that I am a bit confused about which one is more appropriate to use. It seems that CoHelper may have more tenure, but I am wondering if COM.ahk isn't a refined solution and that CoHelper is maintained in the interests of backward compatibility.?. Could someone please advise which solution would be best tackled by someone with little to no experience with COM?

Second, is there a primer that describes the high-level concepts that need to be understood in order to experience success with COM?

i.e. I am trying to make use of either native OS resources, or make use of a third-party dll, in order to achieve proper Comm Port connectivity. The third-party dll seems to hold the most promise as it is a targeted solution. I am entertaining making use of ActiveXpert's ACP DLL. The ActiveComPort manual serves to explain it in pretty grasp-able terms. It seems that they wrote the tool to be used in environment that support COM and/or ActiveX objects. The Properties and Functions are pretty well documented. What I am struggling with is getting started. Basically, if I understand things correctly, I need to initiate the tool, open a port, control the DTR/RTS signal lines, and Transmit/Receive Data @ 19200 baud. I have experienced success with port.dll, mentioned several times on these forums, but it is painfully slow (kernel interaction overhead.?.), and a faster solution is needed. Too bad there isn't a EasyCom.DLL (yes, I read the abandoned thread), as I get calling DLLs. This Object stuff has me struggling, however, as I possess absolutely zero oop experience or training...

Can someone help to point me in the right direction, please, maybe with a little push (or hard shove - just not off of the cliff Smile)?

Thanks, in advance.

-t


Last edited by TodWulff on Wed Mar 19, 2008 3:35 am; edited 1 time in total
Back to top
View user's profile Send private message
Lexikos



Joined: 17 Oct 2006
Posts: 2737
Location: Australia, Qld

PostPosted: Sun Mar 16, 2008 5:55 am    Post subject: Reply with quote

I believe CoHelper.ahk and COM.ahk are not being maintained, since Sean left the forums. COM.ahk is more up-to-date. I would also recommend it since it is function library-compatible.
Quote:
Second, is there a primer that describes the high-level concepts that need to be understood in order to experience success with COM?
Not in relation to AutoHotkey. There are probably countless generic COM tutorials out there, but you may be better off learning from the examples around the forum.
Quote:
Too bad there isn't a EasyCom.DLL
Have you seen Embedded Windows Scripting (VBScript & JScript) and COM?
Back to top
View user's profile Send private message
TodWulff



Joined: 29 Dec 2007
Posts: 99

PostPosted: Sun Mar 16, 2008 6:07 am    Post subject: Reply with quote

Lexikos wrote:
I believe CoHelper.ahk and COM.ahk are not being maintained, since Sean left the forums. COM.ahk is more up-to-date. I would also recommend it since it is function library-compatible.

Sad Too bad about Sean, really... I'll review the link and see if I can grasp what you are getting at regarding function-library compatibility.

Lexikos wrote:
Quote:
Second, is there a primer that describes the high-level concepts that need to be understood in order to experience success with COM?
Not in relation to AutoHotkey. There are probably countless generic COM tutorials out there, but you may be better off learning from the examples around the forum.

Thanks for finishing my query - yes, I intended to state "...within the AHK environment." I have actually gotten the ACP.dll to initialize and barf back it's version just within the last hour or so, so I am making progress. I am currently hung on getting data back from the object. I'll keep plugging away - persistence has a way of paying off...

Lexikos wrote:
Quote:
Too bad there isn't a EasyCom.DLL
Have you seen Embedded Windows Scripting (VBScript & JScript) and COM?

I saw it. I guess I need to take note and learn it.

Thanks, kind sir(?)!

-t
Back to top
View user's profile Send private message
Guest






PostPosted: Sun Mar 16, 2008 6:22 am    Post subject: Reply with quote

I believe the best way to learn how to use COM is to try to translate existing codes. I took an example from the page you linked.

Code:
COM_Init()
objComport := COM_CreateObject("ActiveXperts.Comport")

COM_Invoke(objComport, "Device=", "COM1")
COM_Invoke(objComport, "BaudRate=", 56000)
COM_Invoke(objComport, "HardwareFlowControl=", True)
COM_Invoke(objComport, "SoftwareFlowControl=", False)

COM_Invoke(objComport, "Open")
COM_Invoke(objComport, "WriteString", "at&f")
str := COM_Invoke(objComport, "ReadString")
MsgBox, % "Received: [" . str . "]"
COM_Invoke(objComport, "Close")

COM_Release(objComport)
COM_Term()
Back to top
TodWulff



Joined: 29 Dec 2007
Posts: 99

PostPosted: Sun Mar 16, 2008 6:32 am    Post subject: Reply with quote

OMG - didn't think about trying it the way you suggested (instantiating the object):
Code:
objComport := COM_CreateObject("ActiveXperts.Comport")


I ended up having to resort to a 'older' implementation:

Code:
   ; App_Object := "AComport.dll"
   ; pdic := ActiveXObject(App_Object)
   ; ^^^ didn't work
   
   ; App_AppID := "{68A2C188-A606-4841-AE8A-D58C6F6BE583}"
   ; pdic := ActiveXObject(App_AppID)
   ; ^^^ didn't work
   
   App_ClsID := "{07ECB42B-322A-40B9-A8A9-3815AF3C4F60}"
   App_IntID := "{38014DE4-7967-4F71-A6C1-CDB62E7DD269}"
   pdic := CreateObject(App_ClsID,App_IntID)
   ; ^^^ worked - had to use the TLB to get the vitals...


I was surprised at how painless it was, once I got the syntax correct.

I'll give your suggested code a whirl. Thank you.

-t
Back to top
View user's profile Send private message
TodWulff



Joined: 29 Dec 2007
Posts: 99

PostPosted: Sun Mar 16, 2008 9:37 pm    Post subject: Reply with quote

Ok, I have experienced some success with using the ACP dll via COM.ahk.

However I am having issue with getting one set of functions to work with the ACP object. Specifically, the RaiseDTR construct.

From a working VB app:

Code:
Private Sub CheckDTR_Click()
   
    objComport.RaiseDTR (CheckDTR.Value)
    GetResult

End Sub


I have tried the following:
Code:
   COM_Invoke(ObjComport, "RaiseDTR", "+" . "1")
      x := COM_Invoke(ObjComport, "GetErrorDescription", COM_Invoke(ObjComport, "LastError"))
      msgbox,,, Error = %x%, .5

Code:
   COM_Invoke(ObjComport, "RaiseDTR", "+" . 1)
      x := COM_Invoke(ObjComport, "GetErrorDescription", COM_Invoke(ObjComport, "LastError"))
      msgbox,,, Error = %x%, .5

Code:
   COM_Invoke(ObjComport, "RaiseDTR=", "1")
      x := COM_Invoke(ObjComport, "GetErrorDescription", COM_Invoke(ObjComport, "LastError"))
      msgbox,,, Error = %x%, .5

Code:
   COM_Invoke(ObjComport, "RaiseDTR=", 1)
      x := COM_Invoke(ObjComport, "GetErrorDescription", COM_Invoke(ObjComport, "LastError"))
      msgbox,,, Error = %x%, .5


Also, I have tried, as an argument TRUE, "TRUE", etc. Just about every conceivable iteration that I could come up with to try to get COM.ahk to feed the object the correct parameters - all to no avail.

In all cases, the error returned is 'Success' (0), but with the logging that is facilitated by the ACP.dll, I can see where it is not getting commanded properly as there are not any entries consistent with setting the DTR state.

However, if I look at the log file when the VB test app is running, I can see the following entries logged:
Code:
...
[15:30:48] SET DTR [LO], result=[Error #0: Success]
[15:30:51] SET DTR [HI], result=[Error #0: Success]
...


And when I have a third party app monitoring the Serial Port, I am seeing no DTR activity with my code, but I am seeing the state of DTR altering as expected when the VB app is running...

Any suggestions?

Full test source:
Code:
   #singleinstance force
   #include COM.ahk
   #NoEnv
   
   COM_Init()
   objComport := COM_CreateObject("ActiveXperts.Comport")
   COM_Invoke(ObjComport, "LogFile=", "C:\Documents and Settings\todw\Desktop\ACP.log")
   COM_Invoke(ObjComport, "Device=", "COM3") ;com3
   ; COM_Invoke(ObjComport, "BaudRate=", 19200) ; 19200
   ; COM_Invoke(ObjComport, "Parity=", 1) ; n
   ; COM_Invoke(ObjComport, "DataBits=", 8) ; 8
   ; COM_Invoke(ObjComport, "StopBits=", 1) ; 1
   ; COM_Invoke(ObjComport, "HardwareFlowControl=", 2) ; enabled
   ; COM_Invoke(ObjComport, "SoftwareFlowControl=", 2) ; enabled
   ; COM_Invoke(ObjComport, "RTSFlowControl=", 2) ; enabled
   ; COM_Invoke(ObjComport, "DTRFlowControl=", 2) ; enabled
   COM_Invoke(ObjComport, "Open")

   COM_Invoke(ObjComport, "RaiseDTR", "+" . "1")
      x := COM_Invoke(ObjComport, "GetErrorDescription", COM_Invoke(ObjComport, "LastError"))
      msgbox,,, Error = %x%, 1

   COM_Invoke(ObjComport, "RaiseDTR", "+" . 1)
      x := COM_Invoke(ObjComport, "GetErrorDescription", COM_Invoke(ObjComport, "LastError"))
      msgbox,,, Error = %x%, 1

   COM_Invoke(ObjComport, "RaiseDTR=", "1")
      x := COM_Invoke(ObjComport, "GetErrorDescription", COM_Invoke(ObjComport, "LastError"))
      msgbox,,, Error = %x%, 1

   COM_Invoke(ObjComport, "RaiseDTR=", 1)
      x := COM_Invoke(ObjComport, "GetErrorDescription", COM_Invoke(ObjComport, "LastError"))
      msgbox,,, Error = %x%, 1

   COM_Invoke(objComport, "Close")
   COM_Release(objComport)
   COM_Term()


Log file from two run attempts with my script:
Code:
[17:27:31] OPEN DEVICE [ActiveComport Build 3.0.7.1212], Device=[COM3], Baudrate=[default], settings=[D,D,D], HWFlowCtrl=[default], SWFlowCtrl=[default], result=[Error #0: Success]
[17:27:33] CLOSE DEVICE
[17:28:15] OPEN DEVICE [ActiveComport Build 3.0.7.1212], Device=[COM3], Baudrate=[default], settings=[D,D,D], HWFlowCtrl=[default], SWFlowCtrl=[default], result=[Error #0: Success]
[17:28:18] CLOSE DEVICE


Log file from a good VB session:
Code:
[17:15:55] OPEN DEVICE [ActiveComport Build 3.0.7.1212], Device=[COM3], Baudrate=[default], settings=[D,D,D], HWFlowCtrl=[default], SWFlowCtrl=[default], result=[Error #0: Success]
[17:15:57] SET DTR [HI], result=[Error #0: Success]
[17:15:58] SET DTR [LO], result=[Error #0: Success]
[17:16:00] CLOSE DEVICE


Please review and advise. Thank you.

-t

p.s. I do know that the error fetching and display constructs in my source is working as if I leave the VB app running by accident, and I run the test script, I get a msgbox of "Error = Generic port open error" on all 4 attempts...

p.s.s. Where is the syntax guidance for Msgbox where it describes the use of the % operator in line like you have done in your suggested code?:
Code:
...
MsgBox, % "Received: [" . str . "]"
...
I looked and couldn't fine any reference to it's use in this fashion... TIA. -t
Back to top
View user's profile Send private message
Guest






PostPosted: Sun Mar 16, 2008 11:04 pm    Post subject: Reply with quote

TodWulff wrote:
Code:
Private Sub CheckDTR_Click()
   
    objComport.RaiseDTR (CheckDTR.Value)
    GetResult

End Sub

From this, RaiseDTR is certainly Method, not PropertyPut. You must not suffix it with = for Method/PropertyGet. And the parameter is simply a value (:LONG or BOOL?), not an object. So, again you must not prefix it with +. Thus
Code:
COM_Invoke(ObjComport, "RaiseDTR", 1)


Quote:
Code:
...
MsgBox, % "Received: [" . str . "]"
...

This page may be of help:
http://www.autohotkey.com/docs/Functions.htm
Back to top
TodWulff



Joined: 29 Dec 2007
Posts: 99

PostPosted: Sun Mar 16, 2008 11:25 pm    Post subject: Reply with quote

Anonymous wrote:
TodWulff wrote:
Code:
Private Sub CheckDTR_Click()
   
    objComport.RaiseDTR (CheckDTR.Value)
    GetResult

End Sub

From this, RaiseDTR is certainly Method, not PropertyPut. You must not suffix it with = for Method/PropertyGet. And the parameter is simply a value (:LONG or BOOL?), not an object. So, again you must not prefix it with +. Thus
Code:
COM_Invoke(ObjComport, "RaiseDTR", 1)


OK ... call me an idiot ... Guess I didn't try "every" iteration... Embarassed Embarassed

For the record, I did not take from the COM/CoHelper page that that version of the construct was valid, so I simply dismissed it as an option. I only saw the function= and + . pram options as the only two way to invoke the command...

I just tested it and it works exactly as expected. Thank you.!.

Ya know, some say 'ignorance is bliss.' - I've got only one response for that ... "BS!" I hate wasting my time and the time of others because of my ignorance... Sorry.

Anonymous wrote:
This page may be of help:
http://www.autohotkey.com/docs/Functions.htm

It was (er, still is Smile). I was just reading up some more on threads and functions when I saw the text about same. Thank you!
Back to top
View user's profile Send private message
Guest






PostPosted: Mon Mar 17, 2008 12:04 am    Post subject: Reply with quote

It's OK. That's learning anyway. IMO, all these inconveniences arise from the fact that COM is realized through an external script in AHK, not as the built-in functionality.
Back to top
TodWulff



Joined: 29 Dec 2007
Posts: 99

PostPosted: Mon Mar 17, 2008 12:36 am    Post subject: Reply with quote

Thanks. I concur on the use of the script vs. built in facilities...

Seeing as I digressed above a bit with the % imbedded function operator - is what I am trying to do feasible?:

Take this 2-line statement:
Code:
x := COM_Invoke(ObjComport, "GetErrorDescription", COM_Invoke(ObjComport, "LastError"))
msgbox,,, Error = %x%, .5


And turn it into this 1-line statement:
Code:
msgbox,,, %  "Error =" . COM_Invoke(ObjComport, "GetErrorDescription", COM_Invoke(ObjComport, "LastError")) ,  .5


It seems to almost work. The last parameter that was to be passed to Msgbox (the timeout period) is getting absorbed as part of the text to display.

Is the solution a syntactical one, is a more obscure approach needed to make it a one-line statement, or is it simply not feasible with current AHK constructs?
Back to top
View user's profile Send private message
Lexikos



Joined: 17 Oct 2006
Posts: 2737
Location: Australia, Qld

PostPosted: Mon Mar 17, 2008 2:31 am    Post subject: Reply with quote

The commas in the expression trip up MsgBox's flexible parameter handling. Escaping them seems to work:
Code:
msgbox,,, % "Error =" . COM_Invoke(ObjComport`, "GetErrorDescription"`, COM_Invoke(ObjComport`, "LastError")),  .5

; Testing the syntax...
COM_Invoke(x,y,z=""){
    return "(" x "," y "," z ")"
}
Back to top
View user's profile Send private message
TodWulff



Joined: 29 Dec 2007
Posts: 99

PostPosted: Mon Mar 17, 2008 2:48 am    Post subject: Reply with quote

Wicked kewl! I learned quite a bit today, thanks to your personal assistance.

I DO appreciate it.!.

I don't know that having a single line of code, like I proposed (and you figured out), would bring anything to the table, besides mass confusion, but hell, knowing how to do it will surely lend itself to being useful someday, I am sure.

I am sure that there are several threads on which this could lead into - code readability, code size (compactness), thoroughput (optimization), etc. etc. etc., but that is for another day.

I guess that I do have one last question: Do you feel that sticking with COM is the way to go, or would you, if you were me, delve into the Embedded Scripting tool set that Eric has been toiling over -i.e. will there be ROI in the long run if I go that route, or is Chris likely to roll COM support directly into AHK in the near future?

(I qualify my question with the assertion that ultimately my focus herein is getting the serial comm stuff put to bed, and then focusing on completing the IDE functionality so that I can get back to coding up my UAV avionics suite in the AHK/NPP ARMbasic IDE...)


Please advise, when convenient. Have a good one, Lexikos.

-t
Back to top
View user's profile Send private message
Lexikos



Joined: 17 Oct 2006
Posts: 2737
Location: Australia, Qld

PostPosted: Mon Mar 17, 2008 4:24 am    Post subject: Reply with quote

You may find it easiest to embed existing (VBS or JS) scripts. I generally write code from scratch while referring to MSDN, so I use COM.ahk. (I haven't done much with third-party ActiveX controls.)
Quote:
...is Chris likely to roll COM support directly into AHK in the near future?
My educated guess would be no. It is actually one of my long-term goals. Smile
Back to top
View user's profile Send private message
TodWulff



Joined: 29 Dec 2007
Posts: 99

PostPosted: Mon Mar 17, 2008 5:12 am    Post subject: Reply with quote

Fully understood. Thank you for your insight. The COM model is pretty simple - cripes all one has to do is to create the object, and then invoke it with the appropriate functions/methods/etc. I don't know how much simpler it can be (10 hours ago, I would have laughed at the concept of it being simple to use)... Obviously, I am using it only for a sliver of what it is capable of being utilized for, however...

As info, ActiveComport is not a free dll. While I have a registered copy of it, licensing prevents me from distributing it (without paying a stupid amount of monies). I also suspect that when I get my tool completed, that others in the ARMbasic community will most likely want the IDE that I am creating.

I presume that the same type of functionality can be achieved using native MS objects.

Do you know what MSDN articles I can read to in order to determine what objects I need to make use of, in order to achieve similar functionality (full serial comm port connectivity)?

Please review and advise.

-t
Back to top
View user's profile Send private message
TodWulff



Joined: 29 Dec 2007
Posts: 99

PostPosted: Mon Mar 17, 2008 5:18 am    Post subject: Reply with quote

Lexikos wrote:
Quote:
...is Chris likely to roll COM support directly into AHK in the near future?
My educated guess would be no. It is actually one of my long-term goals. Smile

I, while knowing that you are one of the AHK gurus, didn't realize that you were part of the development team.

I am flattered that you'd take so much of your personal time to hold my hand through my trivial struggles.

'Tis much appreciated. Good luck on the migration of COM into AHK!!!

-t
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Goto page 1, 2, 3  Next
Page 1 of 3

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group