One way rs-232, How do I do it?
micoder
Posts: 36
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
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
0
Comments
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
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.
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
I would need to see more of the protocol manual to figure out whether D0 is actually a fixed value or not.
- Chip
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.
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.
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?
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.
While pushes are events, they are not handled independently. The way it's handled in Netlinx is much more than just syntax.
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
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
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
Assuming D15 is $02 and D0 is $03
Then you do this
I don't think you'll have to worry about buffer overflow if all responses begin with $02.
Thank you kbeatty
This sample of code will be very helpful for me.
Michael