Class/structure/something else in class

  • Thread starter =?iso-8859-1?B?UmVu6SBKZW5zZW4=?=
  • Start date
?

=?iso-8859-1?B?UmVu6SBKZW5zZW4=?=

Hello

I got a problem with a class i'm trying to create.

the problem is that i would like to use the dot when i access some
parametes in the class

like.

Connect()
measure.current(10)
trigger()
disconnect()

the class access some hardware

connect opens the serialport
disconnect close it again

trigger sendst a command to the serialport to start measure.

and measure.current i want to send a command to the same serialport
but how? can onyone paste a few lines of code how do to this.

Thanks in advance

René
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

René Jensen said:
Hello

I got a problem with a class i'm trying to create.

the problem is that i would like to use the dot when i access some
parametes in the class

like.

Connect()
measure.current(10)
trigger()
disconnect()

the class access some hardware

connect opens the serialport
disconnect close it again

trigger sendst a command to the serialport to start measure.

and measure.current i want to send a command to the same serialport
but how? can onyone paste a few lines of code how do to this.

Thanks in advance

René

Which class is it that you are trying to create? Is it the class that
contains these methods, or the class of the measure property?

Why is it that you want to use a period? What is it that you want to
accomplish?
 
?

=?iso-8859-1?B?UmVu6SBKZW5zZW4=?=

What i need is a class containing

connect()
Disconnect()
measurecurrent(channel as int)
measurevoltage(channel as int)
...... (there is about 10 meassure)
scanaddcurrent(channel as int)
scanaddvoltage(channel as int)
......(there is the same 10 as measure)
trigger()

and i can easily create this
but the below makes more sense i think

so what i want is to somehow create
connect()
Disconnect()
measure.voltage(channel as int)
measure.amp(channel as int)
measere.(the 10 others)
scanadd.amp(channel as int)
scanadd.(the rest of the possebilities)
trigger()

the options (voltage, amp, etc.) are the same for measure and scan

as the first class(acq) know the serial port it can easily do the
measureamp as this is just send a textstring to the serial port.

But measure.amp the second class containg the measure options will not
know the serial port and can't send the data there by

did that make sense

I'n very new to OOP
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

René Jensen said:
What i need is a class containing

connect()
Disconnect()
measurecurrent(channel as int)
measurevoltage(channel as int)
..... (there is about 10 meassure)
scanaddcurrent(channel as int)
scanaddvoltage(channel as int)
.....(there is the same 10 as measure)
trigger()

and i can easily create this
but the below makes more sense i think

so what i want is to somehow create
connect()
Disconnect()
measure.voltage(channel as int)
measure.amp(channel as int)
measere.(the 10 others)
scanadd.amp(channel as int)
scanadd.(the rest of the possebilities)
trigger()

the options (voltage, amp, etc.) are the same for measure and scan

as the first class(acq) know the serial port it can easily do the
measureamp as this is just send a textstring to the serial port.

But measure.amp the second class containg the measure options will not
know the serial port and can't send the data there by

did that make sense

I'n very new to OOP

Create a class for the Measure and ScanAdd properties, and make their
constructors take either a reference to the serial port object or the
parent object.

Example:

Public Class Serial

'command class for Measure
Public Class MeasureCommands

'reference to parent
Private _parent As Serial

Public Sub MeasureCommands(parent As Serial)
_parent = parent
End Sub

Public Function Voltage(channel As Integer) As Integer
'uses _parent to access serial port
End Function

End Class

'command class for ScanAdd
Public Class ScanAddCommands

'reference to parent
Private _parent As Serial

Public Sub ScanAddCommands(parent As Serial)
_parent = parent
End Sub

Public Sub Amp(channel as Integer)
'uses _parent to access serial port
End Sub

End Class

'local variables for command objects
Private _measure As MeasureCommands
Private _scanAdd As ScanAddCommands

Public Sub Serial()
'create commands objects
_measure = New MeasureCommands(Me)
_scanAdd = New ScanAddCommands(Me)
End Sub

Public Property Measure() As MeasureCommands
Get
Return _measure
End Get
End Property

Public Property ScanAdd() As ScanAddCommands
Get
Return _scanAdd
End Get
End Property

End Class
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top