markb


About me


  • markb has started 5 topics. 12 people are following them.
  • markb has made 2 replies.

Recent activity

Subscribe to this feed
  • question

    ezuk replied on October 01, 2008 10:32 to the question "Help!" in Tibbo:

    ezuk
    No such info at this time.
  • question

    viron replied on September 09, 2008 10:34 to the question "send a negative number (short) out serial port" in Tibbo:

    viron
    Add 65536 to the negative number. Apply your calculation to the result and send the bytes.

    At the receiving end if MSB is greater than 128 then after reconstruction subtract 65536 to get back the negative number.

    Attention the range of two byte signed integers is -32798 to 32768.

    Regards,
    Viron.
  • question

    KeinXor replied on September 08, 2008 13:28 to the question "does anyone have any DNS code please" in Tibbo:

    KeinXor
    DNS.tbs

    include "global.tbh"

    public dim sNameServerIP as string 'Name Server IP
    dim wID as word
    dim sOPCode as string(4) '0 = standard query, 1 = inverse query, 2 = server status request
    dim sRD as string(1) 'recursion desired
    dim wQDCount as word 'number of questions
    dim wQType as word 'query type
    dim wQClass as word 'query class
    public dim bAnsCount as byte 'number of answers

    'query type
    '+-----------------------+
    '| Value | Description |
    '+-------+---------------+
    '| 1 |IP Address |
    '| 2 |Name Server |
    '| 5 |Canonical name |
    '| 12 |pointer record |
    '| 13 |host info |
    '| 15 |mail exchange |
    '+-------+---------------+

    dim sQuestion as string 'the question(domain name) in DNS format
    dim sIPString as string 'contains all ip addresses mapped to the domain name in question.
    '---------------------------------------------------------------------------------------
    'Extract IPs from the response strings in the sock rx buffer, and store all IPs in the sIPString
    'Also return the result of the query.
    public function ExtractFromRXBuff as byte
    dim bPos as byte
    dim i as byte
    dim sIPStart as string
    dim sTemp as string
    dim bFlag as byte
    dim bRCode as byte
    dim sAns1 as string
    dim sAns2 as string
    dim sTempIP as string
    sock.num = 0
    sAns1 = sock.getdata(255)
    sAns2 = sock.getdata(255) 'the response string is longer than 255
    sIPStart = chr(0) + chr(1) + chr(0) + chr(1) '0001 0001 IP Address Answer
    bPos = instr(1,sAns1,sQuestion,1) 'the position of the question(Domain Name) in the respond packet
    bAnsCount = asc(mid(sAns1,bPos-5,1)) 'the number of answers
    bFlag = asc(mid(sAns1,bPos-9,1)) 'extracting the query result "RCode" from the flag
    bRCode = val("&b" + right(bin(bFlag),4))
    bPos = bPos + len(sQuestion) + 5
    'bPos = instr(bPos,sAns1,sIPStart,1) 'the position of first IP Address Answer
    if len(sAns2) > 0 then
    sTemp = right(sAns1,len(sAns1)-bPos) + left(sAns2,bPos) 'locating the part of response that contains IPs
    else
    sTemp = right(sAns1,len(sAns1)-bPos)
    end if
    for i = 1 to bAnsCount
    dim sIP as string
    dim bIPLen as byte
    bPos = instr(1,sTemp,sIPStart,i) + 9
    bIPLen = asc(mid(sTemp,bPos,1))
    sTempIP = sTempIP + str(i) + ":" + mid(sTemp,bPos,bIPLen + 1)
    next i
    sIPString = sTempIP
    ExtractFromRXBuff = str(bRCode) 'bRCode: 0:no error, 2:server fail, 3:name error
    end function
    '---------------------------------------------------------------------------------------
    'initialize DNS connection, and set the default value
    public sub InitDNS
    wID = 1
    sOPCode = "0000"
    sRD = "1"
    wQDCount = 1
    wQType = 1
    wQClass = 1
    sock.num = 0
    sock.txbuffrq(2)
    sock.rxbuffrq(4)
    sys.buffalloc
    sock.protocol = PL_SOCK_PROTOCOL_UDP
    sock.inconmode = PL_SOCK_INCONMODE_ANY_IP_ANY_PORT
    sock.reconmode=PL_SOCK_RECONMODE_3
    sock.targetip = sNameServerIP
    sock.targetport = 53
    sock.connect
    end sub
    '---------------------------------------------------------------------------------------
    'convert sTemp into binary string, padding the 0 and add to the sDNSQuery string
    function BinaryConverter(sTemp as string, sDNSQuery as string) as string
    sTemp = right(sTemp,len(sTemp) - 2)
    do while len(sTemp) < 16
    sTemp = "0" + sTemp
    loop
    BinaryConverter = sDNSQuery + chr(val("&b"+ left(sTemp,8))) + chr(val("&b"+ right(sTemp,8)))
    end function
    '---------------------------------------------------------------------------------------
    'form the DNS query string and send the query to DNS server
    public function Query(sQueryName as string) as string
    dim sDNSQuery as string
    dim sQFlag as string
    dim i as byte
    dim sTemp as string
    sDNSQuery = BinaryConverter(bin(wID),sDNSQuery)
    sQFlag = "0"+ sOPCode + "00" + sRD + "00000000"
    sDNSQuery = sDNSQuery + chr(val("&b"+ left(sQFlag,8))) + chr(val("&b"+ right(sQFlag,8)))
    sDNSQuery = BinaryConverter(bin(wQDCount),sDNSQuery)
    sDNSQuery = sDNSQuery + chr(0) + chr(0) + chr(0) + chr(0) + chr(0) + chr (0)
    sQueryName = sQueryName + "."
    do while instr(1,sQueryName,".",1) > 0
    dim bPos as byte
    bPos = instr(1,sQueryName,".",1)
    sTemp = sTemp + chr(bPos-1) + left(sQueryName, bPos-1)
    sQueryName = right(sQueryName, len(sQueryName)-bPos)
    loop
    sQuestion = sTemp
    sDNSQuery = sDNSQuery + sQuestion + chr(0)
    sDNSQuery = BinaryConverter(bin(wQType),sDNSQuery)
    sDNSQuery = BinaryConverter(bin(wQClass),sDNSQuery)
    sock.num = 0
    sock.setdata(sDNSQuery)
    sock.send
    Query = sDNSQuery
    end function
    '---------------------------------------------------------------------------------------
    'return the IP address according the index, in string format. (there can be many IP mapped
    'to one domain name.
    public function ConvertToIPString(bIndex as byte) as string
    dim sTemp as string
    dim bIPLen as byte
    dim bPos as byte
    if bIndex > bAnsCount then
    bIndex = 1
    end if
    bPos = instr(1,sIPString,str(bIndex)+":",1)
    bIPLen = asc(mid(sIPString,bPos + 2,1))
    sTemp = mid(sIPString,bPos+3,bIPLen)
    ConvertToIPString = ddstr(sTemp)
    end function
  • question

    KeinXor replied on September 08, 2008 13:27 to the question "does anyone have any DNS code please" in Tibbo:

    KeinXor
    global.tbh

    declare sNameServerIP as string
    declare bAnsCount as byte
    declare sub InitDNS
    declare function Query(sQueryName as string) as string
    declare function ExtractFromRXBuff as byte
    declare function ConvertToIPString(bIndex as byte) as string
  • question

    KeinXor replied on September 08, 2008 13:20 to the question "does anyone have any DNS code please" in Tibbo:

    KeinXor
    Hello,
    I hope that this code will help you:
    main.tbs

    include "global.tbh"

    sub on_sys_init
    'set IP address
    net.gatewayip = "192.168.1.1"
    net.netmask = "255.255.255.0"
    net.ip = "192.168.1.105"
    sNameServerIP = "168.95.1.1"
    InitDNS
    end sub

    sub on_sock_data_arrival
    dim s as byte
    dim k1 as string
    dim k2 as string
    dim k3 as string
    dim k4 as string
    dim k5 as string
    s = ExtractFromRXBuff
    k1 = ConvertToIPString(1)
    k2 = ConvertToIPString(2)
    k3 = ConvertToIPString(3)
    k4 = ConvertToIPString(4)
    k5 = ConvertToIPString(5)
    end sub

    sub on_button_pressed
    if sock.statesimple = PL_SSTS_EST then
    Query("www.yahoo.com")
    end if
    end sub
  • question

    markb replied on September 08, 2008 06:10 to the question "does anyone have any DNS code please" in Tibbo:

    markb
    does anyone have any tibbo basic code that implements DNS functionality?
  • question

    Eric Suesz replied on September 08, 2008 04:11 to the question "does anyone have any DNS code please" in Tibbo:

    Eric Suesz
    Is this a question for Tibbo? I'm a bit confused. Maybe you can add a little more detail?
  • question

    markb asked a question in Tibbo on September 06, 2008 10:03:

  • markb started following the question "Help!" in Tibbo.

  • question

    markb asked a question in Tibbo on September 06, 2008 10:00:

    markb
    send a negative number (short) out serial port
    I can send an integer (short) value out the serial port as two bytes by (value / 256) and (value AND 256), but this doesn't work for negative numbers.

    eg, my short is '-2', which is 0xFFFE, so I want to send 'FF' and then 'FE',but...

    -2 / 256 = 0 and
    -2 AND 256 = 0

    how can i split my short into it's two bytes when it's negative?

    TIA,
    Mark
  • question

    viron replied on September 04, 2008 08:41 to the question "talk to I2C device" in Tibbo:

    viron
    Hi,
    The DS2480B is a rs-232 to 1-wire protocol chip that can interface to 1-wire network.

    Regards,
    Viron.
  • question

    ezuk replied on September 01, 2008 12:41 to the question "talk to I2C device" in Tibbo:

    ezuk
    I think this is one for the official support. To tell you the truth, I'm not even sure it's possible. But aren't there real-time clocks that use SPI?
  • question

    A comment on the question "talk to I2C device" in Tibbo:

    markb
    thank you very much. this will do nicely. I was hoping there was an 'in-built' fuction rather than hand-coded solution in basic.. – markb, on August 31, 2008 00:21
  • question

    KeinXor replied on August 30, 2008 14:54 to the question "talk to I2C device" in Tibbo:

    KeinXor
    hello,
    in module EM1000 is real-time clock.
    To communicate with I2C procedure:
    i2c.tbh

    '------------------------------------------------------------------------------
    'Enumerations

    '------------------------------------------------------------------------------
    'Global variables

    '------------------------------------------------------------------------------
    'Pins definition
    const SDA= PL_IO_NUM_4_RTS
    const SCL= PL_IO_NUM_5
    '------------------------------------------------------------------------------
    'Function/Subrutines declaration

    declare function StoreIP(byref IP as string)as byte
    declare sub RestoreIP()



    i2c.tbs


    include "I2C.tbh"

    '------------------------------------------------------------------------------
    'Enumerations

    '------------------------------------------------------------------------------
    'Global variables

    '------------------------------------------------------------------------------
    'Pins definition

    const IP_DATA_LNG= 3 'Lenght of binary IP data (0-3)
    const IP_EE_ADD= 0 'Address in external EEPROM
    const EE_ADD= &hA0 'EEPROM hardware address (24C01...24C1025)
    '------------------------------------------------------------------------------
    'Function/Subrutines declaration

    declare sub I2C_Putc(x as byte)
    declare function I2C_Getc()as byte
    declare sub I2C_Start
    declare sub I2C_Stop
    declare sub I2C_Ack
    declare sub I2C_Nack

    '******************************************************************************
    'Store IP in external EEPROM
    '******************************************************************************
    public function StoreIP(byref IP as string)as byte

    dim IP_bin as byte 'IP binary data
    dim cnt as byte 'GP counter
    dim ReadData as byte 'Data read back from EEPROM

    for cnt = 0 to IP_DATA_LNG 'Write 4 binary IP bytes

    'Store one byte data to external EEPROM
    '---------------------------------------------------------------------
    IP_bin = asc(mid(IP,1 + cnt,1)) 'Convert singer character to binary data
    I2C_Start 'Process I2C start frame
    I2C_Putc(EE_ADD) '24Cxxx HW address + WRITE
    I2C_Putc(IP_EE_ADD + cnt) '24Cxxx memory address
    I2C_Putc(IP_bin) 'Send data to I2C device
    I2C_Stop 'Terminate I2C writting (I2C stop frame)

    'Read back the stored data back
    '---------------------------------------------------------------------
    I2C_Start 'Process I2C start frame
    I2C_Putc(&b10100000) 'Chip and region Address+WRITE
    I2C_Putc(IP_EE_ADD + cnt) 'Memory address
    I2C_Start 'Process I2C start(or restart) frame
    I2C_Putc(EE_ADD + 1) '24Cxxx HW address + READ
    ReadData = I2C_Getc 'Get data from I2C device
    I2C_Nack 'Terminate read procedure (I2C NACK frame)
    I2C_Stop 'Terminate I2C reading (I2C stop frame)

    'Check if the data was written correctly
    '---------------------------------------------------------------------
    if(IP_bin <> ReadData) then 'Check for correct writtnig
    StoreIP = 0 'Write in EEPROM error
    exit function
    end if
    next cnt
    StoreIP = 1 'Write to ext. EEPROM was OK

    end function
    '******************************************************************************
    'Update IP value from external EEPROM and save it in "net.ip" proprety
    '******************************************************************************
    public sub RestoreIP

    dim cnt as byte 'GP counter
    dim IP_bin as byte 'IP binary data
    dim IP_str as string(5) 'IP string data + NULL character??

    for cnt = 0 to IP_DATA_LNG 'Read 4 binary IP bytes
    I2C_Start 'Process I2C start frame
    I2C_Putc(&b10100000) '24Cxxx HW address + READ
    I2C_Putc(IP_EE_ADD + cnt) 'Memory address
    I2C_Start 'Process I2C start(or restart) frame
    I2C_Putc(EE_ADD + 1) 'Chip and region Address+READ
    IP_bin = I2C_Getc 'Get data from I2C device
    I2C_Nack 'Terminate read procedure (I2C NACK frame)
    I2C_Stop 'Terminate I2C reading (I2C stop frame)
    IP_str = IP_str + chr(IP_bin) 'Concatenate IP string data(reconstruct...)
    next cnt
    net.ip = ddstr(IP_str) 'Store IP addres to "net.ip" proprety

    end sub
    '******************************************************************************
    'I2C Put char subrutine
    '******************************************************************************
    sub I2C_Putc(vData as byte)

    dim bitCnt as byte 'Bits counter
    dim CompVal as byte 'Value to compare - MASK
    dim BitData as boolean 'Comparison result (1 or 0)

    io.num = SCL 'Initialize the transmition
    io.state = LOW
    bitCnt = 0 'Initialize the bits counter
    CompVal = &h80 'Initialize the MASK
    do until bitCnt = 8 '1 byte has 8 bits...
    io.num = SDA 'Select SDA line
    BitData = vData AND CompVal 'Define the state of the bit(MSB-->LSB)
    if(BitData) then
    io.state = HIGH 'Bit is 1
    else
    io.state = LOW 'Bit is 0
    end if
    io.num = SCL 'Write the bit to I2C device
    io.state = HIGH
    io.state = LOW
    bitCnt = BitCnt + 1 'Increment bit counter(next bit)
    CompVal = CompVal / 2 'Move the comparision to the next bit(MSB-->LSB)
    loop
    io.num = SDA 'Emulate the ACK frame
    io.state = HIGH
    io.num = SCL
    io.state = HIGH
    io.state = LOW

    end sub
    '******************************************************************************
    'I2C Get char function
    '******************************************************************************
    function I2C_getc as byte

    dim bitCnt as byte 'Bit counter
    dim CompVal as byte 'Value to compare - MASK

    io.num = SCL 'Initialize the reception
    io.state = LOW
    io.num = SDA
    io.state = HIGH
    bitCnt = 0 'Initialize the bits counter
    CompVal = &h80 'Initialize the MASK
    I2C_Getc = 0 'Initialize the received data
    do until bitCnt = 8 '1 byte has 8 bits...
    io.num = SCL
    io.state = HIGH 'Read one bit from I2C device
    io.num = SDA
    if(io.state = HIGH) then 'Devine the state of the bit
    I2C_Getc = I2C_Getc OR CompVal 'Store the value of the bit
    end if
    bitCnt = bitCnt + 1 'Increment bit counter(next bit)
    CompVal = CompVal / 2 'Move the comparision to the next bit(MSB-->LSB)
    io.num = SCL
    io.state = LOW 'Clear the clock line (the data can change now...)
    loop

    end function
    '******************************************************************************
    'I2C Start frame
    '******************************************************************************
    sub I2C_Start

    io.num = SCL
    io.state = HIGH 'Set SCL line
    io.num = SDA
    io.state = HIGH 'Set SDA line
    io.state = LOW 'Clear SDA line
    io.num = SCL
    io.state = LOW 'Clear SCL line

    end sub
    '******************************************************************************
    'I2C Stop frame
    '******************************************************************************
    sub I2C_Stop

    io.num = SDA
    io.state = LOW 'Clear SDA line
    io.num = SCL
    io.state = HIGH 'Set SCL line
    io.num = SDA
    io.state = HIGH 'Set SDA line
    io.num = SCL
    io.state = HIGH 'Set SCL line

    end sub
    '******************************************************************************
    'I2C ACK frame
    '******************************************************************************
    sub I2C_Ack

    io.num = SCL
    io.state = LOW 'Clear SCL line
    io.num = SDA
    io.state = LOW 'Clear SDA line
    io.num = SCL
    io.state = HIGH 'Set SCL line
    io.state = LOW 'Clear SCL line

    end sub
    '******************************************************************************
    'I2C NACK frame
    '******************************************************************************
    sub I2C_Nack

    io.num = SCL
    io.state = LOW 'Clear SCL line
    io.num = SDA
    io.state = HIGH 'Set SDA line
    io.num = SCL
    io.state = HIGH 'Set SCL line
    io.state = LOW 'Clear SCL line

    end sub

  • question

    markb asked a question in Tibbo on August 29, 2008 10:53:

    markb
    talk to I2C device
    Hi All,
    How can I communictae with an I2C (or Dallas 2-wire) device?
    I want to use a real-time clock chip in my design, but how to 'talk' to it?
    TIA<
    Mark
  • question

    markb asked a question in Tibbo on August 29, 2008 10:52:

    markb
    talk to I2C device
    Hi All,
    How can I communictae with an I2C (or Dallas 2-wire) device?
    I want to use a real-time clock chip in my design, but how to 'talk' to it?
    TIA<
    Mark
  • question

    ezuk replied on April 13, 2008 08:35 to the question "When will documentation be ready?" in Tibbo:

    ezuk
    I do apologize for the delay with the docs. I asked our engineers again. We hope to get it done as soon as possible, but I still cannot commit to any definite deadline.

    We are very aware of this problem, and are working hard to fix it. Sorry.
  • question

    markb asked a question in Tibbo on April 11, 2008 00:11:

    markb
    When will documentation be ready?
    When will there be complete information about the fd, kb and LCD objects? Without data, hardware connections etc, these things may as well not exist, as we cannot use them.