Home AMX User Forum NetLinx Studio
Options

One way rs-232, How do I do it?

I have done programming for 2 way rs232. I find that pretty simple. But I hope someone can point me in the right direction to be able to capture data from a test instrument. This instrument only sends one way and continuously. How do I know when to capture good data from the serial buffer and then clear it ?

I realize this may sound like a rather beginner type question, but I have just never had to do this and cannot think of a way. No doubt the answer is simple and I will kick myself. Please, someone let me know how to do this so I can kick myself.

Michael

Comments

  • Options
    AMXJeffAMXJeff Posts: 450
    Parsing data from a device is almost like an art. Unfortunately, the people in this forum will need to know the model number and manufacture of the device you want to capture its data. Part of the parsing of the data is looking for markers in the protocol. Please submit either the protocol documents or Manu/model number information. I am sure you will have an influx of helpers!
  • Options
    micodermicoder Posts: 36
    rs-232 one way

    Thanks for the quick reply Jeff,
    Here is the protocol The instrument is the Sper Scientific 850081 water quality meter.

    The 16 digits data stream will be displayed in the following format:

    D15 D14 D13 D12 D11 D10 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0
    Each digit indicates the following status:
    D0 End Word
    D1 & D8 Display reading, Dl = LSD, D8 = MSD
    E.g: If the display reading is 1234, then 08 to Ohs: 00001234
    D9 Decimal Point (DP), position from right to the left
    0 = No DP, 1= 1 DP, 2 = 2 DP, 3 = 3 DP
    D10 Polarity: 0 = Positive 1 = Negative
    D11 & D12 Annunciator for Display
    ?C=O1 ?F=02
    mV=18 mS=14
    0-6F1 = 06 mg/L = 07
    D13 The upper display data = 1, The lower display data = 2
    D14 4
    D15 Start Word
    RS232 FORMAT: 9600, N, 8, 1
  • Options
    jweatherjweather Posts: 320
    Assuming D0 is always the same value, and doesn't appear anywhere else in the message, you can use it as a delimiter to grab complete messages by using REMOVE_STRING and passing the value of D0 as the delimiter.

    You might also want to hook up the device and look at what it's sending to make sure that it matches the manual... not that anyone would ever write an inaccurate protocol manual. :)
  • Options
    micodermicoder Posts: 36
    delimiter

    Jweather,
    Thanks for the reply. I do not have as much as experience as do you. Could you give me a sample of code that you would use to try and snatch the good stuff?

    I realize it would not be a final product by any means, but it would sure be starting point for me.

    Thanks

    Michael
  • Options
    jweatherjweather Posts: 320
    Assuming you have a fixed delimiter you can use, call it $FF, I would use code like the following:
    DEFINE_VARIABLE
    VOLATILE CHAR buf[50]
    
    DEFINE_EVENT
    DATA_EVENT [dv] {
        STRING: {
    	STACK_VAR CHAR msg[16]
    
    	buf = "buf,DATA.TEXT" // add new data to end of buffer
    	
    	while (true) {
    	    msg = REMOVE_STRING(buf, "$FF", 1) // remove a block ending in $FF
    	    if (LENGTH_STRING(msg) == 0) break; // no block returned
        
    	    SEND_STRING 0, "'data from event: ', msg"
    	}
        }
    }
    

    I would need to see more of the protocol manual to figure out whether D0 is actually a fixed value or not.
  • Options
    The manual or the manufacturer should explain somewhere what the values for "Start Word" and "End Word" are. You'll need those to identify where the start and end of data coming into your program are...

    - Chip
  • Options
    mpullinmpullin Posts: 949
    change topic name?

    Could we change the name of this topic to "How to read RS232 Buffer" or something? When I read "One Way RS-232" I think of SENDING one-way RS232, which is a hardware issue (and not something this topic tells us how to do), as opposed to this which is a programming issue.
  • Options
    jjamesjjames Posts: 2,908
    Read this....
    http://amx.com/techsupport/techNote.asp?id=616

    This is how I parse / buffer incoming strings. I use code example two in that tech note.
  • Options
    micodermicoder Posts: 36
    Is this Netlinx?

    I just received the device and went to start programming. I went to my Axcess Programming Guide, and could find neither DEFINE_EVENT, STACK_VAR or DEFINE_DATA. I am programming for an older AXF-BP card frame. I am assuming at this point that these are newer commands for the newer products. Is it possible to parse one way received rs232 in Axcess?
    jweather wrote: »
    Assuming you have a fixed delimiter you can use, call it $FF, I would use code like the following:
    DEFINE_VARIABLE
    VOLATILE CHAR buf[50]
    
    DEFINE_EVENT
    DATA_EVENT [dv] {
        STRING: {
    	STACK_VAR CHAR msg[16]
    
    	buf = "buf,DATA.TEXT" // add new data to end of buffer
    	
    	while (true) {
    	    msg = REMOVE_STRING(buf, "$FF", 1) // remove a block ending in $FF
    	    if (LENGTH_STRING(msg) == 0) break; // no block returned
        
    	    SEND_STRING 0, "'data from event: ', msg"
    	}
        }
    }
    

    I would need to see more of the protocol manual to figure out whether D0 is actually a fixed value or not.
  • Options
    AXF-BP is the card frame for Axcess Control processors. This card frame would be populated with a AXC-EM which is the Axcess Master. There is a server card that I think is called AXC-SPE. This card would allow you to have multiple card frames with 1 master card in the first card frame.

    All of this is to say that Axcess systems are not event driven so all you would have is DEFINE_PROGRAM and not DEFINE_EVENT. To parse incoming strings in an Axcess system, you would use CREATE_BUFFER then in the DEFINE_PROGRAM area have a conditional statement that would for example parse the buffer if there is string length and if the end delimiter is found. Keep in mind that these buffers can overflow and you must program a solution to periodically clear the buffer.
  • Options
    DHawthorneDHawthorne Posts: 4,584
    kbeattyAMX wrote: »
    All of this is to say that Axcess systems are not event driven so all you would have is DEFINE_PROGRAM and not DEFINE_EVENT. To parse incoming strings in an Axcess system, you would use CREATE_BUFFER then in the DEFINE_PROGRAM area have a conditional statement that would for example parse the buffer if there is string length and if the end delimiter is found. Keep in mind that these buffers can overflow and you must program a solution to periodically clear the buffer.

    Not to nit-pick too much, but that is a misleading statement - Axcent is just as event-driven as NetLinx, it's just a different syntax. A PUSH statement within DEFINE_PROGRAM is the event handler that looks for a button press; in NetLinx it is just separated out to a BUTTON_EVENT. But either way, nothing happens until the programed event (a button press, or whatever) is seen, and either way, every pass through mainline, the master is looking for that event. More is done under-the-hood in NetLinx, but much of the same stuff is going on.
  • Options
    AXCESS communication updates occur only between passes through mainline (or after each iteration through LONG_WHILE loops). This places timing constraints on mainline processing in order for the system to operate properly. NetLinx avoids these constraints by processing network activity through a separate thread of execution. Bus activity is serviced concurrently with event processing and mainline execution.

    The event processing that previously could occur only through mainline code can now be handled through code in the DEFINE_EVENT section. This provides a more efficient mechanism for processing events in that mainline does not have to be traversed to process a single I/O request. A handler can be defined for processing device-specific events as well as providing feedback for the device initiating the event notification. If a handler is present, mainline will not be called to process the event; the handler is called instead. Once the handler completes its execution, the system is ready to process the next input message. When no more messages are pending, mainline is run. In effect, mainline becomes an idle time process.

    While pushes are events, they are not handled independently. The way it's handled in Netlinx is much more than just syntax.
  • Options
    micodermicoder Posts: 36
    1 way rs232

    Thanks,

    I have used bi-directional rs232 for a long time and am quite comfortable doing something simple like that. However, now it looks like I will need to look for the delimiter. I realize I will have to clear the buffer, but knowing when to do that is something I will need to experiment with.

    I appreciate the help. I was never a wiz bang programmer with Axcess but I always got the job done and working reliably. I did not learn Axcess until I was in my 50s. I never used a subroutine and always put comments on almost everything I did. This allowed me to go back and easily change something. This often meant that I wrote the same code twice or three times in places. However, this also allowed my old brain to easily see what was happening. Nobody ever cared what the code in my presentation rooms looked like. They cared if it worked well and reliably.

    Thanks again

    kbeattyAMX wrote: »
    AXF-BP is the card frame for Axcess Control processors. This card frame would be populated with a AXC-EM which is the Axcess Master. There is a server card that I think is called AXC-SPE. This card would allow you to have multiple card frames with 1 master card in the first card frame.

    All of this is to say that Axcess systems are not event driven so all you would have is DEFINE_PROGRAM and not DEFINE_EVENT. To parse incoming strings in an Axcess system, you would use CREATE_BUFFER then in the DEFINE_PROGRAM area have a conditional statement that would for example parse the buffer if there is string length and if the end delimiter is found. Keep in mind that these buffers can overflow and you must program a solution to periodically clear the buffer.
  • Options
    micodermicoder Posts: 36
    receiving one way rs232

    Is there anyone out there that could post some sample code as a starting place for me to try and receive data? I am using axcess. Thanks in advance for any help.

    Michael
  • Options
    micodermicoder Posts: 36
    receiving one way rs232

    I have tried something to accomplish this. I decided to try measuring the number of bytes of the information. Each send has the same number of bytes.

    I did did this:
    Y = LENGTH_STRING (TENMABUFFER)
    IF (Y) >= 28
    {
    VOMTEMP = LEFT_STRING (TENMABUFFER,28)
    CLEAR_BUFFER TENMABUFFER
    SEND_COMMAND TP,"'TEXT1-',(VOMTEMP),"

    This seems to be getting me the information. Does anyone see a problem with this method? I am a little worried that when I put together the rest of the program, it will take to long per pass and miss the length. I thought about inserting this periodically through the program.

    Michael
  • Options
    You really need to know what D0 is and what D15 is..

    Assuming D15 is $02 and D0 is $03

    Then you do this
    If (length_string(buffer))
    {
      trash = remove_string(buffer,"$02",1)
      incoming = remove_string(buffer,"$03",1)
      if (length_string(incoming) = 15)
      {
        //process for TP display
      }
      else 
      {
        if (length_string(buffer) > 500)) set_length_string(buffer,0)
      }
    }
    

    I don't think you'll have to worry about buffer overflow if all responses begin with $02.
  • Options
    micodermicoder Posts: 36
    one way rs232

    Thank you kbeatty
    This sample of code will be very helpful for me.

    Michael
Sign In or Register to comment.