Я борюсь, потому что ввод в текстовое поле представляет собой строку. , как мне это сделать, пожалуйста? Спасибо
Код: Выделить всё
private void btnSendData_Click(object sender, EventArgs e)
{
if (serialPort1.IsOpen)
{
byte[] payload= System.Text.Encoding.Unicode.GetBytes(tBoxDataOut.Text);
var addressAndOpcode = new byte[] { 0x0A, 0x08, 0x04, 0x01, 0x02, 0x03 };
// this is wrong it should be size of 4 bytes after position 5 which has value 0x03
addressAndOpcode[6] = payload;
try
{
serialPort1.Write(addressAndOpcode, 0, addressAndOpcode.length ??);
}
catch (Exception err)
{
MessageBox.Show(err.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
, будет добавлено в конец массива, прежде чем я смогу отправить его через последовательный порт
Вот так:
Код: Выделить всё
{ 0x0A, 0x08, 0x04, 0x01, 0x02, 0x03, 0xff, 0xff, 0xff, 0xff };
Подробнее здесь: https://stackoverflow.com/questions/787 ... hrough-the