A_Mia Posted March 3, 2013 Report Share Posted March 3, 2013 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 Quote Link to comment Share on other sites More sharing options...
Saragani Posted March 4, 2013 Report Share Posted March 4, 2013 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) {} Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.