I only need to send a hexadecimal like this to a remote serial for the device to accept it.
2 byte hexadecimal I need to send is:
181E
I can telnet to the remote serial and send that command:
telnet x.x.x.x port
181E
I get a response back which is okay.
How can I do this in linux c?
I want to use the write function.
err = write(socket,181E,2);
Or How can I store the 2 byte decimal to a variable so It will be read as 181E?
int this_is_2_bytes = 181E; // Is this correct?
err = write(socket, this_is_2_bytes, sizeof(this_is_2_bytes));
You need to send a hexadecimal string . So,
const char cmd[] = "181E";
err = write(socket, cmd, strlen(cmd));
No, writing an int is not correct on all systems. Write a two-element byte array.
write()函数需要一个指针作为第二个参数,并将其存储在字符数组中。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.