Aller au contenu

La communication vers un ordinateur en RS232

    Pour envoyer une variable (8bits) entre un ordinateur et une Basic Stamp, via RS323, utilisant COM – porte série ou USB convertisseur. RS232 est un protocole asynchrone (comme MIDI RS485 et TCP-IP). Chaque côté à son propre horloge pour compter les un et les zéros.

    Du côté PC et Basic Stamp, il faut délimiter la vitesse de la communication (en anglais dit ‘baud rate’). On utilise le standard: 9600 bits /second 8-bit no-parity inverted. (en langage PBasic 9600 bits/sec = 16468). Page 279 du guide. C’est une vitesse d’environ 8 bits (ou la lettre “A”) par milliseconde.

    DB9LE PBASIC:

    ‘POUR TRANSMET UNE VALEUR AU PC: dans ce code PIN 1 est connecté au TX ‘du connecteur DB9

    ………OUTPUT 1

    ………main: ‘label
    ………SEROUT 1, 16468, [“salut”] ‘envoyer une byte
    ………goto main

    ‘POUR LIRE UNE VALEUR VENANT DU PC: dans ce code PIN 0 est connecté au RX du connecteur DB9

    ………INPUT 0
    ………switch var byte

    ………switch = 255

    ………main:
    ………SERIN 0,16468, [switch] ………goto main

    Le PC peut lire la donnée depuis Macromedia Director et le Serial Xtra de Geoff Smith, MAX MSP ou Pure Data.

    LINGO EXEMPLE CODE:

    __moviescript__

    global theXtra, theXtraName, theXtraFilename

    on startmovie
    –SEE SAMPLE MOVIE AT PHYSCIAL BITS TO GET A LICENSE OR DEMO VERSION
    end

    on LoadXtraFileIfNecessary
    if scanXtraList() = false then
    if the platform contains “Macintosh” then
    if ( getProp(the environment, #osVersion) contains “10.” ) then
    set theXtraFilename to theXtraName&”.osx”
    else
    set theXtraFilename to theXtraName&”.os9″
    end if
    else
    set theXtraFilename to theXtraName&”.x32″
    end if
    — So it is not open
    openxlib the pathname&theXtraFilename
    end if
    end

    on openThePort
    global theports, keyspan
    theports = string(FindPorts())
    keyspanstart = offset(“/dev/cu.USA19Q”, theports) –USA19
    keyspanend = offset(“1.1”, theports)
    keyspan = chars(theports, keyspanstart, keyspanend +2)
    theXtra.OpenPort(keyspan)
    theXtra.setProtocol(9600, “n”, 8, 1)
    end

    on stopMovie
    if objectP( theXtra ) then
    theXtra.ClosePort()
    set theXtra to 0
    end if
    closexlib
    clearglobals
    end

    __passthroughframescript__

    global theXtra

    on exitFrame me
    if theXtra.IsPortOpen() = 0 then openThePort
    if theXtra.IsPortOpen() = 1 then go the frame + 1
    end

    __exitframescript__

    global theXtra, prox

    on exitframe
    readStamp
    go the frame
    end

    on ReadStamp
    if theXtra.CharsAvailable( ) > 0 then
    prox = theXtra.ReadNumber()
    end if
    end

    Source: hehe.org.free.fr | CC

    Ne restez pas à la traîne des dernières tendances technologiques !
    This is default text for notification bar