Owner manual
60
API / VCOM Commands
Appendix
IND100077-132
Basic Example for setting Half/Full Duplex Mode
Example using Linux, C style.
Note, ttyS7 has been used as port ID. It may differ depending on your system installation. In any case, simply write
ttySx (where x is the number dened by the Operating System automatically) for Virtual COM Port.
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <errno.h>
#include <termios.h>
#include <unistd.h>
int main(void)
{
int n;
int f;
struct termios options;
//Open COM Port
f = open(“/dev/ttyS7”, O_RDWR | O_NOCTTY | O_NDELAY);
if(f == -1)
{
perror(“open_port: Unable to open:”);
return -1;
}
else
{
printf(“COM Port Opened!\n”);
fcntl(f, F_SETFL, 0);
}
//Congure COM Port
tcgetattr(f, &options);
cfsetispeed(&options, B9600);
cfsetospeed(&options, B9600);
options.c_cag |= (CLOCAL | CREAD);
options.c_cag &= ~PARENB;
options.c_cag &= ~CSTOPB;
options.c_cag &= ~CSIZE;
options.c_cag |= CS8;
tcsetattr(f, TCSANOW, &options);
//Half Duplex Write
unsigned char half_duplex_cmd[9] = {0x07,0xFF,0x51,0x44,0x55,0x01,0x0E,0x00,0xFF};
write(f, half_duplex_cmd,9);
printf(“Sent Half Duplex\n”);
//Full Duplex Write
unsigned char full_duplex_cmd[9] = {0x07,0xFF,0x51,0x44,0x55,0x01,0x0E,0xFF,0x00};
write(f, full_duplex_cmd,9);
printf(“Sent Full Duplex\n”);
//Close COM Port
close(f);
printf(“Finished!\n”);
return 0;
}