问题描述
程式可以执行我想要把下面5个变数原本16进位换成10进位TAG_RSSITAG_LQITAG_DITAG_T1TAG_T2如何把输出的资料TAG_IDTAG_RSSITAG_LQITAG_DITAG_T1TAG_T2写入MySQL的资料库publicpartialclassForm1:Form{stringTAG_Data="";intTAG_Total=0;boolProcessing=false;publicForm1(){InitializeComponent();for(inti=1;i<=16;i++){comboBoxPort.Items.Add("COM"+i.ToString());}comboBoxPort.SelectedIndex=3;////dataGridTextBoxColumn1//dataGrid1.TableStyles.Add(this.dataGridTableStyle1);dataGridTableStyle1.GridColumnStyles.Add(this.dataGridTextBoxColumn1);dataGridTextBoxColumn1.Width=320;}privatevoidbutton_Start_Stop_Click(objectsender,EventArgse){inti,Single_Length=0;char[]com=newchar[5];boolempty;stringTAG_ID,TAG_RSSI,TAG_LQI,TAG_DI,TAG_T1,TAG_T2;if(button_Start_Stop.Text=="Stop"){button_Start_Stop.Text="Start";serialPort1.Close();return;}try{serialPort1.PortName=comboBoxPort.Text;serialPort1.Open();}catch(Exceptionex){MessageBox.Show(ex.Message,"Error!!");return;}button_Start_Stop.Text="Stop";Processing=false;System.Threading.Thread.Sleep(3000);com[0]='A';com[1]='3';com[2]=Convert.ToChar(0x0D);serialPort1.Write(com,0,3);while(serialPort1.IsOpen){while(TAG_Data.Length>22){Single_Length=TAG_Data.IndexOf(Convert.ToChar(0x0D));if(Single_Length>=22&&Single_Length<TAG_Data.Length){Processing=true;TAG_ID=TAG_Data.Substring(0,16);TAG_RSSI=TAG_Data.Substring(16,2);TAG_LQI=TAG_Data.Substring(18,2);TAG_DI=TAG_Data.Substring(20,2);if(Single_Length>22){TAG_T1=TAG_Data.Substring(22,4);}else{TAG_T1="-";}if(Single_Length>26){TAG_T2=TAG_Data.Substring(26,4);}else{TAG_T2="-";}empty=true;for(i=0;i<TAG_Total;i++){if(dataSet1.Tables["TAGMessage"].Rows[i]["ID"].ToString()==TAG_ID){dataSet1.Tables["TAGMessage"].Rows[i]["RSSI"]=TAG_RSSI;dataSet1.Tables["TAGMessage"].Rows[i]["LQI"]=TAG_LQI;dataSet1.Tables["TAGMessage"].Rows[i]["DI"]=TAG_DI;dataSet1.Tables["TAGMessage"].Rows[i]["T1"]=TAG_T1;dataSet1.Tables["TAGMessage"].Rows[i]["T2"]=TAG_T2;tAGMessageBindingSource.Position=i;empty=false;break;}Application.DoEvents();}if(empty){dataSet1.Tables["TAGMessage"].Rows.Add(TAG_ID,TAG_RSSI,TAG_LQI,TAG_DI,TAG_T1,TAG_T2);TAG_Total++;textBox1.Text=TAG_Total.ToString();}dataGrid1.Refresh();TAG_Data=TAG_Data.Substring(Single_Length+1);}else{break;}Application.DoEvents();}Processing=false;Application.DoEvents();}}privatevoidbutton_Clear_Click(objectsender,EventArgse){dataSet1.Clear();TAG_Total=0;textBox1.Text=TAG_Total.ToString();}privatevoidbutton_Exit_Click(objectsender,EventArgse){serialPort1.Close();Application.Exit();}privatevoidserialPort1_DataReceived(objectsender,System.IO.Ports.SerialDataReceivedEventArgse){if(!Processing){TAG_Data=serialPort1.ReadExisting();}}}
解决方案
解决方案二:
具体什么内容,举个例子出来,如果是简单的16进制字符串转10进制,很容易stringstr="0x10";inti=Convert.ToInt32(str,16);
解决方案三:
一个PDA程式执行后可以选的COMPort按Start就会取到TAG_IDTAG_RSSITAG_LQITAG_DITAG_T1TAG_T2