Lantronix Device Connection with serial feedback

This program waits for the Lantronix device to give an acknowledgment of a net connection before it starts to send data. The Lantronix Device has to have its connect mode set to verbose, so that it will send ASCII N when not connected, ASCII D when disconnecting, and ASCII C when a connection is made.

Technorati Tags: ,


'     connection to the Lantronix device through a hex inverter:
TX var portd.0
RX var portd.1

' serial to PC for debugging:
debugTX var portc.6

' some indicator LED's for later use:
yellowLED var portb.2
greenLED var portb.7
redLED var portb.3

' two switches:
switch1 var portb.0
switch2 var portb.1

' data coming in the serial port:
inbyte var byte

'    set the switch pins to input mode:
input switch1
input switch2

' clear all variables:
clear

main:
    ' the Lantronix device is set to connect mode D5, meaning that
    ' it will return a byte to the PIC to indicate
    ' the connection status. a "C" means it's
    ' connected to a remote device or server.
    ' this routine waits for a C:
    
    while inByte <> "C"
        serin2 RX, 16468, [inbyte]
        serout2 portc.6, 16468, [inbyte, 10, 13]    
    wend
    
    ' once we're connected, we send out the switch states
    ' via the Lantronix devic:
    serout2 TX, 16468, ["b0: ", DEC portb.0, 9, "b1: ", DEC portb.1, 10, 13]    
goto main