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.
Is there a way to do something like this.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
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
Bookmarks