¿ªÔÆÌåÓý

ctrl + shift + ? for shortcuts
© 2025 Groups.io

Beginner's Guide to OCX Implementation Request


 

Does anybody have a sample snippet of code for VB implementation of the OCX?

I'm new to OOP and quickly becomming beat up by it. I have the appropriate
OCX loaded (and can see all the Subs and Functions in the Object Browser)
but am unable to place a successful call for something as simple as
determining the units.

I'm 100% sure it's on my end since I continue to receive Error 424 - Object
Required - I'm not calling the functions properly.

I'm 0-3 on researching the subject in VB books - none talk specifically
about this issue.

I'll take a simple 1 line example if anyone could offer it. I'll be able to
extrapolate from there.

Thanks in advance,

James


 

Hello James,

1) Place the OCX on a form, then try to find the OCX on the form, it
has no border or other visible feature
2) Name the OCX Motion (F4 to get to the Property page)
3) Now you can "talk" to the OCX with standard dot notation

Here is my Initialize Routine

Sub Initialize()
Dim status As Boolean
' initialize
Motion.InitEngine
'start
If Motion.StartEngine Then
MsgBox(" Engine started OK")
Else
MsgBox(" Engine failed to startOK")
End If
'reset
Motion.Reset
status = Motion.IsReset
'reset again ?
Motion.Reset
status = Motion.IsReset
' Don't know why I need a second call. (first false then true)

End Sub


Have fun, at the moment I am frustrated because I can do virtually
anything with the OCX but I can not convince it to generate pulses.


Best regards
and good luck
Peter



--- In mach1mach2cnc@..., "James Stevens"
<jstevens@c...> wrote:
Does anybody have a sample snippet of code for VB implementation
of the OCX?

I'm new to OOP and quickly becomming beat up by it. I have the
appropriate
OCX loaded (and can see all the Subs and Functions in the Object
Browser)
but am unable to place a successful call for something as simple as
determining the units.

I'm 100% sure it's on my end since I continue to receive Error
424 - Object
Required - I'm not calling the functions properly.

I'm 0-3 on researching the subject in VB books - none talk
specifically
about this issue.

I'll take a simple 1 line example if anyone could offer it. I'll
be able to
extrapolate from there.

Thanks in advance,

James


 

Peter,

Thanks for the post - I think my first mistake was trying to use Master5
OCX.

I downloaded the demo for Mach 2 Rev 4.0 lockdown to try it out. I created
a new form in VB5 and followed your procedure below. I copied the text into
VB5 - when I try to run it, VB5 crashes. I've tried it with Mach2 running
and not running and have been getting mixed results.

When I am able to have it run without crashing, I get no message boxes which
tells me something is wrong.

I am able to run the OCX driver test successfully and get around 24K pulses.

I haven't yet registered Mach2 as I just downloaded it and wanted to make
sure I could do what I wanted before I send Art his well deserved money.
Could this be the problem?

Basically what I want to do is be able to write my own VB code and utilize
Art's routines to control the motor and "see" the position through the DRO.
I don't think it's out of the question, I just can't get the right format
down for getting started.

Can I do this with an independent VB5 program or do I need to do it with
scripting inside Mach2? That will help me make some decisions.

What I'd like to do is create a little doc that shows any other idiots like
myself who are interested in getting started exactly how to do it. I want
kid's instructions - not expert's jargon (like all of the VB books out
there - "first, create an instance of the class so you can initialize the
object as private") to be available to everyone who wants to get into this.
I'm willing to take a stab at the docs (which would greatly pale in
comparison to John Prentice's work) but if I can't get started, I certainly
can't tell others how to do it.

Any help is appreciated.

Thanks,

James

----- Original Message -----
From: "Peter" <elasebay@...>

1) Place the OCX on a form, then try to find the OCX on the form, it
has no border or other visible feature
2) Name the OCX Motion (F4 to get to the Property page)
3) Now you can "talk" to the OCX with standard dot notation

Here is my Initialize Routine

Sub Initialize()
Dim status As Boolean
' initialize
Motion.InitEngine
'start
If Motion.StartEngine Then
MsgBox(" Engine started OK")
Else
MsgBox(" Engine failed to startOK")
End If
'reset
Motion.Reset
status = Motion.IsReset
'reset again ?
Motion.Reset
status = Motion.IsReset
' Don't know why I need a second call. (first false then true)

End Sub


 

Peter,

I was able to get the Master5 ocx to work by naming the OCX instead of:

Private Motion As Master5Remote

So much for reading books!

Thanks for the help! I'll work with the Master5 OCX for now.

James

Thanks for the post - I think my first mistake was trying to use Master5
OCX.


Art
 

James:

You cannot run Mach2 at the same time as your VB application. When you
use an OCX, you must have exclusive use of it.
Send me an offline message so I can send you a small VB application which
uses the OCX, I don't have the source, but it shows the VB interface works.
Unfortunatley, I don't use VB at all, only C++, but the ocx shouldn't crash
on you in any event, I suspect it may be the SetWindowHandle() routine must
be called to set the right interface to your form...

Art
www.artofcnc.ca


Art
 

Peter:

If you write an VB application with a button on it that calls StraightFeed
( 10,10,10,0,0,0) in it does it move? If not, send me the application, I can
debug such a thing quite easily and see what the holdup is. Send the
directorty you use zipped up so the VB application, the .xml file your using
are both in a directory. I'll let you know why theres no movement...

Thanks,
Art
www.artofcnc.ca


Les Newell
 

Hi Art,

There is still something wrong. If I compile the program then run the exe it mostly works. If I try and run the program from within the VB IDE then VB bombs with a protection fault.

There are also some major redrawing problems when using the OCX from VB. Labels don't get redrawn correctly if the main window is resized or another window is dragged over it. Also when you switch from one page to another the controls on the new page don't always get drawn and the controls from the previous pages don't get erased. Forcing a refresh by moving another window over the application sorts it out apart from the labels.

With Borland C++ builder the IDE doesn't crash but I get the same redraw problems. I also had to use SetWindowHandle to stop everythig getting drawn on the desktop. Also for some reason I get an access violation when I try to call SetProfileName()

Les


Mark Tucker
 

--- In mach1mach2cnc@..., Les Newell <les@l...> wrote:
Hi Art,

There is still something wrong. If I compile the program then run
the
exe it mostly works. If I try and run the program from within the
VB IDE
then VB bombs with a protection fault.

There are also some major redrawing problems when using the OCX
from VB.
Labels don't get redrawn correctly if the main window is resized
or
another window is dragged over it. Also when you switch from one
page to
another the controls on the new page don't always get drawn and
the
controls from the previous pages don't get erased. Forcing a
refresh by
moving another window over the application sorts it out apart from
the
labels.

With Borland C++ builder the IDE doesn't crash but I get the same
redraw
problems. I also had to use SetWindowHandle to stop everythig
getting
drawn on the desktop. Also for some reason I get an access
violation
when I try to call SetProfileName()

Les
Les/Art

I thought it was my poor vb understanding but i am getting all the
faults above of which the first one (vb crashing when in ide is a
pain).
I have been writing progs and having to compile to exe to check them
which does not make debugging very easy.I also can not get the about
box to display the license,it displays "demo mode" even though
everything is in the same directory (license.dat,Project,ocx).

At least i know i am not going mad.

Regards
Mark


 

Hi, Mark

Do you feel like sharing VB code?
This OCX is driving me nuts.
here is what I suggest:
We agree on a name for the OXC (say ArtsMotion, or simply M like in
motion to save typing)
We agree on some common routines that one needs
We prototype the functions and Subs and then distribute them for
general testing and feed back.
We can also distribute the exe files for people that are willing to
test our code, without getting into the VB details

If you see any value in this please respond to peterd@...

best regards
peter

PS:
?? Have you used M.StraightFeed ?
I can not figure out why VB doesn't accept the syntax, according to
the object browser this is a sub but it seems to be a function






--- In mach1mach2cnc@..., "Mark Tucker" <rmtucker@l...>
wrote:
--- In mach1mach2cnc@..., Les Newell <les@l...> wrote:
Hi Art,

There is still something wrong. If I compile the program then run
the
exe it mostly works. If I try and run the program from within the
VB IDE
then VB bombs with a protection fault.

There are also some major redrawing problems when using the OCX
from VB.
Labels don't get redrawn correctly if the main window is resized
or
another window is dragged over it. Also when you switch from one
page to
another the controls on the new page don't always get drawn and
the
controls from the previous pages don't get erased. Forcing a
refresh by
moving another window over the application sorts it out apart
from
the
labels.

With Borland C++ builder the IDE doesn't crash but I get the same
redraw
problems. I also had to use SetWindowHandle to stop everythig
getting
drawn on the desktop. Also for some reason I get an access
violation
when I try to call SetProfileName()

Les
Les/Art

I thought it was my poor vb understanding but i am getting all the
faults above of which the first one (vb crashing when in ide is a
pain).
I have been writing progs and having to compile to exe to check
them
which does not make debugging very easy.I also can not get the
about
box to display the license,it displays "demo mode" even though
everything is in the same directory (license.dat,Project,ocx).

At least i know i am not going mad.

Regards
Mark


Art
 

Hi Mark, Les..et all.

There seems to be a growing interest in useing the OCX for application
development. Unfortunately I never use VB and don't know how on a good day.
I can tell you a few things..

1) You application will read demo unitl the engine is fully started. It is
the process of starting the engine that verifies your license.

2) Errors like crashing are probably due to all the graphics involved.
Perhaps no screens should be loaded. It should be possible to InitEngine,
StartEngine, Reset, and then StraightFeed(x,x,x,x,x,x). If someone writes
such a beast and it won't feed, I will debug and let you know why it won't
run as it is. I would love to see a guide to VB'ing the ocx and will assist
all I can.

If you guys get an application that is crashing or doing something
improper, send me a non-debug version and I can use it to debug with and let
you know the trouble. I suspect that, unlike C++, VB may have trouble with
the graphics, but it should still be able to move the motors and such via
OCX control. While I did design everything as an OCX for that very reason,
till now, no-one has wanted to use it in this way. I will, of course, help
as much as I can along the way..

Thanks,
Art
www.artofcnc.ca


Les Newell
 

Hi Art,
The main two problems that I know of with VB are:

1) VB crashes as soon as you try running your app. This is before any calls are made to the OCX. If the same app is compiled then run as an exe then it runs OK but of course you can't debug it. As you don't have a copy of VB it could be a problem for you to find this one.

2) Graphic redraw problems. The VB demo I sent you a while back should show this. Try resizing the window or changing pages.

Sorry about the CBuilder test program I sent you last night. I thought the exe seemed very small. I will try to see why it did not compile with static libraries.

Les

Art wrote:

Hi Mark, Les..et all.
There seems to be a growing interest in useing the OCX for application
development. Unfortunately I never use VB and don't know how on a good day.
I can tell you a few things..
1) You application will read demo unitl the engine is fully started. It is
the process of starting the engine that verifies your license.
2) Errors like crashing are probably due to all the graphics involved.
Perhaps no screens should be loaded. It should be possible to InitEngine,
StartEngine, Reset, and then StraightFeed(x,x,x,x,x,x). If someone writes
such a beast and it won't feed, I will debug and let you know why it won't
run as it is. I would love to see a guide to VB'ing the ocx and will assist
all I can.
If you guys get an application that is crashing or doing something
improper, send me a non-debug version and I can use it to debug with and let
you know the trouble. I suspect that, unlike C++, VB may have trouble with
the graphics, but it should still be able to move the motors and such via
OCX control. While I did design everything as an OCX for that very reason,
till now, no-one has wanted to use it in this way. I will, of course, help
as much as I can along the way..
Thanks,
Art
www.artofcnc.ca
Yahoo! Groups Links


 

Mark
You have probably done this, but is you licenses file in the Mach2
folder?
Jim

----- Original Message -----
From: "Mark Tucker" <rmtucker@...>
To: <mach1mach2cnc@...>
Sent: Friday, March 05, 2004 12:43 AM
Subject: [mach1mach2cnc] Re: Beginner's Guide to OCX Implementation Request


--- In mach1mach2cnc@..., Les Newell <les@l...> wrote:
Hi Art,

There is still something wrong. If I compile the program then run
the
exe it mostly works. If I try and run the program from within the
VB IDE
then VB bombs with a protection fault.

There are also some major redrawing problems when using the OCX
from VB.
Labels don't get redrawn correctly if the main window is resized
or
another window is dragged over it. Also when you switch from one
page to
another the controls on the new page don't always get drawn and
the
controls from the previous pages don't get erased. Forcing a
refresh by
moving another window over the application sorts it out apart from
the
labels.

With Borland C++ builder the IDE doesn't crash but I get the same
redraw
problems. I also had to use SetWindowHandle to stop everythig
getting
drawn on the desktop. Also for some reason I get an access
violation
when I try to call SetProfileName()

Les
Les/Art

I thought it was my poor vb understanding but i am getting all the
faults above of which the first one (vb crashing when in ide is a
pain).
I have been writing progs and having to compile to exe to check them
which does not make debugging very easy.I also can not get the about
box to display the license,it displays "demo mode" even though
everything is in the same directory (license.dat,Project,ocx).

At least i know i am not going mad.

Regards
Mark






Yahoo! Groups Links




Art
 

Les:

I did notice the failure of the graphics to switch properly. I can't think
why, you'd think a C program using the OCX would behave much like a VB
program.. One of those microsoft things I guess. Only troubleshooting will
tell.

Art
www.artofcnc.ca


Art
 

Les:

Your test program is crashing when trying to set the profile. This is
beacuse the way VB handles strings is different than VC's strings. Your
sending a BStr while that call expects a Ansi String. I can add a BString
handler, but for now, skip the call. It is used only to set the name of the
profile on the screen. The text file in your driectory called "profile.txt"
actually contains the xml file to load. This was due to a chicken and egg
problem. I needed the profile name to get the prefered profile name from the
xml to load the profile I needed the name from in the first place.

The graphics issues we'll have to deal with when I return. It seems that
a HideWindow() will not hide a VB window all the time. I'm sure there's
somethign we can design to fix that up...

Thanks for the test file. It actually crashes in a system dll that runs a
ConvertAnsiToBstr routine on the text, which is already a bstring..?? Christ
knows why, the routine expects an ansi anyway...Its like VB says, this is a
C OCX so I'll convert this to ansi...
.

Thanks,.
Art
www.artofcnc.ca


 

Hello Art,

Have a nice vacation.

I have the OCX working from Vb (occasionally), there are still a lot
of questions.
I'll test and struggle some more and in 5 to 6 days I will send you
all the code for debugging.

The most "luck" I had with ExecuteGCode.
I also had StraightFeed work

Seems that we will get to the bottom of it soon.

Absorbe some sun for me too !
Best regards
Peter


--- In mach1mach2cnc@..., Art <fenerty@a...> wrote:
Hi Mark, Les..et all.

There seems to be a growing interest in useing the OCX for
application
development. Unfortunately I never use VB and don't know how on a
good day.
I can tell you a few things..

1) You application will read demo unitl the engine is fully
started. It is
the process of starting the engine that verifies your license.

2) Errors like crashing are probably due to all the graphics
involved.
Perhaps no screens should be loaded. It should be possible to
InitEngine,
StartEngine, Reset, and then StraightFeed(x,x,x,x,x,x). If
someone writes
such a beast and it won't feed, I will debug and let you know why
it won't
run as it is. I would love to see a guide to VB'ing the ocx and
will assist
all I can.

If you guys get an application that is crashing or doing
something
improper, send me a non-debug version and I can use it to debug
with and let
you know the trouble. I suspect that, unlike C++, VB may have
trouble with
the graphics, but it should still be able to move the motors and
such via
OCX control. While I did design everything as an OCX for that very
reason,
till now, no-one has wanted to use it in this way. I will, of
course, help
as much as I can along the way..

Thanks,
Art
www.artofcnc.ca


Art
 

Just checking in for last minute mail, glad to hear things are starting to
shape up Peter, Good luck with it..
I've spent the day troubleshooting the dreaded memory leak, FINALLY I have
found the source of the problem.
Hopefully I can solve it before I leave, it will make quite a difference to
the low memory users. Its like pulling teeth
tracing this one down but I'm actually to the routine causing the memory
gobs being wasted...

Thanks,
Art
www.artofcnc.ca

----- Original Message -----