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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...