/// <summary> /// 串口对手初始化 /// </summary> private void InitSerialPort() { //初始化串口配置类 configCom1 = new ConfigCom(this.cbSerial1, this.cbBaudRate1, this.cbDataBits1, this.cbStop1, this.cbParity1); configCom2 = new ConfigCom(this.cbSerial2, this.cbBaudRate2, this.cbDataBits2, this.cbStop2, this.cbParity2); //初始化串口助手类 serialPort1 = new SerialPortHelper(); serialPort1.ConfigSerialPort = configCom1.GetConfigComData(); serialPort1.BindSerialPortDataReceivedProcessEvent(new SerialPortHelper.DelegateSerialPortDataReceivedProcessEvent(SerialPortDataReceivedProcess)); serialPort1.BindSerialPortErrorEvent(new SerialPortHelper.DelegateSerialPortErrorEvent(SerialPortErrorProcess)); serialPort1.SerialReceviedTimeInterval = 40; serialPort1.SerialWriteTimeInterval = 1; serialPort1.SerialReceviedLengthMax = 1024; serialPort1.SerialMark = "串口1"; serialPort2 = new SerialPortHelper(); serialPort2.ConfigSerialPort = configCom1.GetConfigComData(); serialPort2.BindSerialPortDataReceivedProcessEvent(new SerialPortHelper.DelegateSerialPortDataReceivedProcessEvent(SerialPortDataReceivedProcess)); serialPort2.BindSerialPortErrorEvent(new SerialPortHelper.DelegateSerialPortErrorEvent(SerialPortErrorProcess)); serialPort2.SerialReceviedTimeInterval = 40; serialPort2.SerialWriteTimeInterval = 1; serialPort2.SerialReceviedLengthMax = 1024; serialPort2.SerialMark = "串口2"; }
/// <summary> /// 选择地图 /// </summary> /// <returns></returns> public JsonResult SwitchMapAjax() { Message ms = null; string value = Request.Params["value"]; if (string.IsNullOrEmpty(value)) { ms = new Message(false, "选择地图数据缺失", ""); } //<!--系统调用地图类型 0 系统自建ArcGis 1 Google地图 2 天地图 3Baidu地图--> //<add key="mapType" value="1" /> //<!--是否经纬度偏移量转换 0 表示不需要 1表示需要--> //<add key="lonLatChange" value="1" /> if (value == "1")//google { ConfigCom.UpdateAppSetting("mapType", value); ConfigCom.UpdateAppSetting("lonLatChange", "1"); } else { ConfigCom.UpdateAppSetting("mapType", value); ConfigCom.UpdateAppSetting("lonLatChange", "0"); } ms = new Message(true, "选择地图成功", ""); return(Json(ms)); }
/// <summary> /// 串口开关按钮事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSerialPortSwitch_Click(object sender, EventArgs e) { Button btn = (Button)sender; ConfigCom cc = (btn.Tag.ToString() == "1") ? configCom1 : configCom2; SerialPortHelper spb = (btn.Tag.ToString() == "1") ? serialPort1 : serialPort2; CheckBox chkTimer = (btn.Tag.ToString() == "1") ? chkSerialWriteLoop1 : chkSerialWriteLoop2; GroupBox grp = btn.Parent as GroupBox; if (btn.Text == "打开串口") { string strError; try { spb.OpenCom(cc.GetConfigComData(), out strError); } catch (Exception err) { strError = err.Message; } if (strError != "null") { MessageBox.Show(strError); } else { cc.GetDetectCom().Close(); Console.WriteLine("开启{0}端口成功。", cc.PortName); btn.Text = "关闭串口"; GroupBoxEnable(grp, false); } } else { spb.CloseCom(out string strError); if (strError != "null") { MessageBox.Show(strError); } else { cc.GetDetectCom().Open(); Console.WriteLine("关闭端口成功。"); btn.Text = "打开串口"; GroupBoxEnable(grp, true); chkTimer.Checked = false; } } }
/// <summary> /// ConfigCom测试函数 /// </summary> private void ConfigComTest() { //一次性绑定所有配置 //cc = new ConfigCom(cbSerial, cbBaudRate, cbDataBits, cbStop, cbParity); //常用绑定配置 //cc = new ConfigCom(cbSerial, cbBaudRate); //选择绑定配置 cc = new ConfigCom(cbSerial); cc.BindBaudRateObj(cbBaudRate); cc.BindDataBitsObj(cbDataBits); cc.BindStopBitsObj(cbStop); cc.BindParityObj(cbParity); //设置默认搜索串口信息(覆盖已存在的) cc.SetSerialPortDefaultInfo("TI CC2540 USB CDC Serial Port"); //添加默认搜索串口信息(追加) cc.AddSerialPortDefaultInfo("通用USB串口设备"); }
/// <summary> /// 初始化串口配置控件 /// </summary> private void initSerialConfig() { //实例化串口配置 configCom = new ConfigCom(cbSerial); configCom.BindBaudRateObj(cbBaudRate); configCom.BindDataBitsObj(cbDataBits); configCom.BindStopBitsObj(cbStop); configCom.BindParityObj(cbParity); configCom.BaudRate = 115200; //初始化串口配置 ConfigComType defConfig = GetSerialConfig(); configCom.BaudRate = defConfig.BaudRate; configCom.DataBits = defConfig.DataBits; configCom.StopBits = defConfig.StopBits; configCom.Parity = defConfig.Parity; //设置串口搜索默认值 configCom.SetSerialPortDefaultInfo("USB 串行设备"); //TI CC2540 USB CDC Serial Port configCom.AddSerialPortDefaultInfo("TI CC2540 USB CDC Serial Port"); }
/// <summary> /// 初始化串口助手 /// </summary> private void InitSerialPortHelper() { //实例化串口配置 configCom = new ConfigCom(comboSerial); configCom.PortName = comboSerial.Text; configCom.BaudRate = 115200; configCom.DataBits = 8; configCom.StopBits = StopBits.One; configCom.Parity = Parity.None; //设置串口搜索默认值 configCom.SetSerialPortDefaultInfo("USB 串行设备"); //TI CC2540 USB CDC Serial Port configCom.AddSerialPortDefaultInfo("TI CC2540 USB CDC Serial Port"); //实例化串口助手 serialPortHelper = new SerialPortHelper(configCom.GetConfigComData()); serialPortHelper.BindSerialPortDataReceivedProcessEvent(new SerialPortHelper.DelegateSerialPortDataReceivedProcessEvent(SerialPortDataReceivedProcess)); serialPortHelper.BindSerialPortErrorEvent(new SerialPortHelper.DelegateSerialPortErrorEvent(SerialPortErrorProcess)); serialPortHelper.SerialReceviedTimeInterval = 40; serialPortHelper.SerialWriteTimeInterval = 200; serialPortHelper.SerialReceviedLengthMax = 1024; }