Translate C++ code that uses char type to Python -
how code in python? nrcomm1->sendchar
can replaced serial.write(a_char)
void prepare() { char temp[50]; sprintf(temp,"%04xt2000a", 76); send(temp); } void send(char *tx_string) { unsigned char checksum = 0x02; nrcomm1->sendchar(0x02); while(*tx_string) { nrcomm1->sendchar(*tx_string); checksum ^= *tx_string++; } nrcomm1->sendchar(0x03); checksum ^= 0x03; nrcomm1->sendchar(checksum); }
it (not working example, started):
update: provided hints how make example work...
def prepare(): temp = "%04xt2000a" % 76 send(temp) def send(tx_string): checksum = 0x02 serial.write(checksum) # hint: int conversion not work since tx_string # string representation of hex value, add conversion code while(tx_string): serial.write(int(tx_string[0])) checksum = checksum ** int(tx_string[0]) tx_string = tx_string[1:] serial.write(0x03) checksum = checksum ** 0x03 serial.write(checksum)
Comments
Post a Comment