我在编程方面并没有真正的经验,但我正在尝试将 C++ 代码从 Linux 移植到 Windows。这是一个写入串行端口并读取答案的函数,然后对其进行解析。我可能可以把它放在一起,但我不确定如何将以下内容从 Linux 移植到 Windows:
void serialPort::mark() {
options.c_cflag |= PARENB | CMSPAR | PARODD;
tcsetattr(fd, TCSAFLUSH, &options);
}
和
void serialPort::space() {
options.c_cflag |= PARENB | CMSPAR;
options.c_cflag &= ~PARODD;
tcsetattr(fd, TCSANOW, &options);
这些函数用于在写入串行端口时在标记和空间奇偶校验之间切换 - 命令的第一个字节必须用标记奇偶校验写入,其余的用空间奇偶校验写入,如下所示:
char sum=checksum(length,command);
char* bufptr;
int nbytes=0;
mark();
write(fd,&length,1); //write first byte with mark parity
usleep(2000);
read(fd,buffer,255);
space(); //write remaining bytes with space parity
for(int i=0; i<length;i++){
write(fd,&command[i],1);
usleep(2000);
read(fd,buffer,1);
}
write(fd,&sum,1);
但我坚持这一点。我什至不知道在 Windows 中是否可行。请问有人有什么想法吗?非常感谢你。