Bu projede seriport kullanmam lazım. Şu şekilde yeni bir kod yazdım ama hala istediğim gibi çalışmıyor.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO.Ports;
using System.IO;
namespace WindowsFormsApp15
{
public partial class Form1 : Form
{
int g;
string[] ports = SerialPort.GetPortNames();
public Form1()
{
InitializeComponent();
}
private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
g = serialPort1.BytesToRead;
if (g >= 9)
{
byte[] data = new byte[g];
serialPort1.Read(data, 0, g);
string B1 = string.Format("{0:X}", data[0]);
string B2 = string.Format("{0:X}", data[1]);
string B3 = string.Format("{0:X}", data[2]);
string B4 = string.Format("{0:X}", data[3]);
string B5 = string.Format("{0:X}", data[4]);
string B6 = string.Format("{0:X}", data[5]);
if (g == 9)
{
string B7 = string.Format("{0:X}", data[6]);
string B8 = string.Format("{0:X}", data[7]);
string B9 = string.Format("{0:X}", data[8]);
changebyte();
byte[] crc16 = { (byte)Convert.ToInt16(B1, 16), (byte)Convert.ToInt16(B2, 16), (byte)Convert.ToInt16(B2, 16), (byte)Convert.ToInt16(B3, 16), (byte)Convert.ToInt16(B4, 16), (byte)Convert.ToInt16(B5, 16), (byte)Convert.ToInt16(B6, 16), (byte)Convert.ToInt16(B6, 16) };
string GenCrc16 = null;
if (B8 == (GenCrc16(crc16, 7) & 00xFF).ToString("X") && B9 == (GenCrc16(crc16, 7) >> 8).ToString("X") );
{
}
}
}
}
private bool ToString(string v)
{
throw new NotImplementedException();
}
private void changebyte()
{
throw new NotImplementedException();
}
private void Form1_Load(object sender, EventArgs e)
{
foreach (string port in ports)
{
comboBox1.Items.Add(port);
comboBox1.SelectedIndex = 0;
}
}
}
}