Problem with ActiveX control

Rob100

New member
Joined
Jun 27, 2004
Messages
3
Hi there,

Im still new to C# and am playing with my first real app.

I am using Sapia-Incs SMTX ActiveX control, but all the examples are for VB6 and C++.

To docs say:

Visual Basic:
Function MbReadHoldingRegs(UnitID As Integer, StartReg As Integer, NumRegs As Integer, pRegs As Integer) As Integer

Visual C++:
short MbReadHoldingRegs(short UnitID, short StartReg, short NumRegs, short* pRegs);

My code is as follows:

private void butUpdate_Click(object sender, System.EventArgs e)
{ short status;
short [] MyData = new short [32];
status = axSMTX1.MbReadHoldingRegs(10,7168,32, ref MyData[0]);
ErrorCode.Text = Convert.ToString(status);
Uni2String myUni2 = new Uni2String();
for(int z = 0; z<32; z++)
{
myUni2.unicode[z] = (ushort)MyData[z];
}
UnicodeString.Text = (myUni2.Convert());
ErrorCode.Text = axSMTX1.LastErrorString();

}
}

class Uni2String
{
public string text;
public ushort [] unicode = new ushort [32];
public string Convert()
{
for(int x=0; x < unicode.Length; x++)
{
text = text + (char)(unicode[x]);
}
return text;
}
}

I had to insert "ref" into status = axSMTX1.MbReadHoldingRegs(10,7168,32, ref MyData[0]) to keep VS quiet, but despite hunting about on the net Im still lost...

Basically the idea is to read 32 Unicode chars from the modbus slave device, convert them to a string and display them on the form. Uni2String() works fine, I just cant get values help in the MyData array into myUni2.unicode[n].

Can someone help me? Ive been pulling my hair out for hours on this... :confused:

Thanks,

Rob.
 
Last edited by a moderator:
Back
Top