Home AMX User Forum AMX General Discussion

Relay Box Hex Codes problem

I am trying to control a Relay Box that uses 232, but I'm having a problem with sending the correct code structure, I think. The device's protocol guide shows the following settings need to be made on my controller:

Configure port as 4800 bps N-8-1.

So I've done this:
DATA_EVENT[dvRelay]  //data event for rs232 relay8net control box
{
	ONLINE:
	{
		SEND_COMMAND dvRelay, "'SET BAUD 4800,O,8,1'"
	}
For the actual command structure, the protocol guide says this:

First byte = header (40h)
Second byte = address (01h - FEh)
Third byte =
Zone number (1 ? 8) in lower nibble and
Command (3 = ON & 4 = off) in upper
Example (all 3 bytes) for module address 1:
zone1 on = 40 01 31 (hex)
zone1 off = 40 01 41 (hex)

So I read that to mean that I need to send 40 01 31 in hex to the device. Here is what I have in my button presses:
BUTTON_EVENT[dvTp,40]
{
	PUSH:
	{
		nShadeStatus = 1
		SEND_STRING dvRelay, "$40,$01,$13"  //turns relay 1 on
		Wait 5 'relay 1 on'
		SEND_STRING dvRelay, "$40,$01,$14"  //turns relay 1 off
	}
}
I don't know if it's a problem with the processor not sending commands at the right speed, or if my interpretation of how to send the codes I want is incorrect. help? Is there a place in NS3 to verify the port settings on the controller?

Comments

  • Joe HebertJoe Hebert Posts: 2,159
    vegastech wrote:
    Configure port as 4800 bps N-8-1.
    vegastech wrote:
    So I've done this:
    SEND_COMMAND dvRelay, "'SET BAUD 4800,O,8,1'"
    
    It should be:
    SEND_COMMAND dvRelay, "'SET BAUD 4800,[b]N[/b],8,1'"
    

    vegastech wrote:
    zone1 on = 40 01 31 (hex)
    zone1 off = 40 01 41 (hex)
    wrote:
    Here is what I have in my button presses
    		SEND_STRING dvRelay, "$40,$01,$13"  //turns relay 1 on
    		Wait 5 'relay 1 on'
    		SEND_STRING dvRelay, "$40,$01,$14"  //turns relay 1 off
    

    It should be:
    		SEND_STRING dvRelay, "$40,$01,[b]$31[/b]"  //turns relay 1 on
    		Wait 5 'relay 1 on'
    		SEND_STRING dvRelay, "$40,$01,[b]$41[/b]"  //turns relay 1 off
    
  • edgelitocedgelitoc Posts: 160
    You can try TELNET the master and see the response on the relay controller
  • vegastechvegastech Posts: 369
    I've gotta stop programming all day on the weekends...Gets me crosseyed. Thanks!
  • vegastech wrote: »
    Is there a place in NS3 to verify the port settings on the controller?

    You can verify port settings by enabling notifications for the device (set your notification options first.)

    Then use 'Control a Device' to send the port the GET BAUD command. The ports settings will show up in the notifications window.
  • vegastechvegastech Posts: 369
    Good to know. I have the settings correct now and I am sending commands correctly - awesome. I am, however, having some difficulty with my feedback. In my data event, I have a select...active set where I am doing a find string on my string buffer, sRelayStatus:
    DATA_EVENT[dvRelay]  //data event for rs232 relay8net control box
    {
    	ONLINE:
    	{
    		SEND_COMMAND dvRelay, "'SET BAUD 4800,N,8,1'"
    	}
    	STRING:
    	{
    		sRelayStatus = DATA.TEXT
    		
    		SELECT
    		{
    			ACTIVE(FIND_STRING(sRelayStatus, '$40,$01,$31',1)):
    			{
    				nShadeStatus = 1
    				SEND_COMMAND dvJVCLT37X898Tp, "'^TXT-46,0, Relay 1 is ON'"
    			}
    			ACTIVE(FIND_STRING(DATA.TEXT, '$40,$01,$41',1)):
    			{
    				nShadeStatus = 1
    				SEND_COMMAND dvJVCLT37X898Tp, "'^TXT-46,0, Relay 1 is OFF'"
    			}
    
    I am running into an issue where I can see the feedback response / string value of 40,1,41 (in the watch bar when I have the display type set to hex) which is the box saying that zone 1 is off, but the response is in hex, just like the commands I send. I have tried leaving the $ in place as well as removing it, but to no avail. Is this an issue of the unit sending hex back, and the find_string function not being able to search for hex? The protocol guide says this:

    The response of the Rain8 is to execute any command then send back the same three bytes as an ACK.
  • Joe HebertJoe Hebert Posts: 2,159
    vegastech wrote: »
    ACTIVE(FIND_STRING(sRelayStatus, '$40,$01,$31',1)):
    
    You need double quotes not single.
    Try this instead:
    ACTIVE(FIND_STRING(sRelayStatus, "$40,$01,$31",1)):
    
  • vegastechvegastech Posts: 369
    Seriously...I can't believe how much of a tard I'm being with this! I must have looked over the code and the protocol 50 times, and still never caught on. :( Hey, at least it works! Thanks guys!
  • vegastechvegastech Posts: 369
    Things are moving fairly smoothly...I have my relays turning off and on, feedback is good. I am using the relays to control a projector lift, which requires that the associated relay stays on for a number of seconds as it goes up or down. I want to be able to reverse the feature should someone press up or down by accident. Here is my code for the close button:
    BUTTON_EVENT[dvJVCLT37X898Tp,41]  //CLOSE
    {
    	PUSH:
    	{
    		If (nShade1Status = 1)
    			{
    				CANCEL_WAIT 'relay 1 on'
    				SEND_STRING dvRelay, "$40,$01,$41"
    				
    			}
    				
    		SEND_STRING dvRelay, "$40,$01,$32"
    		Wait 50 'relay 2 on'
    		SEND_STRING dvRelay, "$40,$01,$42"
    		
    	}
    }
    
    The problem I have is this: If the lift is going up and I press down, the open ( or up) relay opens (which is good), but the close (or down) doesn't trigger. When the IF statement is not true, each relay works as it should. Will the IF statement not work in this situation?
  • HedbergHedberg Posts: 671
    There doesn't appear to me to be anything obviously wrong with what you are doing. Does the device have a buffer? Will it handle multiple commands with no delay between them? Perhaps putting a small wait before trying to close relay #2 will work.
    BUTTON_EVENT[dvJVCLT37X898Tp,41]  //CLOSE
    {
       PUSH:
      {
         If (nShade1Status = 1)
         {
           CANCEL_WAIT 'relay 1 on'
           SEND_STRING dvRelay, "$40,$01,$41"
    				
         }
    				
         wait 2
          SEND_STRING dvRelay, "$40,$01,$32"
        Wait 52 'relay 2 on'
        SEND_STRING dvRelay, "$40,$01,$42"
    		
       }
    }
    
  • vegastechvegastech Posts: 369
    Harold, you are da man! You were right - the box just needed some time between commands. Something to pack into (for real this time) my bag of tricks!
  • HedbergHedberg Posts: 671
    You might think about a queue/timeline or holding your commands until the device responds to the previous command.
Sign In or Register to comment.