Home AMX User Forum AMXForums Archive Threads AMX Applications and Solutions

First time RS232

Hi there,
it's me again! First of all i would really like to thank those who answered my previous threads...you guys gave me great hints!

Now i'm facing for the first time a serial communication with a PLASMA device ( a philips BDS4241V00).
Well, i've got the protol but many many doubts!

Just an example of the protocol:

1. Mute : m (0x6d)
-Read Mute Status
(1) Transmission
[0x57][m][ ][ Display ID][ ][0xFF][CR][LF]
(2) OK Ack
[Data]
Data = 0(00h) : Off Status
Data = 1(01h) : On Status
(3) Error Ack
[0x15]

ok. Clear and simple.
I have to:
SEND_STRING PLASMA1,"$57,$6D,$20,$01,$20,$FF,$0D,$0A"

all the other commands are quite the same. The problem is: how do i ditinguish the answer if all the commands sends back ACK + some data?
I thought to store in a variable what command i've just sent but who grants me that the device answers syncronously?

Hope i've been clear enough

Tks everyone

Comments

  • Spire_JeffSpire_Jeff Posts: 1,917
    If the protocol for the plasma indicates that it responds to all commands with a reply, you could build a queue to hold commands to be sent.

    You have to write code to insert commands from your code into a queue. You also have to write code to handle the actual communication with the device. This Comm code will take the first command from the queue and send it to the plasma. The code waits a set amount of time for a response. If a response is received, it deals with the response accordingly (if the response was bad command, the comm code resends the command up to X number of times before reporting an error and so on). Once the comm code is satisified that the command was sent and dealt with properly, it removes it from the queue and proceeds to send the next command in the queue. If no response is received within the time out period, the comm code should resend the command X number of times before reporting an error.

    This is the basic framework I use when creating a 2way serial comm module.

    Jeff

    P.S.
    I think I covered everything, but I'm in the middle of troubleshooting and I am sure that some of the others on the board will point out any ommisions I have made :)
  • lattanzilattanzi Posts: 22
    sounds interesting

    Where am i supposed to manage the queue? In define_program section?
    I'm thinking of an array of, say, 10 elements through which the program loops, if it's not empty, and a variable to store the result of the command to be set inside a data_event.

    Will you post some code, please?

    tks!
  • Spire_JeffSpire_Jeff Posts: 1,917
    You have to create a queue. I normally create something like:
    DEFINE_CONSTANT
    INTEGER MAX_CMD_LENGTH = 100
    QUEUE_SIZE = 50
    
    DEFINE_VARIABLE
    INTEGER nCUR_CMD
    INTEGER nCUR_QUEUE_INSERTION
    CHAR [QUEUE_SIZE][MAX_CMD_LENGTH]
    
    


    Basically you increment the nCUR_QUEUE_INSERTION as you insert commands. Once it is greater than QUEUE_SIZE, you start it back at 1. It should never be allowed to change to be equal CUR_CMD (that means queue is full).

    Same concept with nCUR_CMD. You increment it as you send commands. When nCUR_CMD equals nCUR_QUEUE_INSERTION, you have processed all of the commands in the queue.

    Hope this helps.

    Jeff

    P.S.
    If this seems a little complicated, you might try hiring one of the independant programmers around to write the module for you and see if they will let you see the final source code as a learning tool.
Sign In or Register to comment.