Beispiel #1
0
        private void btn_c104_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.txt_fwq_ip.Text) ||
                string.IsNullOrEmpty(this.txt_fwq_phone.Text) ||
                string.IsNullOrEmpty(this.txt_fwq_port.Text) ||
                string.IsNullOrEmpty(this.txt_fwq_apn.Text) ||
                string.IsNullOrEmpty(this.txt_fwq_apnname.Text) ||
                string.IsNullOrEmpty(this.txt_fwq_apnkey.Text)

                )
            {
                MessageBox.Show("服务器参数不能为空"); return;
            }



            ServerParamType type = (ServerParamType)Convert.ToInt32(this.combox_fwq_type.SelectedValue);


            string gprs_adress = this.txt_fwq_ip.Text;

            string gprs_port = this.txt_fwq_port.Text;

            string gsm = this.txt_fwq_phone.Text;

            string apn = this.txt_fwq_apn.Text;

            string apn_name = this.txt_fwq_apnname.Text;

            string apn_key = this.txt_fwq_apnkey.Text;

            DataItem item = new DataItem_C104(type, gprs_adress, gprs_port, gsm, apn, apn_name, apn_key);

            CYWriteDataCmdSend(item);
        }
Beispiel #2
0
        public DataItem_C104(ServerParamType ParamType, string GPRS_Adress, string GPRS_Port, string GSM, string APN, string APN_Name, string APN_Kay)
        {
            this.ParamType = ParamType;

            this.GPRS_Adress = GPRS_Adress;
            this.GPRS_Port   = GPRS_Port;
            this.GSM         = GSM;

            this.APN      = APN;
            this.APN_Name = APN_Name;
            this.APN_Kay  = APN_Kay;



            //this.identityCode = IdentityCode.设置上传周期;
            //this.indexCode = 0x00;
            //this.controlCode = ControlCode.CYWriteData;
            //this.length = 89;

            this.dataUnits = new byte[86];

            dataUnits[0] = (byte)Convert.ToInt32(this.ParamType);



            //GPRS网络地址 25
            byte[] gprs_adress = Encoding.ASCII.GetBytes(GPRS_Adress);

            if (gprs_adress.Length > 25)
            {
                Console.WriteLine("GPRS网络地址超长"); return;
            }

            for (int i = 0; i < gprs_adress.Length; i++)
            {
                dataUnits[1 + i] = gprs_adress[i];
            }

            //GPRS网络端口号 5
            byte[] gprs_port = Encoding.ASCII.GetBytes(GPRS_Port);

            for (int i = 0; i < gprs_port.Length; i++)
            {
                dataUnits[26 + i] = gprs_port[i];
            }


            //GSM网络地址(手机号) 15
            byte[] gsm = Encoding.ASCII.GetBytes(GSM);

            for (int i = 0; i < gsm.Length; i++)
            {
                dataUnits[31 + i] = gsm[i];
            }


            //APN接入点 20
            byte[] apn = Encoding.ASCII.GetBytes(APN);

            for (int i = 0; i < apn.Length; i++)
            {
                dataUnits[46 + i] = apn[i];
            }


            //APN用户名 10
            byte[] apn_name = Encoding.ASCII.GetBytes(APN_Name);

            for (int i = 0; i < apn_name.Length; i++)
            {
                dataUnits[66 + i] = apn_name[i];
            }



            //APN用户密码 10
            byte[] apn_key = Encoding.ASCII.GetBytes(APN_Kay);

            for (int i = 0; i < apn_key.Length; i++)
            {
                dataUnits[76 + i] = apn_key[i];
            }
        }