Code C# – RS232 – HEX – Checksum
Sử dụng RS232 (truyền thông nối tiếp) trong C#
Sử dụng:
using System.IO.Ports;
2. Khai báo
SerialPort sp = new SerialPort();
3. code
sp.PortName = "COM5";
sp.BaudRate = 9600;
sp.Parity = Parity.None;
sp.DataBits = 8;
sp.StopBits = StopBits.One;
sp.Open();
byte[] bytestosend4 = { 0xA0, 0x02, 0x00, 0xA2 };
sp.Write(bytestosend, 0, 4);
sp.Close();
int checksum(byte[] byteArray)
{
int result = 0;
foreach (byte value in byteArray)
{
result += value;
}
return result;
}