xport code, have example, confused though


Closed Thread
Results 1 to 15 of 15

Hybrid View

  1. #1
    Join Date
    Feb 2005
    Location
    Toronto, Canada
    Posts
    46

    Default xport code, have example, confused though

    Hi everyone. so I'm excited to get the xport direct up and running and I see some of you here have used it.

    I got the following code from : http://www.tigoe.net/pcomp/code/cate...basic%20Pro/35
    but I'm unsure of how to use it. (can a 16f628 run the xport? it can right? it's just serial communication...)

    my understanding thus far is

    1. I need to use a terminal such as windows hyperterminal to set it up (can this instead be done via pbp?

    2. hook up and run code.

    I'm unsure of an exact hook up but I'm sure the manual will tell me, but I've tried to first compile the example code and get LOTS of errors...

    not sure why, are there includes or other things I should be doing to get this code to compile? I'm using microcode studio and pbp 2.45

    Thanks for any and all help!


    Code:
    The relevant Xport settings for this application are as follows:
    
    *** Channel 1
    Baudrate 9600, I/F Mode 4C, Flow 00
    Port 10001
    Remote IP Adr: --- none ---, Port 00000
    Connect Mode : D4
    Disconn Mode : 00
    Flush   Mode : 00
    
    *** Expert
    TCP Keepalive    : 45s
    ARP cache timeout: 600s
    High CPU performance: disabled
    Monitor Mode @ bootup : enabled
    HTTP Port Number : 80
    SMTP Port Number : 25
    
    The code:
    
    ' Xport_to_SQL
    '    Microcontroller is connected to a Lantronix Xport
    '    serial-to-ethernet device. This program connects
    '    to a HTTP server through the Xport, makes a HTTP GET
    '    request for a PHP script, and sends the value
    '    of an analog sensor through as a part of the
    '    GET request.
    
    '    Xport communicates at 9600-8-n-1 non-inverted (true) serial.
    
    '    By Tom Igoe, 31 oct 2005
    '    updated 25 Oct. 2005
    
     ' Define ADCIN parameters
    DEFINE  ADC_BITS        10     ' Set number of bits in result
    DEFINE  ADC_CLOCK       3         ' Set clock source (3=rc)
    DEFINE  ADC_SAMPLEUS    50        ' Set sampling time in uS
    
    '   pins to define serial RZX and TX
    tx var portc.6
    rx var portc.7
    '   pins with LEDs to indicate whether we're connecting
    '   or sending an HTTP request:
    httpPin var portb.7
    TCPPin var portb.6
    output TCPPin
    output httpPin
    
    ' constant to set the baud rate:
    inv9600 con 16468
    '   for non-inverted connections (PIC to Xport direct):
    true9600 con 84
    
    ' define variables:
    adcVar var word
    inByte var byte
    connected var bit
    
    TRISA = %11111111       ' Set PORTA to all input
    ADCON1 = %10000010      ' Set PORTA analog and right justify result
    
    connected = 0
    
    ' pause to let Xport boot up:
    pause 2000
     main:
      ' if you're connected to the server, then
      ' make a HTTP call.  If not, then connect
      ' to the server:
      if connected = 1 then
      ' read sensors, convert to bytes:
          adcin 0, adcVar
          ' send HTTP GET request for php script:
        gosub http_request
      else
        ' attempt to connect to the server:
        gosub xport_connect
      endif
      tcpPin = connected
      ' pause so we're not overwhelming the server:
      pause 3000
    goto main
    
    xport_connect:
        ' turn off LED to indicate HTTP GET is in progress:
        'low tcpPin
        '   wait for a "C" byte to come back:
        while inByte <> 67
            serout2 tx, true9600, ["C128.122.253.189/80", 10]
            serin2 rx, true9600, [inByte]
        wend
        ' turn on TCP pin to indicate that we connected:
        'high TCPPin
        connected = 1
    return
    
    http_request:
        ' light LED to indicate HTTP GET request in progress:
        high httpPin
        SEROUT2 TX, true9600, ["GET /~tqi6023/sql_datalog.php?action=insert&"]
        serout2 tx, true9600, ["sensorValue=", DEC adcVar]
        serout2 tx, true9600, [" HTTP/1.1", 10]
        serout2 tx, true9600, ["HOST: itp.nyu.edu", 10, 10]
        ' wait for bytes from server:
        ' php script sends a 0 to end transmission:
        while inByte <> 0
            serin2 rx, true9600, [inByte]
        wend
        ' now we're disconnected:
        connected = 0
        ' turn off LED, since GET request is complete:
        low httpPin
    return

  2. #2
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Hi Kenpo,
    I do not think 628 is going to do it, no ADC.
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

  3. #3
    Join Date
    Feb 2005
    Location
    Toronto, Canada
    Posts
    46


    Did you find this post helpful? Yes | No

    Default

    sorry, please ignore the ADC code he has in there then.
    I have no plans of using ADC.

    for now I simply want to send an integer number to an online script.

    just a test.
    I didn't want to edit his code and risk removing soemthing I shouldn't so it's just a copy/paste

  4. #4
    Join Date
    Feb 2005
    Location
    Toronto, Canada
    Posts
    46


    Did you find this post helpful? Yes | No

    Default

    ok, so here's my modified version:

    untested, but compiles.

    what I am unsure of:
    1. how to set the xport with all the funky terminal settings and if it can be done via pbp

    2. right now his code waits for a 0 return.
    I'd like to receive more than that. ie, the number 55 and then do something like turn a pin HIGH. I'm unsure of how to do that though without breaking it. ie, it's waiting for a 0 return..

    sorry for those of you that breath code, this must seem very silly

    Code:
    include "modedefs.bas"
    
    @ DEVICE pic16F628A, INTRC_OSC_NOCLKOUT
    ' System Clock Options 
    
    @ DEVICE pic16F628A, MCLR_OFF
    ' Master Clear Options (Internal)
      DEFINE OSC 4
      CMCON = 7		
    
    
    
    
    '   pins to define serial RZX and TX
    tx var portA.6
    rx var portA.7
    '   pins with LEDs to indicate whether we're connecting
    '   or sending an HTTP request:
    httpPin var portb.7
    TCPPin var portb.6
    output TCPPin
    output httpPin
    
    ' constant to set the baud rate:
    inv9600 con 16468
    '   for non-inverted connections (PIC to Xport direct):
    true9600 con 84
    
    ' define variables:
    adcVar var word
    inByte var byte
    connected var bit
    
    connected = 0
    
    ' pause to let Xport boot up:
    pause 2000
     main:
      ' if you're connected to the server, then
      ' make a HTTP call.  If not, then connect
      ' to the server:
      if connected = 1 then
      ' read sensors, convert to bytes:
          adcVar = 55
          ' send HTTP GET request for php script:
        gosub http_request
      else
        ' attempt to connect to the server:
        gosub xport_connect
      endif
      tcpPin = connected
      ' pause so we're not overwhelming the server:
      pause 3000
    goto main
    
    xport_connect:
        ' turn off LED to indicate HTTP GET is in progress:
        'low tcpPin
        '   wait for a "C" byte to come back:
        while inByte <> 67
            serout2 tx, true9600, ["C128.122.253.189/80", 10]
            serin2 rx, true9600, [inByte]
        wend
        ' turn on TCP pin to indicate that we connected:
        'high TCPPin
        connected = 1
    return
    
    http_request:
    adcVar = 56
        ' light LED to indicate HTTP GET request in progress:
        high httpPin
        SEROUT2 TX, true9600, ["GET /xport_test.php?action=insert&"]
        serout2 tx, true9600, ["sensorValue=", DEC adcVar]
        serout2 tx, true9600, [" HTTP/1.1", 10]
        serout2 tx, true9600, ["HOST: brandejs.ca", 10, 10]
        ' wait for bytes from server:
        ' php script sends a 0 to end transmission:
        while inByte <> 0
            serin2 rx, true9600, [inByte]
        wend
        ' now we're disconnected:
        connected = 0
        ' turn off LED, since GET request is complete:
        low httpPin
    return

  5. #5
    Join Date
    Feb 2005
    Location
    Toronto, Canada
    Posts
    46


    Did you find this post helpful? Yes | No

    Default

    look at me, spamming my own post...

    just wondering, could I do soemthing like change

    Code:
    while inByte <> 0
            serin2 rx, true9600, [inByte]
        wend
    to

    Code:
    while inByte == z
            serin2 rx, true9600, [inByte]
        wend
    that way I set inByte earlier on as 'z' and then it hangs down below until I get the number 55, or 3 or 0.

    I'm imagining grabbing the weather value in degrees off the net for example

    (and having my php script only output an integer value, not the extra html filler)

  6. #6
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Forget SERIN/SEROUT @ 9600 baud @4MHZ... even worst when dealing with the internal OSC. That PIC have a USART, use it + ceramic resonator + crystal for more reliable results.

    You could try DEBUG/DEBUGIN... but there's no advantages over HSERIN/HSEROUT appart the possibility to use Inverted mode.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  7. #7
    safa913's Avatar
    safa913 Guest


    Did you find this post helpful? Yes | No

    Question hello

    i have xport direct plus and i use 16f877a pic
    can i use the same code ?

Similar Threads

  1. Reading in Manchester code
    By brid0030 in forum Code Examples
    Replies: 0
    Last Post: - 10th March 2009, 21:55
  2. How much code space do PBP statements use.
    By Darrel Taylor in forum Code Examples
    Replies: 5
    Last Post: - 13th February 2009, 21:31
  3. Loop with two motor and 2 sensors
    By MrRoboto in forum mel PIC BASIC
    Replies: 4
    Last Post: - 8th December 2008, 23:40
  4. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08:26
  5. Re-Writing IF-THEN-AND-ENDIF code?
    By jessey in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 18th August 2006, 17:23

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