c++ - Sending special ascii char through usb converter rs232 -
i need send special chars through usb rs232 converter device.
b.cpp:
unsigned char message[] = "Àwlo~p"; int main(void) { openport(port, 9600); int = 0; // while (i < 2000) { writeport(message); char* readchar = readport(); cout <<"rr "<< static_cast<string>(readchar); // i++; // sleep(5); // } closeport(); return exit_success;
}
my writeport function:
void writeport(unsigned char* message) { int e; (int = 0; < 7; i++) { e = message[i]; printf("out: %d", e) ; write(tty_fd, &message[i], 6); usleep(10); } }
beacose first sign out of range normal char "À" 192 see in printf it's divide 2 bytes.
printf output:
out: 195 out: 128 out: 119 out: 76 out: 79 out: 126 out:80
how can send that's specyfic char?
putting non-ascii characters c source file risky. if want specific byte sequence, write out array of numbers:
unsigned char message[] = { 192, 119, 76, 79, 126, 80 };
or string hexadecimal escapes:
unsigned char message[] = "\xc0wlo~p";
Comments
Post a Comment