Link to home
Create AccountLog in
Avatar of kavvis
kavvis

asked on

VB.NET Advantech PCI-1761 Write I/O

I have a problem that I belived I hade the solution on but right now I don´t know....

I have a I/O-card that I use in my VB.net application. I test the "demo" I get from the manufactory. The I/O card has 0-7 outputs...

 Private Sub PictureBox_Click(ByVal sender As Object, ByVal e As EventArgs)
        Dim err As ErrorCode = ErrorCode.Success
        Dim box As PictureBox = DirectCast(sender, PictureBox)
        Dim boxInfo As DoBitInformation = CType(box.Tag, DoBitInformation)

        boxInfo.BitValue = (Not CInt((boxInfo).BitValue)) And &H1
        box.Tag = boxInfo
        box.Image = imageList1.Images(boxInfo.BitValue)
        box.Invalidate()

        ' refresh hex
        Dim state As Integer = Int32.Parse(m_portHex(boxInfo.PortNum - ConstVal.StartPort).Text, NumberStyles.AllowHexSpecifier)
        state = state And Not (&H1 << boxInfo.BitNum)
        state = state Or boxInfo.BitValue << boxInfo.BitNum

        m_portHex(boxInfo.PortNum - ConstVal.StartPort).Text = state.ToString("X2")
        err = InstantDoCtrl1.Write(boxInfo.PortNum, CByte(state))
        If err <> ErrorCode.Success Then
            HandleError(err)
        End If
    End Sub

Open in new window


that code works but When I try to clean the code up I can´t it to work as I want in my real application.

This is whats happens..

When I run the demo mode in debug mode I can se that when I hit the first ouput the "    err = InstantDoCtrl1.Write(boxInfo.PortNum, CByte(state))"  (state = 1 )
And then I hit the last output
the state = err = InstantDoCtrl1.Write(boxInfo.PortNum, CByte(state))"  (state = 128 )


it goes like this from 0 - 7 output   1 , 2, 4, 8, 16, 32, 64,128

If I hit the  2 output and the 4 output then I get
the state = err = InstantDoCtrl1.Write(boxInfo.PortNum, CByte(state))"  (state = 18 )

User generated image
So it works in the demo but I don´t how I shoud get it to work in my own application
or I mean it works in my application to
InstantDoCtrl1.Write(0, CByte(1))
But I´m not sure how I write to the diffrent I/O´s alone...
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of kavvis
kavvis

ASKER

-Thank you... well test this..