Jump to content

VB .Net error


A_Mia

Recommended Posts

All,

I need to write to a timer preset and am getting an 'object' error using the .net driver.

I'm sort of between a rock and a hard place...

THanks in advance.

Below is the 'function' that attempts to write -

Public Function Write_TimerPreset(ByVal tmrIndex As Int16, ByVal TmrValue As integer) As Boolean

Dim values As Object() = New Object(2) {}

Try

values(0) = DirectCast(TmrValue, Object)

Catch

System.Windows.Forms.

MessageBox.Show("One of more of the values are not valid")

Return False

Exit Function

End Try

Dim wo As WriteOperands = New WriteOperands()

With wo

.NumberOfOperands = 1

.OperandType =

OperandTypes.TimerPreset

.StartAddress = tmrIndex

.Values = values

.TimerValueFormat = TimerValueFormat.SecondsFormat

End With

Dim rw(0) As ReadWriteRequest

rw(0) = wo

Try

plc.ReadWrite(rw)

Catch

Dim ErrorMessage As String = "Could not communicate with the PLC" & vbCrLf & "Error # " & Str(Err.Number) & " was generated by " _

& Err.Source & vbCrLf & Err.Description

'Display the message as a critical message.

MsgBox(ErrorMessage,

MsgBoxStyle.Critical, "PLC Connection Error")

CaptureErr(EquipmentPK,

"Unitronics Class", "Write_TimerPreset", Str(Err.Number), Err.Source, Err.Description, Now(), EmployeePK, 0)

Return False

End Try

Return True

End Function

post-8786-0-92991000-1362343003_thumb.jpg

Link to comment
Share on other sites

That's because you have a 3 values array and only the first one has a value (while the other 2 are Null, ergo Null Reference exception), and you are also writing only 1 value so no need to 3 values array.

instead of:

Dim values As Object() = New Object(2) {}

have it:

Dim values As Object() = New Object(0) {}

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

This site uses cookies. By clicking I accept, you agree to their use.