private void PIN4_Click(object sender, EventArgs e) { if (dataGridView1.DataSource == null) { MyClass.Myclass Myclass = new MyClass.Myclass(); byte[] COM1 = new byte[16]; COM1[0] = 0x5f; COM1[1] = 0x5f; COM1[2] = 0x00; COM1[3] = 0x0A; COM1[4] = 0x00; COM1[5] = 0x01; COM1[6] = 0x10; COM1[7] = 0x01; COM1[8] = 0x00; COM1[9] = 0x00; COM1[10] = 0x03; COM1[11] = 0x04; byte[] crc = new byte[8]; byte[] crcreturn = new byte[2]; for (int i = 4, j = 0; i < 12; i++, j++) { crc[j] = COM1[i]; } crcreturn = Myclass.CRC16(crc, crc.Length); COM1[12] = crcreturn[1]; COM1[13] = crcreturn[0]; COM1[14] = 0x55; COM1[15] = 0xAA; Sp1.Write(COM1, 0, COM1.Length); } else { DataTable dt = (DataTable)dataGridView1.DataSource; dt.Rows.Clear(); dataGridView1.DataSource = dt; MyClass.Myclass Myclass = new MyClass.Myclass(); byte[] COM1 = new byte[16]; COM1[0] = 0x5f; COM1[1] = 0x5f; COM1[2] = 0x00; COM1[3] = 0x0A; COM1[4] = 0x00; COM1[5] = 0x01; COM1[6] = 0x10; COM1[7] = 0x01; COM1[8] = 0x00; COM1[9] = 0x00; COM1[10] = 0x03; COM1[11] = 0x04; byte[] crc = new byte[8]; byte[] crcreturn = new byte[2]; for (int i = 4, j = 0; i < 12; i++, j++) { crc[j] = COM1[i]; } crcreturn = Myclass.CRC16(crc, crc.Length); COM1[12] = crcreturn[1]; COM1[13] = crcreturn[0]; COM1[14] = 0x55; COM1[15] = 0xAA; Sp1.Write(COM1, 0, COM1.Length); } }
private void Connect_Click(object sender, EventArgs e) //0x0001 { MyClass.Myclass Myclass = new MyClass.Myclass(); byte[] COM1 = new byte[19]; COM1[0] = 0x5f; COM1[1] = 0x5f; COM1[2] = 0x00; COM1[3] = 0x0d; COM1[4] = 0x00; COM1[5] = 0x01; COM1[6] = 0x10; COM1[7] = 0x01; COM1[8] = 0x00; COM1[9] = 0x00; COM1[10] = 0x01; COM1[11] = 0x07; COM1[12] = 0x51; COM1[13] = 0x70; COM1[14] = 0x05; byte[] crc = new byte[11]; byte[] crcreturn = new byte[2]; for (int i = 4, j = 0; i < 15; i++, j++) { crc[j] = COM1[i]; } crcreturn = Myclass.CRC16(crc, crc.Length); COM1[15] = crcreturn[1]; COM1[16] = crcreturn[0]; COM1[17] = 0x55; COM1[18] = 0xAA; Sp1.Write(COM1, 0, COM1.Length); }
private void ReadPIN1_Click(object sender, EventArgs e) //0x0005 { byte[] COM2 = new byte[25]; COM2[0] = 0x5f; COM2[1] = 0x5f; COM2[2] = 0x00; COM2[3] = 0x13; COM2[4] = 0x00; COM2[5] = 0x01; COM2[6] = 0x10; COM2[7] = 0x01; COM2[8] = 0x00; COM2[9] = 0x00; COM2[10] = 0x05; COM2[11] = 0x01; COM2[12] = 0x01; for (int i = 13; i < 13 + 8; i++) { COM2[i] = 0x00; } byte[] crc = new byte[17]; byte[] crcreturn = new byte[2]; for (int i = 4, j = 0; i < 13 + 8; i++, j++) { crc[j] = COM2[i]; } crcreturn = Myclass.CRC16(crc, crc.Length); COM2[21] = crcreturn[1]; COM2[22] = crcreturn[0]; COM2[23] = 0x55; COM2[24] = 0xAA; Sp1.Write(COM2, 0, COM2.Length); }