Author |
|
RWCS Senior Member
Joined: October 28 2002 Location: United States
Online Status: Offline Posts: 102
|
Posted: January 13 2009 at 21:25 | IP Logged
|
|
|
Does anyone have programming example of how one would ph-comsendstring, then receive and test the response? I would be expecting responses like "OK" or " ERR". Thanks for your help.
|
Back to Top |
|
|
RWCS Senior Member
Joined: October 28 2002 Location: United States
Online Status: Offline Posts: 102
|
Posted: January 21 2009 at 09:13 | IP Logged
|
|
|
OK the last question was too hard (or none of the readers are doing this kind of thing).
I'm stuck on reading the COM port. ph_comrecvstring wants a length. ph_combuffercount gives me that length, which I deposit into a global variable {CBUF}. I'm still getting an error on:
ph_comrecvstring ( 1, {CBUF} )
one of the things I've tried is:
ph_comrecvstring ( 1, ph_combuffercount (1) )
Any suggestions?
Bob
|
Back to Top |
|
|
BeachBum Super User
Joined: April 11 2007 Location: United States
Online Status: Offline Posts: 1880
|
Posted: January 21 2009 at 09:24 | IP Logged
|
|
|
This is a long shot but have you tried ph_comrecvstring ( 1, ph_getglobal_s(“CBUF” )). I don’t know if the global is a string or number.
__________________ Pete - X10 Oldie
|
Back to Top |
|
|
RWCS Senior Member
Joined: October 28 2002 Location: United States
Online Status: Offline Posts: 102
|
Posted: January 21 2009 at 09:34 | IP Logged
|
|
|
Thanks for the post.
For me the the conversion (or the status) from string to number and back is unclear. Looking at my Global Variable list it is unclear. They all look the same to me. So lets back up a step, when I do a SET GLOBAL, how do I control the variable type?
Bob
|
Back to Top |
|
|
BeachBum Super User
Joined: April 11 2007 Location: United States
Online Status: Offline Posts: 1880
|
Posted: January 21 2009 at 10:15 | IP Logged
|
|
|
You set the global with whatever value you are using. String are usually denoted by quotes. So a set global would be ph_setglobal_a or s depending on the type of data. Using the command in a macro Set Global could be with or without quotes. For me it’s a hit or miss until it works. I’m far from an expert. Again I try the getglobal using N or S until it works. Some require number format others string. Hope this helps…
__________________ Pete - X10 Oldie
|
Back to Top |
|
|
RWCS Senior Member
Joined: October 28 2002 Location: United States
Online Status: Offline Posts: 102
|
Posted: January 21 2009 at 11:24 | IP Logged
|
|
|
Pete
Thanks for your thoughts, I too struggle with this, and usually just keep trying until things work (sound familiar?). The other factor you failed to mention is that "" works differently than '', so I'm up to three variations to try, so when you are nesting functions the combinations seem endless.
The real mystery here is why
ph_comrecvstring ( 1, ph_combuffercount (1) )
doesn't verify (or work).
Bob
|
Back to Top |
|
|
BeachBum Super User
Joined: April 11 2007 Location: United States
Online Status: Offline Posts: 1880
|
Posted: January 21 2009 at 11:57 | IP Logged
|
|
|
When I tested ph_comrecvstring ( 1, ph_combuffercount (1) ) I get a -2 invalid com port. I assume that is not what you’re getting. I thought maybe there was an execution sequence problem but you have tried the Global approach which should eliminate it. Just a thought since you know the length have you hard coded it? ph_comrecvstring ( 1, 250 )
__________________ Pete - X10 Oldie
|
Back to Top |
|
|
RWCS Senior Member
Joined: October 28 2002 Location: United States
Online Status: Offline Posts: 102
|
Posted: January 21 2009 at 13:20 | IP Logged
|
|
|
I do have a comport open, I think I'm getting a -3. were do you get the error codes?
Responses vary in length from a simple "nak" character to an echoed back command string. Any idea what happens if you ask for more than what is there?
Edited by RWCS - January 21 2009 at 13:21
|
Back to Top |
|
|
BeachBum Super User
Joined: April 11 2007 Location: United States
Online Status: Offline Posts: 1880
|
Posted: January 21 2009 at 13:48 | IP Logged
|
|
|
The error codes are in the help menu:
Return value
String. Returns "length" characters as a string from the COM controls incoming buffer. If fewer characters are available than the length specified, then all remaining characters are returned. Returns - 1 if a comnum < 1 or > 5 is specified. Returns - 2 if the specified COM control is not valid. Returns - 3 if no characters are waiting to be read.
I would think if you ask for more than is there you might get residual. But this description may offset that thought:
ph_combuffercount PowerHome formula function
Description
Returns the total number of characters in the specified COM control's incoming buffer. The buffer is automatically reset when the bufferptr (the number of characters read from the port) = buffercount.
Tony, if you are listening your thoughts…
__________________ Pete - X10 Oldie
|
Back to Top |
|
|
TonyNo Moderator Group
Joined: December 05 2001 Location: United States
Online Status: Offline Posts: 2889
|
Posted: January 21 2009 at 14:08 | IP Logged
|
|
|
Wow. I never saw the first post here. Answering that one...
A good example of this would be my CID macro. It reads characters from the port, assembles them, and looks for various strings.
|
Back to Top |
|
|
RWCS Senior Member
Joined: October 28 2002 Location: United States
Online Status: Offline Posts: 102
|
Posted: January 21 2009 at 14:17 | IP Logged
|
|
|
OK you are right it does work, I'll apologize for my lack of observational skills. . . Thanks
|
Back to Top |
|
|
RWCS Senior Member
Joined: October 28 2002 Location: United States
Online Status: Offline Posts: 102
|
Posted: January 21 2009 at 15:57 | IP Logged
|
|
|
OK I get the CID macro thing, I think (as with many things in PH, there seems to be magic involved) as I understand your setup when the 1st character is received you start a macro. What happens to the next characters that are received which should try to start a macro that is already looping falls into the magic part. Anyway, your macro loops grabbing subsequent characters from the com port building your receive string until you get a -3 (which means empty). This assumes all characters are coming into the com port rapidly enough and the looping speed is slow enough, such that an empty buffer conditions isn't reported in mid string. How am I doing?
The reason I was looking into the com receive stuff, was I have a number of RS-232 controlled devices in my HT, and to make this work I have had to put a bunch of "delay" statements to cover the response time (none of these devices can take a command dump, all want one command at a time and then post a response) I was hoping to get a response read back system going to speed up the process. I'm having trouble with the called macro from the com port structure and how to program my needs around that. 5 commands all expecting an "OK" response which "OK" is which. . .
Bob
|
Back to Top |
|
|