Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
MSComm Control
#1
Code:
Copy      Help
typelib MsComm32 "C:\WINDOWS\system32\MSCOMM32.OCX"

MsComm32.MSComm c._create
c.CommPort=2
c.Settings = "9600,N,8,1"

c.PortOpen= 1

out c.PortOpen

I'm not real sure I'm doing this right. I need to send and receive serial data. c.PortOpen expects True or False. How do create a True in QM, also what do I need to create to handle the OnComm event? I could just poll for data. Thanks.
Matt
Matt B
#2
In COM and Visual Basic, Boolean type is two bytes, same as word in QM. True is 0xffff. To pass True from QM (by value), use 0xffff or TRUE or -1. To pass a boolean value by reference (when that argument is declared with &), at first declare a variable of type word.

I wanted to test this component, but did not find MSCOMM32.ocx on my computer.

When you type . after c, you should see events (lightning icons) in the list. When you double click an event, event handler function is created, and _setevents is inserted.

To receive events, that thread must stay running and able to process messages. Read more about events in the QM Help.
#3
Code:
Copy      Help
typelib MsComm32 "C:\WINDOWS\system32\MSCOMM32.OCX"
VARIANT T=TRUE
VARIANT F="asdfa"


MsComm32.MSComm c._create

c.Settings = "9600,N,8,1"
c.CommPort=1
out c.PortOpen
c.PortOpen = T
c.RThreshold=1
out c.PortOpen
c.Output=F
;c._setevents("c_DMSCommEvents")
;
;opt waitmsg 1
;wait -1

c.PortOpen = 0
This works. I can get an output to my HP48 calculator. But after playing with the control for awhile trying to get it to work QM starting crashing and acting strange. Now QM doesn't seem to recognize MsComm32 definition. You can see it is no longer grey and when I type "c." the popup menu doesn't appear. I think my code has left the MSCOMM32 loaded to many times. How do I unload it before exiting the macro?
Matt B
#4
You cannot unload type libraries. A type library is loaded when compiling the macro (when you start the macro, or only compile) first time in QM session, and unloaded when QM session ends. Here "QM session" is time while that QM macro list file is loaded.

To make the popup menu available, at first compile the macro (menu Tools -> Run -> Compile).

Maybe thread exits too soon. Try to add some delay, 1 or several seconds. Some ActiveX controls are not designed to run in multiple threads. When you run the macro multiple times, it actually runs in multiple different threads. To make the thread running all time, you for exampe can create a dialog that runs all time, and place the code in the dialog procedure, on button click for example.
#5
Quote:I am not familiar with serial port communications, and only can say that the code is correct. Maybe more properties must be set. Does it work in Visual Basic for example?

I still cannot test it. Error (RT) in Macro138: 0x80040112, Class is not licensed for use. Probably it must be installed together with Visual Studio, but I did not select ActiveX controls when installing.
I was afraid it wouldn't work without VB. I've used the control in the past with VB and it worked fine. I'll keep trying.
Quote:You cannot unload type libraries. A type library is loaded when compiling the macro (when you start the macro, or only compile) first time in QM session, and unloaded when QM session ends. Here "QM session" is time while that QM macro list file is loaded.
Does this mean I shouldn't be loading MSCOMM32 at the beginning of my code? Should it be in Init where it'll only get loaded once? It seems with all the QM examples, the libraries get loaded everytime the macro runs. Thanks again.
Matt
Matt B
#6
This worked, I was able to send chars to the PC from my calc on many occasions. It was very unstable though and crashed QM. The QM file was not backed up so I lost the events folder/function that was automatically created. But now double clicking on OnComm event in the popup menu declares the c_DMSCommEvents function/folder but doesn't declare "c" as a local control (commented out) as it did before. I forgot how.
Code:
Copy      Help
VARIANT a=TRUE

MsComm32.MSComm c._create

c.Settings = "9600,N,8,1"
c.CommPort=1
c.PortOpen = a
c.RThreshold=1
out c.PortOpen
c._setevents("c_DMSCommEvents")
opt waitmsg 1
wait -1
Matt B
#7
I'm an idiot. Some of the problems are fixed now that I'm starting the correct version of QM, 2.1.7 not 2.1.6 after a crash.
Matt B
#8
This works great as a function not so great as a macro.
Code:
Copy      Help
;;ListenToSerial
VARIANT a=TRUE
MsComm32.MSComm c._create

c.Settings = "9600,N,8,1"
c.CommPort=1
c.PortOpen = a
c.RThreshold=1
;out c.PortOpen
c._setevents("c_DMSCommEvents")
opt waitmsg 1
wait -1

And this allows me to control Rhapsody music using my HP48 calculator or any other serial source. Great potential.
Code:
Copy      Help
;/
;c_DMSCommEvents/c_OnComm

function MsComm32.IMSComm'c
str Cmd=c.Input
sel Cmd
,case "P"
,act "Rhapsody"
,5 "Rhapsody"
,key Cp
,
,case "S"
,act "Rhapsody"
,5 "Rhapsody"
,key Cs
,
,case "F"
,act "Rhapsody"
,5 "Rhapsody"
,key Cf
,
,case "B"
,act "Rhapsody"
,5 "Rhapsody"
,key Cb
Thanks for the help Gintaras! Any way you could make a serial port trigger?
Matt
Matt B


Forum Jump:


Users browsing this thread: 1 Guest(s)