Active TopicsActive Topics  Display List of Forum MembersMemberlist  Search The ForumSearch  HelpHelp
  RegisterRegister  LoginLogin
PowerHome Programming
 PowerHome Messageboard : PowerHome Programming
Subject Topic: RS-232 and PH Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
RWCS
Senior Member
Senior Member
Avatar

Joined: October 28 2002
Location: United States
Online Status: Offline
Posts: 102
Posted: January 13 2009 at 21:25 | IP Logged Quote RWCS

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 View RWCS's Profile Search for other posts by RWCS Visit RWCS's Homepage
 
RWCS
Senior Member
Senior Member
Avatar

Joined: October 28 2002
Location: United States
Online Status: Offline
Posts: 102
Posted: January 21 2009 at 09:13 | IP Logged Quote RWCS

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 View RWCS's Profile Search for other posts by RWCS Visit RWCS's Homepage
 
BeachBum
Super User
Super User
Avatar

Joined: April 11 2007
Location: United States
Online Status: Offline
Posts: 1880
Posted: January 21 2009 at 09:24 | IP Logged Quote BeachBum

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 View BeachBum's Profile Search for other posts by BeachBum
 
RWCS
Senior Member
Senior Member
Avatar

Joined: October 28 2002
Location: United States
Online Status: Offline
Posts: 102
Posted: January 21 2009 at 09:34 | IP Logged Quote RWCS

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 View RWCS's Profile Search for other posts by RWCS Visit RWCS's Homepage
 
BeachBum
Super User
Super User
Avatar

Joined: April 11 2007
Location: United States
Online Status: Offline
Posts: 1880
Posted: January 21 2009 at 10:15 | IP Logged Quote BeachBum

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 View BeachBum's Profile Search for other posts by BeachBum
 
RWCS
Senior Member
Senior Member
Avatar

Joined: October 28 2002
Location: United States
Online Status: Offline
Posts: 102
Posted: January 21 2009 at 11:24 | IP Logged Quote RWCS

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 View RWCS's Profile Search for other posts by RWCS Visit RWCS's Homepage
 
BeachBum
Super User
Super User
Avatar

Joined: April 11 2007
Location: United States
Online Status: Offline
Posts: 1880
Posted: January 21 2009 at 11:57 | IP Logged Quote BeachBum

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 View BeachBum's Profile Search for other posts by BeachBum
 
RWCS
Senior Member
Senior Member
Avatar

Joined: October 28 2002
Location: United States
Online Status: Offline
Posts: 102
Posted: January 21 2009 at 13:20 | IP Logged Quote RWCS

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 View RWCS's Profile Search for other posts by RWCS Visit RWCS's Homepage
 
BeachBum
Super User
Super User
Avatar

Joined: April 11 2007
Location: United States
Online Status: Offline
Posts: 1880
Posted: January 21 2009 at 13:48 | IP Logged Quote BeachBum

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 View BeachBum's Profile Search for other posts by BeachBum
 
TonyNo
Moderator Group
Moderator Group
Avatar

Joined: December 05 2001
Location: United States
Online Status: Offline
Posts: 2889
Posted: January 21 2009 at 14:08 | IP Logged Quote TonyNo

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 View TonyNo's Profile Search for other posts by TonyNo Visit TonyNo's Homepage
 
RWCS
Senior Member
Senior Member
Avatar

Joined: October 28 2002
Location: United States
Online Status: Offline
Posts: 102
Posted: January 21 2009 at 14:17 | IP Logged Quote RWCS

OK you are right it does work, I'll apologize for my lack of observational skills. . . Thanks
Back to Top View RWCS's Profile Search for other posts by RWCS Visit RWCS's Homepage
 
RWCS
Senior Member
Senior Member
Avatar

Joined: October 28 2002
Location: United States
Online Status: Offline
Posts: 102
Posted: January 21 2009 at 15:57 | IP Logged Quote RWCS

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 View RWCS's Profile Search for other posts by RWCS Visit RWCS's Homepage
 

If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Post ReplyPost New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum