コード例 #1
0
        //_________________________________________________________________________
        // { 0xcd, 0xcc, 0xf6, 0x42 };	//, 0x11,0, 1, 0, 2, 0, 10, 0, 15, 0, 1, 0 };// { 0x0, 0x0, 0, 0x1};	// {  0x30, 0x31, 0x2f, 0x30, 0x31, 0x2f, 0x31, 0x39, 0x37, 0x30, 0x00, 0x30, 0x3a, 0x30, 0x30, 0x3a, 0x30, 0x30, 0x00 };//{,  0x00, 0x00, 0xe4, 0x43 }; //0x00, 0x80, 0xa0, 0x43
        private void BWritePar_Click(object sender, EventArgs e)
        {
            CBDataSave();
            CBDataWriteParSave();
            CBParameterNameSave();

            Properties.Settings.Default.Save();
            int    iID     = int.Parse(TBIDwritePar.Text);
            string sParams = "[\"" + CONST.ПАРАМЕТРЫ.DeviceName.ToString() + "\":\"" + CBDeviceWr.Text + "\"," +
                             CONST.ПАРАМЕТРЫ.Data.ToString() + "\":\"" + CBData.Text + "\"," +
                             CONST.ПАРАМЕТРЫ.ParameterType.ToString() + "\":\"" + CBTypeData.Text + "\"," +
                             CONST.ПАРАМЕТРЫ.ParameterName.ToString() + "\":\"" + CBParameterName.Text + "\"," +
                             CONST.ПАРАМЕТРЫ.RequestName.ToString() + "\":\"MT16\"," +
                             CONST.ПАРАМЕТРЫ.INorOUT.ToString() + "\":\"out" + "\"," +
                             CONST.ПАРАМЕТРЫ.RequestType.ToString() + "\":\"" + CONST.RequestType.Single.ToString() + "\"," +
                             CONST.ПАРАМЕТРЫ.TimeRequest.ToString() + "\":\"" + NTimeResp.Text +
                             "\"]";

            string[] asaDataWritePar = CBDataWritePar.Text.Split(' ');
            int      iSizeData       = CONST.SizeTypeData((TYPE)Enum.Parse(typeof(TYPE), CBTypeData.Text));

            if (iSizeData != asaDataWritePar.Length)
            {
                MessageBox.Show(string.Format("Длина данных [{0}] не равна размеру типа [{1}]", iSizeData, asaDataWritePar.Length));
                return;
            }
            byte[] btaDataWritePar = new byte[iSizeData];
            int    i = 0;

            foreach (var item in asaDataWritePar)
            {
                btaDataWritePar[i++] = byte.Parse(item);
            }
            DRV.WriteValue(iID, sParams, btaDataWritePar);
        }
コード例 #2
0
        //_________________________________________________________________________
        byte[] StrToTypeThenBytes(string asVal, string asTypeVal, EReverce Reverce, int iRow)
        {
            try
            {
                TYPE    TheType = (TYPE)Enum.Parse(typeof(TYPE), GVDataWr.Rows[iRow].Cells[(int)Params.Typ].Value.ToString());
                dynamic oVal    = Global.StrToType(asVal, TheType);
                if (oVal.GetType().ToString().Equals("System.String"))
                {
                    return(new byte[1]);
                }
                if (Reverce == EReverce.Обратная)
                {
                    byte[] btaRev = BitConverter.GetBytes(oVal);
                    return(btaRev.Reverse().ToArray());
                }

                if (Reverce == EReverce.Обратная_по_2_байта)
                {
                    int    iTypeSize = CONST.SizeTypeData(TheType);
                    byte[] btRet     = new byte[iTypeSize];
                    Global.AppendTwoBytesRev(BitConverter.GetBytes(oVal), 0, btRet, 0, iTypeSize);
                    return(btRet);
                }
                return(BitConverter.GetBytes(oVal));
            }
            catch (Exception exc)
            {
                MessageBox.Show(string.Format("Значение параметра [{0}] не соответствует типу [{1}].{2}",
                                              asVal, asTypeVal, exc.StackTrace));
                return(null);
            }
        }