Port bit manipulation useing variables


Results 1 to 5 of 5

Threaded View

  1. #1
    Join Date
    Dec 2004
    Location
    nebraska
    Posts
    79

    Default Port bit manipulation useing variables

    Hello,
    I Am writing a Modbus RTU program to talk with an ILon 100 internet Server. I am trying to streamline my code. I am using modbus single coil write function to write the value of PortB single bit values. The program below works but is there a better way than Case Select. When I say better I mean less code and faster. This is not the whole code but is the jist of the Case Select.

    Code:
    WriteSingleCoil:
    W0 = buffer[3]*255 + buffer[4]      'Combines MFrame 2 byte address into 1 word.
    W0 = w0 - 10                                'Sets up bit address for portB
    If buffer[5] > 0 Then
        Coilstate = 1
    else
        Coilstate = 0
    endif
    Select Case W0
        Case 1
            PORTB.0 = Coilstate
        Case 2
            PORTB.1 = Coilstate
        case 3
            PORTB.2 = Coilstate
        case 4
            PORTB.3 = Coilstate
        case 5
            PORTB.4 = Coilstate
        case 6
            PORTB.5 = Coilstate
        case 7
            PORTB.6 = Coilstate 
        Case 8
            PORTB.7 = Coilstate
        Case else              'test to see if program is getting here
            portb = 255
    End Select
    For B0 = 1 To 8                        ' Send the response to Master
        B1 = buffer[B0]
        Gosub charout
    Next B
    Return
    Is there a way to do something like this.


    PortB.w0 = Coilstate

    I tryed this but it does not work. I'm going to try to use an aliass next but Im not sure if thats a good choice either.
    Thanks
    Nick
    Last edited by ScaleRobotics; - 20th November 2010 at 15:42. Reason: added code tags

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts