How to format manufacter given command?

Posted on 2006-04-25
Last Modified: 2012-08-14
Hi, i have written an app that writes a datastring to the comm port every second. When i used the monitoring ultility provided by the multi port board appears..that the port has been successfully opened and data are transmitting. But my device don't seems to be acting upon receiving the data...... Anyway maybe i could have the datastring format screwed up.

Here's the datastring format given

<STX><POL><5 byte Ascii data><Space><PCS><CR><LF>

STX is chr(12),
POL which is either -ve or +ve...which is always chr(43) in my case
5 byte Ascii Data - i hardcoded it to be 55555
Space which is chr(32)
PCS which are 3 bytes chr(80), chr(67) and chr(83)
CR - return carriage chr(13)
LF - LineFeed chr(10)

In my code...i put it as

myValue = 55555
str_tx = chr(12) & chr(43) & myValue & chr(32) & chr(80) & chr(67) & chr(83) & _
            chr(13) & chr(10)

I am not sure if it is the way present my datastring.... By the way....if i were to type to above string using do i present it? like? STX+55555 PCS
what about the CR and LF and space character when testing it with hyperterminal?
Question by:jaxrpc
    LVL 22

    Expert Comment

    the ascii data should be "55555", not 55555.  also you can use " PCS " instead of  chr(32) & chr(80) & chr(67) & chr(83)

    You should also verify that you've set the right baud rate, stop bits, and parity.

    LVL 45

    Expert Comment

    Hi jaxrpc,

    Another point to consider -- whenever you're dealing with character data as a binary value, represent it in hex instead of decimal.  It's more universally done this way and adds a bit of readability to your code.

    Good Luck!
    LVL 17

    Accepted Solution

    Hi guys

    I haven't use C for some time.
    Has something changed in it?

    what is it?
    str_tx = chr(12) & chr(43) & myValue & chr(32) & chr(80) & chr(67) & chr(83) & _
                chr(13) & chr(10)

    I believe it should be

    unsigned char str_tx[12];
    str_tx[0] = 12;
    str_tx[1] = 43;
    and so on...
    or some other way to fill an array


    LVL 17

    Expert Comment

    to be more specific
    sprintf(str_tx,"%c%c%5d PCS\r\n",12,43,myValue);

    Author Comment

    haha sorry...i copied the code...

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    Suggested Solutions

    Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
    Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
    Video by: Grant
    The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
    The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now