I
ibwhoib
Hey all,
I caught a job where I have to write a linux daemon that communicates with a
device connected to a serial port. Here are some details.
I connect to the device in the standard fashion:
fd = open(device, O_RDWR | O_NOCTTY | O_NDELAY);
I set the port options:
options.c_cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL;
cfsetospeed(&options, B9600);
tcsetattr(fd, TCSANOW, &options);
I now want to write some data to the port. The documentation on the device
has the following information:
"The command structure consist of one start byte, one command byte, five
bytes of data, and one byte checksum"
So I need a string of bytes. I created this string by using a unsigned
character array and setting the values to a command. Like so:
char cmd[7];
cmd[0] = 42;
cmd[1] = 0;
cmd[2] = 0;
cmd[3] = 132;
cmd[4] = 177;
cmd[5] = 0;
cmd[6] = 119;
cmd[7] = 188;
I then try to write the command to the port.
int written;
written = write(fd, cmd, 7);
My first question is is this the correct way to send this command?
Unfortunately, the device doesn't seem to think it is and returns 3 bytes
that are undocumented. I would appreciate any help. If you need any further
information, please let me know.
Thanks,
ib
I caught a job where I have to write a linux daemon that communicates with a
device connected to a serial port. Here are some details.
I connect to the device in the standard fashion:
fd = open(device, O_RDWR | O_NOCTTY | O_NDELAY);
I set the port options:
options.c_cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL;
cfsetospeed(&options, B9600);
tcsetattr(fd, TCSANOW, &options);
I now want to write some data to the port. The documentation on the device
has the following information:
"The command structure consist of one start byte, one command byte, five
bytes of data, and one byte checksum"
So I need a string of bytes. I created this string by using a unsigned
character array and setting the values to a command. Like so:
char cmd[7];
cmd[0] = 42;
cmd[1] = 0;
cmd[2] = 0;
cmd[3] = 132;
cmd[4] = 177;
cmd[5] = 0;
cmd[6] = 119;
cmd[7] = 188;
I then try to write the command to the port.
int written;
written = write(fd, cmd, 7);
My first question is is this the correct way to send this command?
Unfortunately, the device doesn't seem to think it is and returns 3 bytes
that are undocumented. I would appreciate any help. If you need any further
information, please let me know.
Thanks,
ib