OnErrorEvent Event

Description

Notification that an error has occurred and the control cannot complete data transaction

NOTE: nErrorCode parameter changed to from signed short (VB Integer) to Long in version 6.0

VB 6.0

Sub ABCTL_OnErrorEvent( nErrorCode as Long )

VC ++

void CABCTL::OnErrorEvent ( long nErrorCode  )

VB .NET

Private Sub AxABCTL1_OnErrorEvent(ByVal sender As Object, ByVal e As AxABCTLLib._DABCTLEvents_OnErrorEventEvent) Handles AxABCTL1.OnErrorEvent

Parameters

nErrorCode - An error code describing the failure.

nErrorCode < 0 is an IN-GEAR driver related error.

nErrorCode > 0 is a PLC related error

Remarks

When OnErrorEvent fires, the control is providing you notification the read/write transaction with the PLC has failed. 

 

VB 6.0 Example

Sub Command1_Click()
  ABCTL1.Adapter = 0        ' * use adapter 1
  ABCTL1.Node = 2           ' * to PLC Node 2
  ABCTL1.Function = 0       ' * read PLC
  ABCTL1.FileAddr = "N7:0"  ' * starting at N7:0
  ABCTL1.Size = 10          ' * for 10 data points
ABCTL1.Trigger             ' * tell control to read data
End Sub

Sub ABCTL1_OnErrorEvent( nErrorCode as Integer)
  Dim ErrStr as String
  ErrStr = "PLC Communication Error " & Hex$(nErrorCode)
  MsgBox ErrStr
End Sub

VC ++ Example

void MyCWndClass:: OnBtn1Click()
{
  m_ABCTL1.SetAdapter(0);   // * use adapter 1
  m_ABCTL1.SetNode("2");    // * to PLC Node 5
  m_ABCTL1.SetFunction(0);  // * read PLC
  m_ABCTL1.SetFileAddr("N7:0");  // * starting at N7:0
  m_ABCTL1.SetSize(10);     // * for 10 data points
  m_ABCTL1.SetWordVal(0, 100); // * populate the controls data array
  m_ABCTL1.SetWordVal(1, 200);   
  ...
  m_ABCTL1.SetWordVal(9, 1000);

  m_ABCTL1.Trigger();   // * tell control to write data
}
End Sub

void MyCWndClass:: ABCTLOnErrorEvent( short nErrorCode )
{

CString errMsg;

errMsg.Format ("Communication Error %d", nErrorCode );

AfxMessageBox(errMsg);
}
End Sub

VB .NET Example

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

AxABCTL1.Adapter = 0 ' * use adapter 0

AxABCTL1.Node = 2 ' * to PLC Node 2

AxABCTL1.Function = 1 ' * WRITE PLC

AxABCTL1.FileAddr = "N7:0" ' * starting at N7:0

AxABCTL1.CtlSize = 3 ' * for 3 data points

AxABCTL1.set_WordVal(0,1) ‘ * value for N7:0

AxABCTL1.set_WordVal(1,1) ‘ * value for N7:1

AxABCTL1.set_WordVal(2,2) ‘ * value for N7:2

AxABCTL1.Trigger() ' * tell control to write the data

End Sub

 

Private Sub AxABCTL1_OnErrorEvent(ByVal sender As Object, ByVal e As AxABCTLLib._DABCTLEvents_OnErrorEventEvent) Handles AxABCTL1.OnErrorEvent

 

Dim nErrorCode as System.Int16

nErrorCode = AxABCTL1.ErrorCode

Text1.Text = "Communication Error " & nErrorCode

Also See

Error Code Property | ErrorCode List | Winsock Error Codes