VB – Using SAIA communication library.

How to use SAIA communication library with VB.

SAIA DLLs created with C programming language and to use these functions with VB need:

  • define variables to right type
  • write stdcall conventions for C functions in the DLL
  • create a some service functions

VB6 Module with define variables, stdcall conventions and service functions:

VS_source

First create VB application communication module in the project. Next create menu with options such as connect, disconnect and setup.

Connect function:


'Connect
Public Function connect() As String
  Dim Status As Long

  Status = PcdRdChanSetupFromIni("Test.ini", "MyTestApp", PcdOpenData)
  Status = PcdConnectChannel(PcdConn, PcdOpenData, 0, 1)
  connection = PcdOpenData.bConnected
End Function

'Disconnect
Public Function disconnect() As String
  Dim Status As Long

  Status = PcdRdChanSetupFromIni("Test.ini", "MyTestApp", PcdOpenData)
  Status = PcdDisconnectChannel(PcdConn, 0, 0)

  Message = disconnect
  connection = PcdOpenData.bConnected
  'Status = PcdComUnloadDrv(True)

End Function

'setup connection
Public Function ConnectionSetings() As String
  Dim Status As Long

  Status = PcdRdChanSetupFromIni("Test.ini", "MyTestApp",PcdOpenData)
  Status = PcdConnectionDialog(0, PcdOpenData)
  If Status = 1 Then
    Status = PcdWrChanSetupToIni("Test.ini", "MyTestApp", PcdOpenData)
  End If
  ConnectionSetings = "Settings"

End Function

'Exchange data
Private Sub Timer1_Timer()
  If connection = True Then

    'Write value of the slider as integer
    Regs(0) = Slider1.Value
    Result = WriteRegs(101, 1)

    'Read some integers valve
    Result = ReadRegs(101, 3)
    If Result = 0 Then
      Value1.Text = str(Regs(0))
      Value2.Text = str(Regs(1))
      Value3.Text = str(Regs(2))
    End If

    'Read 6 flags
    Result = ReadFlags(101, 6)
    If Result = 0 Then
      If Chr(flagsA(0)) = "0" Then
        in1.Picture = LoadPicture(F_ON)
      Else
        in1.Picture = LoadPicture(F_OUT)
      End If

      If Chr(flagsA(5)) = "0" Then
        in6.Picture = LoadPicture(F_ON)
      Else
        in6.Picture = LoadPicture(F_OUT)
      End If

    End If

End Function

 

    VS_source


Advertisements

One Response to “VB – Using SAIA communication library.”

  1. Kenan SATIR Says:

    Good information. Thanks

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: