Я борюсь, потому что входное текстовое поле представляет собой строку, как мне это сделать, пожалуйста? Спасибо
Код: Выделить всё
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 };
addressAndOpcode[6]= payload; // this is wrong it should be size of 4 bytes after position 5 which has value 0x03
try
{
}
catch (ошибка исключения)
Код: Выделить всё
{
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