コード例 #1
0
ファイル: F_Main.cs プロジェクト: SilyM/-
        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);
            }
        }
コード例 #2
0
ファイル: F_Main.cs プロジェクト: SilyM/-
        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);
        }