• Welcome to Powerbasic Museum 2020-B.
 

News:

Forum in repository mode. No new members allowed.

Main Menu

Modbus ocx

Started by Fabio Stranieri, December 14, 2008, 09:24:04 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Fabio Stranieri

In this moment i use PB9 and trial version FireFly. After 2 lesson of Fried's tutorial and some day around this forum, i want to do something.
Two years ago i have bought a ocx for modbus communication with plc that i use daily with VB6 program.(http://www.modbustools.com/modbus_activex.asp if someone want to test there is a trial version). Following some tutorial on this forum i have added this ocx on the form:





How i can view if this ocx is compatible with PB. (i have read on this forum that no all ocx is compatible with PB)

Why it get me error 526? I have read PB help: Period not allowed - Periods are not allowed within any identifier names.  They may only be used as a separator for member names.  A good alternative is to use an underscore (_) character to decorate variable names.

But i don't understand what it mean!!!

Regards

Fabio


Frederick J. Harris

Mbaxp1 is apparently an interface variable or type PowerBASIC isn't recognizing as such.  Has the control, that is, the ocx been instantiated/initialized within the FireFly code?  Generally, some sort of 'Set' statement is involved.  Hopefully, someone more familiar with FireFly/this ocx can provide you with more to go on. 

José Roca

#2
 
You can't use that VB-like syntax unless you generate an include file with the interface definitions using the COM Browser and adding it to the project. That is, if this control has a dual interface, that I don't know.

Otherwise, you have to use the Automation syntax (OBJECT CALL, LET, GET, SET), e.g.


DIM vVar AS VARIANT
vVar = 4 AS LONG
OBJECT LET DISPATCH_FORM1_MBAXP1.Connection = vVar
vVar = 10 AS LONG
OBJECT LET DISPATCH_FORM1_MBAXP1.BaudRate = vVar
...
...
...
DIM vRes AS VARIANT
OBJECT CALL DISPATCH_FORM1_MBAXP1.OpenConnection TO vRes


Quote
I have read on this forum that no all ocx is compatible with PB.

It is not a matter of compatibility with PB, but of compatibility with the OLE container used to host the OCX. FireFly uses ATL.DLL, Phoenix uses its own container and I use my own container. PB doesn't natively support OCXs yet because it doesn't incorporate an OLE container. So, there is not an uniform way of using them: It all depends of the tool that you are using.


Dominic Mitchell

This OCX is not dual  He has to use the automation syntax.
Dominic Mitchell
Phoenix Visual Designer
http://www.phnxthunder.com

Fabio Stranieri

What do you mean with "dual interface"?

Fabio Stranieri

maybe is: DUAL INTERFACE:  This is a combination of a Direct Interface and a Dispatch Interface.  This most flexible form allows either option to be used, depending upon how the calling application is implemented.

DIRECT INTERFACE:  This is the most efficient form of interface. When you call a particular METHOD or  PROPERTY, the compiler simply performs an indirect jump to the correct entry point listed in the virtual function table (VFT or VTBL).  This is just as fast as calling a standard Sub or Function, and is the default access method used by PowerBASIC.

DISPATCH INTERFACE:  This is a slow form of interface, originally introduced as a part of Microsoft Visual Basic.  When you use DISPATCH, the compiler actually passes the name of the METHOD you wish to execute as a text string.  The parameters can also be passed in the same way.  The object must then look up the names, and decide which METHOD to execute, and which parameters to use, based upon the text  provided.  This is a very slow process.  Many scripting languages still use DISPATCH as their sole method of operation, so continued support is necessary.


Therefoe, when is dual interface i can use Direct and Dispach. When it is NOT Dual interface i can you only Direct or only Dispach?

Dominic: how did you have seen that ocx is not dual interface?

Dominic Mitchell

#6
The easiest way to determine whether an OCX has dual interfaces is to use a type library
browser that shows the COM classes(coclass) and interfaces and their attributes.
Microsoft's OleView type library browser is the best at this.  The one that I use and which
I will make available when Phoenix 3.0 is released will also do this.  Your other option is
José's browser which displays and indented outline view of the interfaces by type.  The view
displays Interfaces, Dual interfaces, Dispatchable interfaces and Events interfaces nodes.
For example, if the Dual interface node is not present, the OCX has no dual interfaces.

When using an OCX, you should pay attention to the type flags of the coclasses and interfaces. 
For example,
 
' ****************************************************************************************
' coclass:        Mbaxp
' clsid:          {B39F2751-9393-4463-8058-29ECC28F08C1}
' Version ProgID: MBAXP.MbaxpCtrl.1
' Description:    MBAXP Modbus Master ActiveX Control
' Type Flags:     [cancreate, licensed, control]
' ----------------------------------------------------------------------------------------
' Interface:      _DMbaxp
' uuid:           {00CE2D84-06EC-4714-87C4-31CB8314B159}
' Description:    Dispatch interface for Mbaxp Control
' Type Flags:     [hidden, dispatchable]
' ****************************************************************************************

The can cancreate flag on the Mbaxp coclass indicates that a statement such as this

objvar = NEWCOM ProgID$

can be used to obtain a reference to the object.  If the cancreate flag is not present, then the
reference has to be obtained from another object. That is, CoCreateInstance cannot be used to
create the object.

The _DMbaxp interface does not have the dual flag, therefore, it is not dual. It however, has the
computed dispatchable flag. This means that it has no direct interfaces and so must be accessed
using syntax such as this

OBJECT GET oMbaxp.StopBits TO lStopBits


Dominic Mitchell
Phoenix Visual Designer
http://www.phnxthunder.com