• C

How to format manufacter given command?

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 vendor...it 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 hyperterminal...how do i present it? like? STX+55555 PCS
what about the CR and LF and space character when testing it with hyperterminal?
jaxrpcAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

grg99Commented:
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.

0
Kent OlsenData Warehouse Architect / DBACommented:
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!
Kent
0
mokuleCommented:
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

regards

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mokuleCommented:
to be more specific
sprintf(str_tx,"%c%c%5d PCS\r\n",12,43,myValue);
0
jaxrpcAuthor Commented:
haha sorry...i copied the vb.net code...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.