AnsweredAssumed Answered

vrf Modbus (again...)

Question asked by VRFuser on Apr 23, 2006
Hi all,

Update on Modbus:

I was checking some other software to use the modbus driver, and I found
this program http://datamaster2003.com/. I could use it with VBScript,
but was not able to access the registers, more or less the same problem
with VEE. The author of DM2003 send me the following reply: (in summary,
most probably mbserver will not be usable in VEE without modifying and
re-compiling)

----------------------------------------------------------------------
When you obtain data using following statement

MBServer.ReadOutputRegisters 1,0,3,Regs

Regs variable become an array of integers, while VBScript
supports only array of variants. Take a look at this code
(ModbusServerModbusSrv.cpp from modsrc01.zip):

STDMETHODIMP CModbusSrv::ReadInputRegisters(short Addr, long DataStart,
short Quantity, VARIANT * vRegValues, VARIANT vVarType, VARIANT
vRealType, long * plRetVal)
{
...
VARTYPE vtDest;
COleVariantEx vDataType(vVarType);
...
if (vDataType.IsMissing()){
   vtDest=VT_I4;
}
else {
   if ((vDataType.ToInt()>=VT_I2) && (vDataType.ToInt()<=VT_R8)){
     vtDest=vDataType.ToInt();
   }
   else {
     vtDest=VT_I4;
   }
}
...
switch (vtDest) {
case VT_I2:
...

As one can conclude, even vVarType=vbVariant has no result because
appropriate case is filtered (VT_I2=2, VT_R8=5, vt_variant=12).

However, things are not so bad in this case. DM2003 can successfully
process such arrays because when you invoke DM2003 methods, variant
array is converted in the Delphi code. So that, if you record data
to the DM2003 worksheet, you can immediately read the last item to
obtain current readout as shown below:

sub ReadMBServer
dim Regs, Cont
MBServer.ReadOutputRegisters 1,0,3,Regs
set Cont=Server.ActiveDocument.Container
Cont.AddItem Regs
Cont.Modified=true
Regs=Cont.Items(Cont.ItemCount-1)
' ^ now Regs is correct VBScript array!
Display.innerHTML=Regs(0)/3
if Running then SetTimeOut "ReadMBServer", 1000
end sub

Another workaround is just to create separate Visual Basic application
(exe or ocx) instead of HTML scriptlet. DM2003 may be launched and its
objects may be accessed from "true" VB as well; moreover, this is one of
most commonly used scenarios.

One could also consider parsing "raw" MODBUS data packages by script in
the same way as I usually do with SCPI commands used by laboratory
measurement instruments. DM2003 includes TCP client socket, and I plan
some experiments in this direction.

And my last suggestion at the moment: since we have source code of
MBServer, I could try to modify and recompile it so it will be
compatible with VBScript environment.
------------------------------------------------------

Nelson

---
You are currently subscribed to vrf as: rsb@soco.agilent.com
To subscribe please send an email to: "vrf-request@lists.it.agilent.com" with the word subscribe in the message body.
To unsubscribe send a blank email to "leave-vrf@it.lists.it.agilent.com".
To send messages to this mailing list,  email "vrf@agilent.com". 
If you need help with the mailing list send a message to
"owner-vrf@it.lists.it.agilent.com".
Search the "unofficial vrf archive" at "www.oswegosw.com/vrf_archive/".

Outcomes