Home AMX User Forum NetLinx Studio

SEND_STRING - Default CR?

Does SEND_STRING send a CR at the end of a command that you send to a device, by chance? I currently have all of my commands with the CR specified which I then pass to the device via SEND_STRING. Just want to make sure it's not assumed that the command will do this.

Cheers,
Matthew

Comments

  • ericmedleyericmedley Posts: 4,177
    Does SEND_STRING send a CR at the end of a command that you send to a device, by chance? I currently have all of my commands with the CR specified which I then pass to the device via SEND_STRING. Just want to make sure it's not assumed that the command will do this.

    Cheers,
    Matthew

    no, you must send it manually yourself.

    it looks like

    SEND_STRING dv_My_Serial_port , " 'a command string',$0D,$0A" // $D for <CR> and $A or <LF>
  • That's what I figured although I ran across some code which was taking a command which had a CR at the end of it, was getting the length of that string and then setting the length of the array to the string length - 1...see below for example:
    STACK_VAR CHAR cCommand[20];
    
    cCommand = REMOVE_STRING(cDeviceQueue,"CR",1);
    SET_LENGTH_STRING(cCommand, LENGTH_STRING(cCommand) - 1);
    
    SEND_STRING dvDevice, "cCommand";
    

    I'm guessing that the device in question does not need a CR terminator in this case and they're just using it to the delimit commands in the queue?

    Cheers,
    Matthew
  • ericmedleyericmedley Posts: 4,177
    That's what I figured although I ran across some code which was taking a command which had a CR at the end of it, was getting the length of that string and then setting the length of the array to the string length - 1...see below for example:
    STACK_VAR CHAR cCommand[20];
    
    cCommand = REMOVE_STRING(cDeviceQueue,"CR",1);
    SET_LENGTH_STRING(cCommand, LENGTH_STRING(cCommand) - 1);
    
    SEND_STRING dvDevice, "cCommand";
    

    I'm guessing that the device in question does not need a CR terminator in this case and they're just using it to the delimit commands in the queue?

    Cheers,
    Matthew

    Hmmm... it's hard to say without the rest of the code.

    I assume that somewhere in the code the variable/constant CR is set to $0D
  • I'm guessing that the device in question does not need a CR terminator in this case and they're just using it to the delimit commands in the queue?
    Like Eric said, it's difficult to say without the code but what you just mentioned sounds correct. When you're using virtual devices in a module most of us use send_command to send information to the module, and send_string when returning information from the module or sending control strings to an actual device. For instance if you take button press 1 on device 10001:1:1 and want to send 'PLAY' to a module which in turn would parse what you sent and send a properly formatted command to the actual device it would look like this:
    DEFINE_DEVICE
    dvTP		= 10001:1:1
    vdvDevice	= 33001:1:0
    
    DEFINE_EVENT
    
    BUTTON_EVENT [dvTP,1]
    {
      PUSH:
      {
    	 SEND_COMMAND vdvDevice, "'PLAY', $0D"
      }
    }
    

    On the other end you would have something like this:
    DATA_EVENT [vdvDevice] //COMMAND STRINGS RECEIVED FROM UI MODULE OR .AXS MAIN
    {
      COMMAND:
      {
    	 sQUEUE="sQUEUE,DATA.TEXT"
    	 IF (FIND_STRING(sQUEUE,"$0D",1))	// $0D is the delimiter for this message
    	 {
    		sCMD = REMOVE_STRING("sQUEUE","$0D",1)
                   SET_LENGTH_STRING(sCMD, LENGTH_STRING(sCMD) - 1);
    		SEND_STRING dvActualDevice "$21,sCMD"  //Re-formats the string being sent to the actual device with $21 as the STX
    	 }
      }
    }
    

    The $0D would act as a delimiter for the module to parse what you sent it which is what it looks like you're seeing in the code you posted. My above code is just a crude example.

    --John
  • Yep...this is pretty much how it's working. The virtual is looking for the delimiter to snag the command and then adding the command to the queue. The code I included was where the queue then executes the command against the device which is expecting the carriage return. I'm pretty sure then that I need to make sure that CR($0D) is not left out with the SET_LENGTH_STRING statement.

    Thanks for the help, guys. I know I've had a ton of questions over the last week...just trying to make sure I don't get bitten by any peculiarities.

    Cheers,
    Matthew
  • Eric, you are correct...I guess I said this in the previous post but the CR is a $0D. I think I'm comfortable with leaving it in because the device specifies it needs the CR as a command terminator.

    Cheers,
    Matthew
Sign In or Register to comment.