0% found this document useful (0 votes)
542 views

ShortBus Quick Start PDF

The document describes ShortBus, a .NET DLL that provides Modbus RTU and TCP/IP master and Modbus RTU slave functionality. It includes functions for reading and writing bits, words, and other data types as a master or slave. As a master, it supports functions for serial and TCP/IP communication. As a slave, it monitors serial communication and provides registers for reading and writing data. The document provides examples of initializing a new master or slave instance and descriptions of key functions.

Uploaded by

macam6
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
542 views

ShortBus Quick Start PDF

The document describes ShortBus, a .NET DLL that provides Modbus RTU and TCP/IP master and Modbus RTU slave functionality. It includes functions for reading and writing bits, words, and other data types as a master or slave. As a master, it supports functions for serial and TCP/IP communication. As a slave, it monitors serial communication and provides registers for reading and writing data. The document provides examples of initializing a new master or slave instance and descriptions of key functions.

Uploaded by

macam6
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

ShortBusQuickStart

ShortBusisadllthatprovidesmasterfunctionality(ModbusRTUandTCP/IP)andslavefunctionality(ModbusRTU)
toanyVisualStudio.NETapplication.

MasterInstanceFunctions
SetCOMPortsetsserialcommunicationportsettings
ErrorStringconvertsintegererrorcodeintoastring
ReadBitsreadbitsusingfunctioncodes0or1
WriteBitSinglewritesinglebitusingfunctioncode5
WriteBitMultiplewritebitsusingfunctioncode15
ReadWordsreadwordsusingfunctioncodes3or4
WriteWordSinglewritesinglewordusingfunctioncode6
WriteWordMultiplewritewordsusingfunctioncode16

MasterInstanceVariables
TCPModeboolean,enablesModbusTCP/IPcommunication
TCPAddressstring,setstheModbusTCP/IPIPaddressorURL
TCPPortunsignedshortinteger,setstheModbusTCP/IPport(default502)
COMserialportusedforthisinstance

SlaveInstanceFunctions
SetPortsetscommunicationportsettings
Openopenstheserialport,monitorsincomingcommunication
Closeclosestheserialport

SlaveInstanceVariables
COMserialportusedforthisinstance
Addressunsignedshortinteger,nodeaddressusedforthisinstancedefault=1
Enableboolean,iftrueenablesslaveinterface,iffalseexceptioncodereturneddefault=true
Data3xunsignedshortintegerarrayfor3xregisters,lengthof65535default=all0
Data4xunsignedshortintegerarrayfor4xregisters,lengthof65535default=all0
ReadOnly4xbooleanarrayforwritepermissionsof4xregisterindices,lengthof65535default=allfalse
Linked3xboolean,iftrue3xdataarrayislinkedto4xdataarraydefault=true
Enable3xboolean,iftrue3xregistersexistandmaybereaddefault=true
Enable4xboolean,iftrue4xregistersexistandmayberead,seeReadOnly4xforwritepermissiondefault=true
EnableFC6boolean,iftrueFC6maybeusedtowrite4xregistersdefault=true
EnableFC16boolean,iftrueFC16maybeusedtowrite4xregistersdefault=true
MsgGoodunsignedlonginteger,totalnumberofmessagesreceivedwithouterror
MsgBadCRCunsignedlonginteger,totalnumberofmessagesreceivedwithbadchecksum
MsgExcunsignedlonginteger,totalnumberofmessagesreceivedwithexceptionresponses
MsgTotalunsignedlonginteger,totalnumberofmessagesreceived

StaticConversionFunctions(UsableForMasterorSlave)
ReadRealconvertsanunsignedshortarrayintoafloat/singlearray
WriteRealconvertsafloat/singlearrayintoanunsignedshortarray
ReadDIntconvertsanunsignedshortarrayintoanintegerarray(16bitto32bit)
WriteDIntconvertsanintegerarrayintoanunsignedshortarray(32bitto16bit)
BitPackconvertsa16countbooleanarrayintoanunsignedshort
BitUnpackconvertsanunsignedshortintoa16countbooleanarray
IntToBoolconvertsanunsignedshortarrayintoabooleanarray
BoolToIntconvertsabooleanarrayintoanunsignedshortarray

SettingUpNewMasterInstance
Examples
VisualC#

ShortBus.MastersbMst=newShortBus.Master();

VisualBasic

DimsbMstAsNewShortBus.Master()

SettingUpNewMasterInstanceUsingTCP/IP
Examples
VisualC#

ShortBus.MastersbMst=newShortBus.Master();
sbMst.TCPMode=true;
sbMst.TCPAddress="localhost";
sbMst.TCPPort=502;

VisualBasic

DimsbMstAsNewShortBus.Master()
sbMst.TCPMode=True
sbMst.TCPAddress="localhost"
sbMst.TCPPort=502

SettingUpNewSlaveInstance
Examples
VisualC#

ShortBus.SlavesbSlave=newShortBus.Slave();

VisualBasic

DimsbSlaveAsNewShortBus.Slave()

MasterInstanceFunctionDescriptions
SetCOMPort
VisualC#(ushortport,ushortbaud,ushortdata,charparity,doublestop)
VisualBasic(portAsUShort,baudAsUShort,dataAsUShort,parityAsChar,stopAsDouble)
Description
FunctionusedtodefinetheCOMvariablefortheinstance
Parameters
portcommunicationport,normally132
baudbaudrate,normally9600or19200
datadatabits,normally8
parityparity,mustbe'O','E'or'N'(VisualC#)or"O","E"or"N"(VisualBasic)
stopstopbits,mustbe0,1,1.5or2
Examples
VisualC#
sbMst.SetCOMPort(3,19200,8,'N',1);

VisualBasic
sbMst.SetCOMPort(3,19200,8,"N",1)

ErrorString
VisualC#(ushortcode),VisualBasic(codeAsUShort)
Description
Convertstheunsignedshorterrorcodeintoastring.
0=NoError
1=NoResponseorConnectionError
2=ExceptionErrorGeneric
5=StartAddress0Invalid(Offset+1Required)
6=NodeAddressMustBeLessThan248
7=NodeAddressCannotBeLessThan1
11=ExceptionErrorIllegalFunction
12=ExceptionErrorIllegalDataAddress
13=ExceptionErrorIllegalDataValue
14=ExceptionErrorSlaveDeviceFailure
15=ExceptionErrorSlaveAcknowledge
16=ExceptionErrorSlaveDeviceBusy
17=ExceptionErrorNegativeAcknowledge
18=ExceptionErrorMemoryParityError
99=BroadcastMessage

Parameters
codeunsignedshortreturnedfromreadorwritefunction
Examples
VisualC#
Variables.status=sbMst.ReadWords(1,1,10,outVariables.words,delay:250);
Result.Text=sbMst.ErrorString(Variables.status);

VisualBasic
err=sbMst.ReadWords(1,1,10,results,delay:=250,type3x:=True)
Result.Text=sbMst.ErrorString(err)

ReadBits
VisualC#(ushortnode,ushortstart,ushortlength,outbool[]bits,[ushortdelay=100],[booltype1x=false]

,[boolorderswap=false])
VisualBasic(nodeAsUShort,startAsUShort,lengthAsUShort,ByRefbits()AsBoolean,[delayAsUShort=100]

,[type1xAsBoolean=False,[orderswapAsBoolean=False])
Description
Readsbitsusingfunctioncodes0(0xregisters)or1(1xregisters).
Return
Thefunctionreturnsanerrorcodeasanunsignedshortbutitmaybeinvokedwithoutreading.Ifthe
errorcodeis0,thatcanbeusedtodeterminethevalidityofthedata.
Parameters
nodedevicetoreaddatafrom(ifnotacknowledgedwithModbusTCP/IPsetas1)
startaddressinnodetobeginreadingfrom,mustbe1orgreater(1=00001or1=10001)
lengthhowmanybitstoread
bitsoutputparameter,booleanarraytostoreresultsinto
delay(optional)specifiesthemsintervalbetweencharacters,100msifnotspecified
type1x(optional)specifiesthatfunctioncode1istobeusedinsteadof0,falseifnotspecified
orderswap(optional)specifiesthatthebitorderistobeswapped,falseifnotspecified
Examples
VisualC#

ushorterr;
bool[]read=newbool[10];
bool[]data=newbool[10];
err=sbMst.ReadBits(1,1,10,outread,delay:250,type1x:false,orderswap:false);
if(err==0)for(inti=0;i<=9;i++)data[i]=read[i];
elsefor(inti=0;i<=9;i++)data[i]=false;

VisualBasic

DimerrAsUShort
Dimread(10)AsBoolean
Dimdata(10)AsBoolean
err=sbMst.ReadBits(1,1,10,read,delay:=250,type1x:=False,orderswap:=False)
Iferr=0Then
Fori=0To9
data(i)=read(i)
Nexti
Else
Fori=0To9
data(i)=False
Nexti
EndIf

WriteBitSingle
VisualC#(ushortnode,ushortstart,booldata,[ushortdelay=100])
VisualBasic(nodeAsUShort,startAsUShort,dataAsBoolean,[delayAsUShort=100])

Description
Writesabitusingfunctioncode5(0xregisters).
Return
Thefunctionreturnsanerrorcodeasanunsignedshortbutitmaybeinvokedwithoutreading.Ifthe
errorcodeis0,thatcanbeusedtodeterminethesuccessofthewrite.
Parameters
nodedevicetoreaddatafrom,node0maybeusedforbroadcasts(ifnotacknowledgedwithModbus
TCP/IPsetas1)
startaddressinnodetobeginreadingfrom,mustbe1orgreater(1=00001)
databooleanvaluetobewritten
delay(optional)specifiesthemsintervalbetweencharacters,100msifnotspecified
Examples
VisualC#
booldata=true;
sbMst.WriteBitSingle(1,1,data,delay:250);

VisualBasic

DimdataAsBoolean
data=True
sbMst.WriteBitSingle(1,1,data,delay:=250)

WriteBitMultiple
VisualC#(ushortnode,ushortstart,ushortlength,bool[]data,[ushortdelay=100],[boolorderswap=false])
VisualBasic(nodeAsUShort,startAsUShort,lengthAsUShort,data()AsBoolean,[delayAsUShort=100]

,[orderswapAsBoolean=False])
Description
Writesbitsusingfunctioncode15(0xregisters).Alengthofoneorgreatermustbespecified.
Return
Thefunctionreturnsanerrorcodeasanunsignedshortbutitmaybeinvokedwithoutreading.Ifthe
errorcodeis0,thatcanbeusedtodeterminethesuccessofthewrite.
Parameters
nodedevicetoreaddatafrom,node0maybeusedforbroadcasts(ifnotacknowledgedwithModbus
TCP/IPsetas1)
startaddressinnodetobeginreadingfrom,mustbe1orgreater(1=00001)
lengthhowmanybitstowrite
databooleanvaluestobewritten
delay(optional)specifiesthemsintervalbetweencharacters,100msifnotspecified
orderswap(optional)specifiesthatthebitorderistobeswapped,falseifnotspecified
Examples
VisualC#

bool[]data=newbool[3]{true,false,true};
sbMst.WriteBitMultiple(1,1,3,data,delay:250);

VisualBasic
Dimdata(3)AsBoolean
data={True,False,True}

sbMst.WriteBitMultiple(1,1,3,data,delay:=250)

ReadWords
VisualC#(ushortnode,ushortstart,ushortlength,outushort[]words,[ushortdelay=100]

,[booltype3x=false],[boolbyteswap=false])
VisualBasic(nodeAsUShort,startAsUShort,lengthAsUShort,ByRefwords()AsUShort,[delayAsUShort=100]

,[type3xAsBoolean=False],[byteswapAsBoolean=False])
Description
Readswordsusingfunctioncodes3(4xregisters)or4(3xregisters).
Return
Thefunctionreturnsanerrorcodeasanunsignedshortbutitmaybeinvokedwithoutreading.Ifthe
errorcodeis0,thatcanbeusedtodeterminethevalidityofthedata.
Parameters
nodedevicetoreaddatafrom(ifnotacknowledgedwithModbusTCP/IPsetas1)
startaddressinnodetobeginreadingfrom,mustbe1orgreater(1=30001or1=40001)
lengthhowmanywordstoread
wordsoutputparameter,unsignedshortarraytostoreresultsinto
delay(optional)specifiesthemsintervalbetweencharacters,100msifnotspecified
type3x(optional)specifiesthatfunctioncode4istobeusedinsteadof3,falseifnotspecified
byteswap(optional)specifiesthatthebyteorderistobeswapped,falseifnotspecified
Examples
VisualC#

ushorterr;
ushort[]read=newushort[10];
ushort[]data=newushort[10];
err=sbMst.ReadWords(1,1,10,outread,delay:250,type3x:false,byteswap:false);
if(err==0)for(inti=0;i<=9;i++)data[i]=read[i];
elsefor(inti=0;i<=9;i++)data[i]=0;

VisualBasic

DimerrAsUShort
Dimread(10)AsUShort
Dimdata(10)AsUShort
err=sbMst.ReadWords(1,1,10,read,delay:=250,type3x:=False,byteswap:=False)
Iferr=0Then
Fori=0To9
data(i)=read(i)
Nexti
Else
Fori=0To9
data(i)=0
Nexti
EndIf

WriteWordSingle
VisualC#(ushortnode,ushortstart,ushortdata,[ushortdelay=100],[boolbyteswap=false])
VisualBasic(nodeAsUShort,startAsUShort,dataAsUShort,[delayAsUShort=100]

,[byteswapAsBoolean=False])

Description
Writesawordusingfunctioncode6(4xregisters).
Return
Thefunctionreturnsanerrorcodeasanunsignedshortbutitmaybeinvokedwithoutreading.Ifthe
errorcodeis0,thatcanbeusedtodeterminethesuccessofthewrite.
Parameters
nodedevicetoreaddatafrom,node0maybeusedforbroadcasts(ifnotacknowledgedwithModbus
TCP/IPsetas1)
startaddressinnodetobeginreadingfrom,mustbe1orgreater(1=40001)
dataunsignedshortvaluetobewritten
delay(optional)specifiesthemsintervalbetweencharacters,100msifnotspecified
byteswap(optional)specifiesthatthebyteorderistobeswapped,falseifnotspecified
Examples
VisualC#
ushortdata=99;
sbMst.WriteWordSingle(1,1,data,delay:250);

VisualBasic

DimdataAsUShort
data=99
sbMst.WriteWordSingle(1,1,data,delay:=250)

WriteWordMultiple
VisualC#(ushortnode,ushortstart,ushortlength,outushort[]data,[ushortdelay=100]

,[boolbyteswap=false])
VisualBasic(nodeAsUShort,startAsUShort,lengthAsUShort,ByRefdata()AsUShort,[delayAsUShort=100]

,[byteswapAsBoolean=False])
Description
Writeswordsusingfunctioncode16(4xregisters).Alengthofoneorgreatermustbespecified.
Return
Thefunctionreturnsanerrorcodeasanunsignedshortbutitmaybeinvokedwithoutreading.Ifthe
errorcodeis0,thatcanbeusedtodeterminethesuccessofthewrite.
Parameters
nodedevicetoreaddatafrom,node0maybeusedforbroadcasts(ifnotacknowledgedwithModbus
TCP/IPsetas1)
startaddressinnodetobeginreadingfrom,mustbe1orgreater(1=00001)
lengthhowmanybitstowrite
dataunsignedshortvaluestobewritten
delay(optional)specifiesthemsintervalbetweencharacters,100msifnotspecified
byteswap(optional)specifiesthatthebyteorderistobeswapped,falseifnotspecified
Examples
VisualC#

ushort[]data=newushort[3]{1,2,3};
sbMst.WriteWordMultiple(1,1,3,data,delay:250);

VisualBasic
Dimdata(3)AsUShort
data={1,2,3}

sbMst.WriteWordMultiple(1,1,3,data,delay:=250)

SlaveInstanceFunctionDescriptions
SetPort
VisualC#(ushortport,ushortbaud,ushortdata,charparity,doublestop)
VisualBasic(portAsUShort,baudAsUShort,dataAsUShort,parityAsChar,stopAsDouble)
Description
FunctionusedtodefinetheCOMvariablefortheinstance
Parameters
portcommunicationport,normally132
baudbaudrate,normally9600or19200
datadatabits,normally8
parityparity,mustbe'O','E'or'N'(VisualC#)or"O","E"or"N"(VisualBasic)
stopstopbits,mustbe0,1,1.5or2
Examples
VisualC#
sbSlave.SetPort(3,19200,8,'N',1);

VisualBasic
sbSlave.SetPort(3,19200,8,"N",1)

Open
VisualC#(noparameters)
VisualBasic(noparameters)
Description
Functionusedtoopentheserialportandmonitorincomingcommunication
Examples
VisualC#
sbSlave.Open();

VisualBasic
sbSlave.Open()

Close
VisualC#(noparameters)
VisualBasic(noparameters)
Description
Functionusedtoclosetheserialport
Examples
VisualC#
sbSlave.Close();

VisualBasic
sbSlave.Close()

StaticConversionFunctionDescriptions
ReadReal
VisualC#(ushortlength,ushortoffset,ushort[]data,[boolbyteswap=false],[boolwordswap=false])
VisualBasic(lengthAsUShort,offsetAsUShort,ByRefdata()AsUShort,[byteswapAsBoolean=False]

,[wordswapAsBoolean=False])
Description
Convertsanunsignedshortarrayintoafloat/singlearray.Each32bitfloat/singlevalueistheresultof
mergingtwoconsecutive16bitunsignedshortvalues.
Return
Thefunctionreturnsafloat/singlearrayofthelengthspecified.
Parameters

lengthhowmanyfloats/singlestoconvert,shouldbehalfofthelengthofthedataarray

offsetwhicharraypositiontobeginconvertingfrom

dataunsignedshortarraytoconverttoafloat/singlearray
byteswap(optional)specifiesthatthebyteorderistobeswapped,falseifnotspecified
wordswap(optional)specifiesthatthewordorderistobeswapped,falseifnotspecified
Examples
VisualC#
ushort[]data=newushort[2];
sbMst.ReadWords(1,1,2,outdata,delay:250);
float[]rdata=sbMst.ReadReal(1,0,data);

VisualBasic
Dimdata(2)AsUShort

sbMst.ReadWords(1,1,2,data,delay:=250)

Dimrdata()AsSingle
rdata=sbMst.ReadReal(1,0,data)

WriteReal
VisualC#(ushortlength,ushortoffset,float[]data,[boolbyteswap=false],[boolwordswap=false])
VisualBasic(lengthAsUShort,offsetAsUShort,ByRefdata()AsSingle,[byteswapAsBoolean=False]

,[wordswapAsBoolean=False])
Description
Convertsafloat/singlearrayintoanunsignedshortarray.Each32bitfloat/singlevalueissplitintotwo
consecutive16bitunsignedshortvalues.
Return
Thefunctionreturnsanunsignedshortarrayofdoublethelengthspecified.
Parameters

lengthhowmanyfloatstocreate,shouldequalthelengthofthedataarray

offsetwhicharraypositiontobeginconvertingfrom

datafloat/singlearraytoconverttoanunsignedshortarray
byteswap(optional)specifiesthatthebyteorderistobeswapped,falseifnotspecified
wordswap(optional)specifiesthatthewordorderistobeswapped,falseifnotspecified
Examples
VisualC#
float[]data=newfloat[1]{987.0F};
sbMst.WriteWordMultiple(1,1,2,sbMst.WriteReal(1,0,data),delay:250);

VisualBasic
Dimdata(1)AsSingle

data(0)=987.0

sbMst.WriteWordMultiple(1,1,2,sbMst.WriteReal(1,0,data),delay:=250)

ReadDInt
VisualC#(ushortlength,ushortoffset,ushort[]data,[boolbyteswap=false],[boolwordswap=false])
VisualBasic(lengthAsUShort,offsetAsUShort,ByRefdata()AsUShort,[byteswapAsBoolean=False]

,[wordswapAsBoolean=False])
Description
Convertsanunsignedshortarrayintoanunsignedintegerarray.Each32bitunsignedintegervalueisthe
resultofmergingtwoconsecutive16bitunsignedshortvalues.
Return
Thefunctionreturnsanunsignedintegerofthelengthspecified.
Parameters

lengthhowmanyunsignedintegerstoconvert,shouldbehalfofthelengthofthedataarray

offsetwhicharraypositiontobeginconvertingfrom

dataunsignedshortarraytoconverttoanunsignedintegerarray
byteswap(optional)specifiesthatthebyteorderistobeswapped,falseifnotspecified
wordswap(optional)specifiesthatthewordorderistobeswapped,falseifnotspecified
Examples
VisualC#
ushort[]data=newushort[2];
sbMst.ReadWords(1,1,2,outdata,delay:250);
uint[]idata=sbMst.ReadDInt(1,0,data);

VisualBasic
Dimdata(2)AsUShort

sbMst.ReadWords(1,1,2,data,delay:=250)

Dimidata()AsUInteger
idata=sbMst.ReadDInt(1,0,data)

WriteDInt
VisualC#(ushortlength,ushortoffset,uint[]data,[boolbyteswap=false],[boolwordswap=false])
VisualBasic(lengthAsUShort,offsetAsUShort,ByRefdata()AsUInteger,[byteswapAsBoolean=False]

,[wordswapAsBoolean=False])
Description
Convertsanunsignedintegerarrayintoanunsignedshortarray.Each32bitunsignedintegervalueis
splitintotwoconsecutive16bitunsignedshortvalues.
Return
Thefunctionreturnsanunsignedshortarrayofdoublethelengthspecified.
Parameters

lengthhowmanyunsignedintegerstocreate,shouldequalthelengthofthedataarray

offsetwhicharraypositiontobeginconvertingfrom

dataunsignedintegerarraytoconverttoanunsignedshortarray
byteswap(optional)specifiesthatthebyteorderistobeswapped,falseifnotspecified
wordswap(optional)specifiesthatthewordorderistobeswapped,falseifnotspecified
Examples
VisualC#
uint[]data=newuint[1]{99999};
sbMst.WriteWordMultiple(1,1,2,sbMst.WriteDInt(1,0,data),delay:250);

VisualBasic
Dimdata(1)AsUInteger

data(0)=99999

sbMst.WriteWordMultiple(1,1,2,sbMst.WriteDInt(1,0,data),delay:=250)

BitPack
VisualC#(ushortoffset,bool[]data,[ushortlength=16],[boolbyteswap=false],[boolorderswap=false])
VisualBasic(offsetAsUShort,ByRefdata()AsBoolean,[lengthAsUShort=16],[byteswapAsBoolean=False]

,[orderswapAsBoolean=False])
Description
Convertsabooleanarrayofupto16valuesintoasingleunsignedshort.Eacharraypositionn(from0to
15)represents2n+1andall16aresummedtocreateasingleunsignedshort.
Return
Thefunctionreturnsanunsignedshort.
Parameters
offsetwhicharraypositiontobeginconvertingfrom

databooleanarraytoconverttoanunsignedshort

length(optional)numberofbooleanvaluesinarraytoconvert(16maximum),16ifnotspecified
byteswap(optional)specifiesthatthebyteorderistobeswapped,falseifnotspecified
orderswap(optional)specifiesthatthebitorderistobeswapped,falseifnotspecified
Examples
VisualC#
bool[]data=newbool[16];
data[0]=true;
data[7]=true;
sbMst.WriteWordSingle(1,1,sbMst.BitPack(0,data,length:16),delay:250);

VisualBasic

Dimdata(16)AsBoolean
data(0)=True
data(7)=True
sbMst.WriteWordSingle(1,1,sbMst.BitPack(0,data,length:=16),delay:=250)

BitUnpack
VisualC#(ushortdata,[boolbyteswap=false],[boolorderswap=false])
VisualBasic(dataAsUShort,[byteswapAsBoolean=False],[orderswapAsBoolean=False])
Description
Convertsanunsignedshortintoabooleanarrayof16values.Eacharraypositionn(from0to15)is
derivedfromthebinaryrepresentationoftheunsignedshort.
Return
Thefunctionreturnsabooleanarray.
Parameters

dataunsignedshorttoconverttoabooleanarray
byteswap(optional)specifiesthatthebyteorderistobeswapped,falseifnotspecified
orderswap(optional)specifiesthatthebitorderistobeswapped,falseifnotspecified
Examples
VisualC#

ushort[]data=newushort[1];
bool[]bdata=newbool[16];
sbMst.ReadWords(1,1,1,outdata,delay:250);
bdata=sbMst.BitUnpack(data[0]);

VisualBasic

Dimdata(1)AsUShort
Dimbdata(16)AsBoolean
sbMst.ReadWords(1,1,1,data,delay:=250)
bdata=sbMst.BitUnpack(data(0))

IntToBool
VisualC#(ushortlength,ushort[]data)
VisualBasic(lengthAsUShort,ByRefdata()AsUShort)
Description
Convertsanunsignedshortarrayintoabooleanarray.Foreachvalue,0=falseandanyvaluegreater
than0istrue.
Return
Thefunctionreturnsabooleanarrayofthespecifiedlength.
Parameters
lengthnumberofunsignedshortvaluestoconvert
dataunsignedshortarraytoconverttoabooleanarray
Examples
VisualC#

ushort[]udata=newushort[16];
udata[0]=1;
udata[7]=1;
sbMst.WriteBitMultiple(1,1,16,sbMst.IntToBool(16,udata));

VisualBasic
Dimudata(16)AsUShort

udata(0)=1

udata(7)=1

sbMst.WriteBitMultiple(1,1,16,sbMst.IntToBool(16,udata))

BoolToInt
VisualC#(ushortlength,bool[]data)
VisualBasic(lengthAsUShort,ByRefdata()AsBoolean)
Description
Convertsabooleanarrayintoanunsignedshortarray.Foreachvalue,false=0andtrue=1.
Return
Thefunctionreturnsanunsignedshortarrayofthespecifiedlength.
Parameters
lengthnumberofbooleanvaluestoconvert

databooleanarraytoconverttoanunsignedshortarray
Examples
VisualC#

bool[]data=newbool[16];
ushort[]idata=newushort[16];
sbMst.ReadBits(1,1,16,outdata,delay:250);
idata=sbMst.BoolToInt(16,data);

VisualBasic

Dimdata(16)AsBoolean
Dimidata(16)AsUShort
sbMst.ReadBits(1,1,16,data,delay:=250)
idata=sbMst.BoolToInt(16,data)

MasterExampleofUsage(TwoSerialPorts)
VisualC#
namespaceMB_Test
{
publicpartialclassForm1:Form
{
publicForm1()
{
InitializeComponent();
Variables.sb1.SetCOMPort(1,19200,8,'N',1);
Variables.sb2.SetCOMPort(3,19200,8,'N',1);
}

publicclassVariables
{
publicstaticShortBus.Mastersb1=newShortBus.Master();
publicstaticShortBus.Mastersb2=newShortBus.Master();
publicstaticushort[]data1=newushort[10];
publicstaticushort[]data2=newushort[10];
}

//periodicallypolldevices,placeresponsesinpublicstaticarraysfor
//universaluseinprogram
privatevoidtimer1_Tick(objectsender,EventArgse)
{
Variables.sb1.ReadWords(1,1,10,outVariables.data1,delay:250);
Variables.sb2.ReadWords(1,1,10,outVariables.data2,delay:250);
}
}
}

VisualBasic
PublicClassForm1
PrivateSubForm1_Load(senderAsObject,eAsEventArgs)HandlesMyBase.Load
Variables.sb1.SetCOMPort(1,19200,8,"N",1)
Variables.sb2.SetCOMPort(3,19200,8,"N",1)
EndSub

PublicClassVariables
PublicShareddata1(10)AsUShort
PublicShareddata2(10)AsUShort
PublicSharedsb1AsNewShortBus.Master()
PublicSharedsb2AsNewShortBus.Master()
EndClass

'periodicallypolldevices,placeresponsesinpublicsharedarraysfor
'universaluseinprogram
PrivateSubTimer1_Tick(senderAsObject,eAsEventArgs)HandlesTimer1.Tick
Variables.sb1.ReadWords(1,1,10,Variables.data1,delay:=250)
Variables.sb2.ReadWords(1,1,10,Variables.data2,delay:=250)
EndSub
EndClass

MasterExampleofUsage(TwoTCP/IPConnections)
VisualC#
namespaceMB_Test
{
publicpartialclassForm1:Form
{
publicForm1()
{
InitializeComponent();
Variables.sb1.TCPMode=true;
Variables.sb2.TCPMode=true;
Variables.sb1.TCPAddress="192.168.1.60";
Variables.sb2.TCPAddress="192.168.1.61";
Variables.sb1.TCPPort=502;
Variables.sb2.TCPPort=502;
}

publicclassVariables
{
publicstaticShortBus.Mastersb1=newShortBus.Master();
publicstaticShortBus.Mastersb2=newShortBus.Master();
publicstaticushort[]data1=newushort[10];
publicstaticushort[]data2=newushort[10];
}

//periodicallypolldevices,placeresponsesinpublicstaticarraysfor
//universaluseinprogram
privatevoidtimer1_Tick(objectsender,EventArgse)
{
Variables.sb1.ReadWords(1,1,10,outVariables.data1,delay:250);
Variables.sb2.ReadWords(1,1,10,outVariables.data2,delay:250);
}
}
}

VisualBasic
PublicClassForm1
PrivateSubForm1_Load(senderAsObject,eAsEventArgs)HandlesMyBase.Load
Variables.sb1.TCPMode=True
Variables.sb2.TCPMode=True
Variables.sb1.TCPAddress="192.168.1.60"
Variables.sb2.TCPAddress="192.168.1.61"
Variables.sb1.TCPPort=502
Variables.sb2.TCPPort=502
EndSub

PublicClassVariables
PublicShareddata1(10)AsUShort
PublicShareddata2(10)AsUShort
PublicSharedsb1AsNewShortBus.Master()
PublicSharedsb2AsNewShortBus.Master()
EndClass

'periodicallypolldevices,placeresponsesinpublicsharedarraysfor
'universaluseinprogram
PrivateSubTimer1_Tick(senderAsObject,eAsEventArgs)HandlesTimer1.Tick
Variables.sb1.ReadWords(1,1,10,Variables.data1,delay:=250)
Variables.sb2.ReadWords(1,1,10,Variables.data2,delay:=250)
EndSub
EndClass

SlaveExampleofUsage(TwoSerialPorts)
VisualC#
namespaceMB_Test
{
publicpartialclassForm1:Form
{
publicForm1()
{
InitializeComponent();
Variables.sb1.SetPort(1,19200,8,'N',1);
Variables.sb2.SetPort(3,19200,8,'N',1);
Variables.sb1.Open();
Variables.sb2.Open();
Variables.sb1.Enable3x=false;
Variables.sb2.Enable3x=false;
}

publicclassVariables
{
publicstaticShortBus.Slavesb1=newShortBus.Slave();
publicstaticShortBus.Slavesb2=newShortBus.Slave();
publicstaticushort[]prgData1=newushort[10];
publicstaticushort[]prgData2=newushort[10];
}

//periodicallypopulatedataarraywithprogramvariables
privatevoidtimer1_Tick(objectsender,EventArgse)
{
for(ushorta=0;a<10;++a)
{
Variables.sb1.Data4x[a]=Variables.prgData1[a];
Variables.sb2.Data4x[a]=Variables.prgData2[a];
}
}
}
}

VisualBasic
PublicClassForm1
PrivateSubForm1_Load(senderAsObject,eAsEventArgs)HandlesMyBase.Load
Variables.sb1.SetPort(1,19200,8,"N",1)
Variables.sb2.SetPort(3,19200,8,"N",1)
Variables.sb1.Open()
Variables.sb2.Open()
Variables.sb1.Enable3x=False
Variables.sb2.Enable3x=False
EndSub

PublicClassVariables
PublicSharedprgData1(10)AsUShort
PublicSharedprgData2(10)AsUShort
PublicSharedsb1AsNewShortBus.Slave()
PublicSharedsb2AsNewShortBus.Slave()
EndClass

'periodicallypopulatedataarraywithprogramvariables
PrivateSubTimer1_Tick(senderAsObject,eAsEventArgs)HandlesTimer1.Tick
Fora=0To9
Variables.sb1.Data4x(a)=Variables.prgData1(a)
Variables.sb2.Data4x(a)=Variables.prgData2(a)
Next
EndSub
EndClass

You might also like