Writing an int or other variables to the serial port.
this->Serialport->Write(string): Is how its currently being done. I want to be able to write a number out without it taking up so many bytes..
Any ideas ?
Thanks.
this->Serialport->Write(string): Is how its currently being done. I want to be able to write a number out without it taking up so many bytes..
Any ideas ?
Thanks.
If your Serialport member is a SerialPort object, then according to MSDN it supports transferring of byte arrays. Now your problem is: how to convert a number to and from byte array?
Supposing this, you can consider and improve the following example for long numbers:
// sending: long x = 12345; array< byte > ^ b = gcnew array< byte >(sizeof(x)); pin_ptr< byte > p = &b[0]; *(long*)p = x; this->Serialport->Write(b, 0, b.length);
// receiving: long x; array< byte > ^ b = gcnew array< byte >(sizeof(x)); this->Serialport->Read(b, 0, b.length); pin_ptr< byte > p = &b[0]; x = *(long*)p;
I hope this helps. Otherwise give us more relevant details.