From: Gerhard Wolf on
Hi,

the documentation of a serial devices explains how to communicate.
I have to send the sequence:

Device adress: 0x01
Function: 0x03
Register adress: 0x0000
....
....
to a serial port. I use the sio_write(int port, char *buf, int len)
API-232 function

but how do i convert the this hex values (0x01, 0x03, 0x000...)
to a char *buf ?

please help
From: Alf P. Steinbach on
* Gerhard Wolf:
> Hi,
>
> the documentation of a serial devices explains how to communicate.
> I have to send the sequence:
>
> Device adress: 0x01
> Function: 0x03
> Register adress: 0x0000
> ...
> ...
> to a serial port. I use the sio_write(int port, char *buf, int len)
> API-232 function
>
> but how do i convert the this hex values (0x01, 0x03, 0x000...)
> to a char *buf ?

Uhm, it seems this is old DOS programming.

Then things get complicated, but you might start by

char* buf = { 0x01, 0x03, 0x00, 0x00 };

It's not really a language question because the details depend heavily on the
DOS C compiler you're using.

Perhaps there is some Usenet group dedicated to old DOS programming?


Cheers & hth.,

- Alf

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
From: Alf P. Steinbach on
* Alf P. Steinbach:
> * Gerhard Wolf:
>> Hi,
>>
>> the documentation of a serial devices explains how to communicate.
>> I have to send the sequence:
>>
>> Device adress: 0x01
>> Function: 0x03
>> Register adress: 0x0000
>> ...
>> ...
>> to a serial port. I use the sio_write(int port, char *buf, int len)
>> API-232 function
>>
>> but how do i convert the this hex values (0x01, 0x03, 0x000...)
>> to a char *buf ?
>
> Uhm, it seems this is old DOS programming.
>
> Then things get complicated, but you might start by
>
> char* buf = { 0x01, 0x03, 0x00, 0x00 };

Meant

char buf[] = { 0x01, 0x03, 0x00, 0x00 };


> It's not really a language question because the details depend heavily
> on the DOS C compiler you're using.
>
> Perhaps there is some Usenet group dedicated to old DOS programming?
>
>
> Cheers & hth.,
>
> - Alf
>


--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
From: Barry Schwarz on
On Wed, 10 Sep 2008 16:25:43 +0200, Gerhard Wolf <quisquiliae(a)gmx.de>
wrote:

>Hi,
>
>the documentation of a serial devices explains how to communicate.
>I have to send the sequence:
>
>Device adress: 0x01
>Function: 0x03
>Register adress: 0x0000
>...
>...
>to a serial port. I use the sio_write(int port, char *buf, int len)
>API-232 function
>
>but how do i convert the this hex values (0x01, 0x03, 0x000...)
>to a char *buf ?

If you really have a pointer instead of an array, step 1 is to make
sure the pointer points to an array large enough to hold the 4 bytes
you intend to send. You then assign the correct values to the
elements of the array. The one byte values are easy. The two byte
value could depend on the endian type of your system but since both
bytes have the same value that problem evaporates.

Possible methods of assigning values to the array include
a - buf[0] = 0x01; buf[1] = 0x03;...
b - memcpy(buf, "\x01\x03\x00\x00", 4);

--
Remove del for email