?
Solved

How to format manufacter given command?

Posted on 2006-04-25
5
Medium Priority
?
337 Views
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 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?
0
Comment
Question by:jaxrpc
5 Comments
 
LVL 22

Expert Comment

by:grg99
ID: 16532944
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
 
LVL 46

Expert Comment

by:Kent Olsen
ID: 16533265
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
 
LVL 17

Accepted Solution

by:
mokule earned 2000 total points
ID: 16542052
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
 
LVL 17

Expert Comment

by:mokule
ID: 16542106
to be more specific
sprintf(str_tx,"%c%c%5d PCS\r\n",12,43,myValue);
0
 

Author Comment

by:jaxrpc
ID: 16542414
haha sorry...i copied the vb.net code...
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
There's never been a better time to become a computer scientist. Employment growth in the field is expected to reach 22% overall by 2020, and if you want to get in on the action, it’s a good idea to think about at least minoring in computer science …
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

621 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