Home AMX User Forum NetLinx Studio

baud rate quistion

I want to change the baud rate of port 2 (the rs-232) of the AMX device to 2400 how can I do that?

Comments

  • ericmedleyericmedley Posts: 4,177
    udi wrote: »
    I want to change the baud rate of port 2 (the rs-232) of the AMX device to 2400 how can I do that?

    check the documentation for your device. You just need to send a command to the port to make the change.
  • HedbergHedberg Posts: 671
    That's correct, look in the documentation. There's all sorts of good stuff in there -- answers to questions you didn't even know to ask.

    But, here's how to find out what the setting currently is:

    send_command 5001:2:0,'GET BAUD'

    See the result in diagnostic notifications.

    then:

    send_command 5001:2:0,'SET BAUD 2400'

    will change it.
  • udiudi Posts: 107
    I tryied it but it didnt work the boud rate of the device is 2400 how can i change the port 2 of the amx to 2400
  • But Hedberg is correct: SEND_COMMAND 5001:2:0,'SET BAUD 2400'
    or the full configuration:
    SEND_COMMAND 5001:2:0,'SET BAUD 2400,N,8,1 485 DISABLE'

    It is important to do this command in the DATA_EVNT..ONLINE of the port, like
    DEFINE_DEVICE
    dvSerial2 = 5001:2:0

    DEFINE_EVENT
    DATA_EVENT[dvSerial2]
    {
    ONLINE:
    {
    SEND_COMMAND dvSerial2,'SET BAUD 2400,N,8,1 485 DISABLE' // 2400 bau, no parity, 8 databits, 1 StoppBit
    SEND_COMMAND dvSerial2,'XOFF' // software handshake off
    SEND_COMMAND dvSerial2,'HSOFF' // hardware handshake off
    SEND_COMMAND dvSerial2,'CHARD-0' // no character delay
    }
    }
  • HedbergHedberg Posts: 671
    udi wrote: »
    I tryied it but it didnt work the boud rate of the device is 2400 how can i change the port 2 of the amx to 2400

    Send the 'SET BAUD' command to the device in question. You need to know what device that is. If it's a Netlinx box, the second serial port is most likely 5001:1:0. If it's an Axcent3 box, it's probably 2. If it's an Axcent box slaved to a Netlinx, or any other configuration other than the second serial port on a stand alone integrated master, you need to figure out how to address the port.

    In any event, get the documentation for whatever device you have and read the part about programming the serial ports and all the details of 'SET BAUD' will be revealed.
  • udiudi Posts: 107
    I have an NI-3100 device and I connected an PIMA alarm device I change the coonection to port 3 of RS-232 and I wrote the code you said in the data event and it works. but I am not
    thank for your help. I did the command but I am not getting exactly the hex code I need to get.
    I get the code:

    Line 4 (10:25:11):: String From [5001:3:1]-[$08$0D$05$00$00$00$00$124.$FE]


    But the HEX code I need to get is :

    [$08$0D$05$00$00$00$00$12$34$2E$FE]

    What is the problem why I don’t get the end of the code correctly?

    In addition I have another problem. I need to calculate the CRC and I found a code in the forum but I don’t know if I do the correct thing. I need to add the calculate I get into the end of the string and then sending it to the device.
    I tried for exanple the command:



    SEND_STRING dvSerial3,"'$0A$0D$0F$04$00$03$00$01$01$FF$FF',(crc16('$0A$0D$0F$04$00$03$00$01$01$FF$FF'))"

    SEND_STRING dvSerial3,"'$0A$0D$0F$04$00$03$00$01$01$FF$FF',(fuCrcCalc('$0A$0D$0F$04$00$03$00$01$01$FF$FF'))"


    I tried the two functions that appear in the forum:
    http://www.amxforums.com/showthread.php?4849-Help-with-quot-Pima-quot-Alarm-System-CRC&highlight=PIMA


    but each gives me different result and it dosent sent the string correct

    //the crc16 function
    Line 14 (10:25:27):: String To [5001:3:1]-[$0A$0D$0F$04$00$03$00$01$01$FF$FFo$E4]
    //the fuCrcCalc function
    Line 15 (10:25:27):: String To [5001:3:1]-[$0A$0D$0F$04$00$03$00$01$01$FF$FF6F]

    They don’t sent the command in hex in the end. How do I need to do that?
    I want to send the command in HEX is the command correct?
    I added my code file the functions is in the code.
    Thanks for any help that leads me in the right direction. Examples are very much appreciated
  • udiudi Posts: 107
    in the fuCrcCalc function I get an E4 in the return is this a CRCH or CRCL and I need to enter the other CRC(H or L).
    how can I do that?
  • The "String From" will show any displayable hex value as ASCII character, any non-displayable character is shown as $xx
    [$08$0D$05$00$00$00$00$12$34$2E$FE]
    Line 4 (10:25:11):: String From [5001:3:1]-[$08$0D$05$00$00$00$00$124.$FE]
    All bytes from $08 up to $12 are non-displayable, so they are shown as hex, but the "$34,$2E" are displayable ASCII, and so the notification will show them as "4.". The last byte "$FE" again is nondisplayable, and so shown as hex again.


    Regarding the crc checksum functions
    SEND_STRING dvSerial3,"'$0A$0D$0F$04$00$03$00$01$01$FF$FF',(fu CrcCalc('$0A$0D$0F$04$00$03$00$01$01$FF$FF'))"
    The string you put in to calculate the checksum is an ASCII string, including also the "$" symbols for the checksum. But the chekcsum is required to be calculated by the hex values, so the code might be
    SEND_STRING dvSerial3,"$0A,$0D,$0F,$04,$00,$03,$00,$01,$01,$FF,$FF,fuCrcCalc("$0A,$0D,$0F,$04,$00,$03,$00,$01,$01,$FF,$FF")"
  • Joe HebertJoe Hebert Posts: 2,159
    As a follow up to what Marc stated:

    If you want to all hex displayed then from the menu bar goto:

    Settings --> Preferences --> Diagnostics and then select Display as… Hex Values in the Notification View.
  • udi wrote: »
    in the fuCrcCalc function I get an E4 in the return is this a CRCH or CRCL and I need to enter the other CRC(H or L).
    how can I do that?

    Again, this may be just the display issue. This may be shown as E4 in notification, but if it has no leading $ symbol, it may be 2 byte values that can be displayed, and so in hex display, it would be "$45,$34".

    P.S.: Thank you Hedberg, I didn't know that settings option :o
  • udiudi Posts: 107
    thanks for all the help.
    I am trying to sending variable that have the string "$0A,$0D,$0F,$04,$00,$03,$00,$01,$01,$FF ,$FF" instead of sending the string itself
    For example
    SEND_STRING dvSerial3,"MSG,fuCrcCalc("MSG")"
    How can I do that?


    I tried the code:
    LOCAL_VAR MSG [1000]
    MSG = "$0A,$0D,$0F,$04,$00,$03,$00,$01,$01,$FF,$FF"

    But the MSG get the string "$0A$0D$0F$04" I changed the length to 3000 but he also get the same string.

    In addition, I want to put the data.text I get from the alarm into an array that could help me to get to the data in the array.
  • udiudi Posts: 107
    another question- How can I convert a hex number to a binary number?
  • HedbergHedberg Posts: 671
    Again, this may be just the display issue. This may be shown as E4 in notification, but if it has no leading $ symbol, it may be 2 byte values that can be displayed, and so in hex display, it would be "$45,$34".

    P.S.: Thank you Hedberg, I didn't know that settings option :o

    Thanks should go to Joe Hebert, not to me.
  • ericmedleyericmedley Posts: 4,177
    udi wrote: »
    another question- How can I convert a hex number to a binary number?

    There is not a binary integer type in Netlinx. You'll have to create a routine to convert it to a string or populate an integer array.
  • PhreaKPhreaK Posts: 966
    udi wrote: »
    another question- How can I convert a hex number to a binary number?

    Hex is binary is decimal is octal etc, same value just different representations. The NCL math library has a function for encoding an int to binary coded decimal if you're device is looking for that, or are you needing to convert it to an ASCII representation of the binary value?
  • udiudi Posts: 107
    I need to change the data text I get from the alarm to a binary for cheaking for example witch zones are open.
    for example:
    byte 28 of the frame I get from the alarm indicates the open zones status for zones 1 to 8. so if byte 28 of the data: data.text[28] = 08H that means in binary 00001000 so zone 4 is open.

    In addition, someone can help me with the string issue I wrote.
  • PhreaKPhreaK Posts: 966
    For checking the zone status you'll need to use a bitwise 'and' (&) operator. Here's a little function that should do the trick for you.
    /**
     * Extracts a boolean state value for a specific zone based on a status byte
     *
     * @param	stateByte		a single byte containing the state feedback from
     *					the alarm system
     * @param	zone			a char containing the zone of interest
     * @return				a boolean value containing the zone open state
     */
    define_function char getZoneStatus(char stateByte, char zone) {
    	return stateByte & (1 << (zone - 1))
    }
    
    This works by creating a mask using the left shift operator to move a high bit to the desired position then '&'s this against the status byte. So say you want to check if zone 3 is open: the 1 << (zone - 1) will become 1 << 2 or 0b0001 << 2 giving decimal 4 or 0b0100. The '&' will then return true if bit 3 is high in stateByte.

    As for the string issue there's a bug in NS diagnostics that will terminate outgoing string display on a null character ($00). The whole string will be going to the device, the output window just won't show it.
  • udiudi Posts: 107
    I didn't exactly understood how to do it
    if I am getting $14 from the device, so the binary is "00010100" and I want to check if zone 3 is open so I need to do:

    if(getZoneStatus($14,3))
    {
    //////DO SOMETHING IF TRUE
    }

    ELSE
    {
    //////DO SOMETHING IF TRUE
    }
  • ppdkppdk Posts: 31
    using Kim's (PhreaK) function and a piece of code from a previous post of yours here is how to get the
    status of the 3rd bit of the 28th byte of the device response:

    if(getZoneStatus(data.text[28],3))
    {
    //DO SOMETHING IF TRUE
    }
    ELSE
    {
    //DO SOMETHING IF FALSE
    }
  • PhreaKPhreaK Posts: 966
    ^ what he said.
  • udiudi Posts: 107
    thanks I did it and it works great.
    now what about my other question. can anyone help me? Examples are very much appreciated .
    udi wrote: »
    I am trying to sending variable that have the string "$0A,$0D,$0F,$04,$00,$03,$00,$01,$01,$FF ,$FF" instead of sending the string itself
    For example
    SEND_STRING dvSerial3,"MSG,fuCrcCalc("MSG")"
    How can I do that?


    I tried the code:
    LOCAL_VAR MSG [1000]
    MSG = "$0A,$0D,$0F,$04,$00,$03,$00,$01,$01,$FF,$FF"

    But the MSG get the string "$0A$0D$0F$04" I changed the length to 3000 but he also get the same string.
  • PhreaKPhreaK Posts: 966
    PhreaK wrote: »
    As for the string issue there's a bug in NS diagnostics that will terminate outgoing string display on a null character ($00). The whole string will be going to the device, the output window just won't show it.

    See my previous post ^^
  • udiudi Posts: 107
    So this mean I'm doing the right commands.
    LOCAL_VAR MSG [1000]
    MSG = "$0A,$0D,$0F,$04,$00,$03,$00,$01,$01,$FF,$FF"
    SEND_STRING dvSerial3,"MSG,fuCrcCalc("MSG")"

    how can I know what size the array should be?
  • ericmedleyericmedley Posts: 4,177
    udi wrote: »
    So this mean I'm doing the right commands.
    LOCAL_VAR MSG [1000]
    MSG = "$0A,$0D,$0F,$04,$00,$03,$00,$01,$01,$FF,$FF"
    SEND_STRING dvSerial3,"MSG,fuCrcCalc("MSG")"

    how can I know what size the array should be?

    'should be'??? well, length_string(MSG) will return an integer value of the current length of the array. In the example you gave, it will be 11.
Sign In or Register to comment.