标签/分类 "代码片段" 下的文章
C语言 十六进制字符串和十六进制之间互转(嵌入式编程)
type.c /* * Module Name: type.c * Module Date: 2019-7-20 * Module Auth: zhangpeng * Description: 存放一些通用的函数 * Others: * Revision History: * Date Rel Ver Notes * 2019-7-20 11:30:12 新建文件 */ #include "board.h" #include <ctype.h> // ----------------------------------------------------------------- // 函数功能: 判断字符串s是否包含c // 函数名称: str_is_include // 参数1 : s 源字符串 // 参数2 : c 目标字符串 // 返回值 : [1] 包含 [其他值] 不包含 // ----------------------------------------------------------------- int str_is_include (char *s, char *c) { int
QT 十六进制字符串和十六进制之间互转(ByteArray和HexString)
举例说明 ByteArray {0x01,0x02,0x03,0x04,0x05,0x06}; HexString "01 02 03 04 05 06" 代码 Convert.cpp #include "convert.h"#include <QString>#include <QMessageBox>#include <QDebug> Convert::Convert() { } QString Convert::ByteArrayToHexString(QByteArray data) { QString ret(data.toHex().toUpper()); int len = ret.length()/2; for(int i=1;i<=len;i++) { ret.insert(2*i+i-1,""); } return ret; } QByteArray Convert::HexStringToByteArray(QString HexString) { bool ok; QByteArray ret; HexString = HexString.trimmed(); HexString = HexString.simplified(); QStringList sl = HexString.split(""); foreach (QString s, sl) { if(!s.isEmpty()) { char c = s.toInt(&ok,16)&0xFF; if(ok){ ret.append(c); }else{ ret.clear(); //ret = NULL; qDebug()<<"非法的16进制字符:"<&l
C# 多线程操作
1 、带参数多线程 Thread t = new Thread(new ParameterizedThreadStart(ProcessAtCommand)); t.Start(at); private void ProcessAtCommand(Object at1) { AtType at = (AtType)at1; } 2、不带参数多线程 Thread t = new Thread(new ThreadStart(Calculate)); t.Start();
CSharp 一些代码小结--文件对话框
C# 一些代码小结–文件对话框 查看文件完整路径 try { Config cfg = new Config(); var file = ""; if (saveFileDialog1.ShowDialog() == DialogResult.OK) { file = saveFileDialog1.FileName;//(获取整个文件名) cfg.WriteConfigFile(command, file); MessageBox.Show("file:" + file); } } catch (Exception) { OutputMessage("检查软件路径下面是否
CSharp 一些代码小结--UI操作
C# 一些代码小结–UI操作 使用控件名调用控件 object obj = this.GetType().GetField("控件名", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.IgnoreCase).GetValue(this); ComboBox cb = (ComboBox)obj; 在控件触发事件时判断触发事件的控件 TextBox text = sender as TextBox; int id = 0; String str = null; switch (text.Name) 跨线程使用委托调用U
CSharp 一些代码小结--使用文件记录日志
C# 一些代码小结–使用文件记录日志 public class FaceLog { public static void AppendInfoLog(string errMsg) { try { string Folder = ".\\log\\"; string fileName = Folder + "Info_" + DateTime.Now.ToString("yyyyMMdd") + ".txt"; if (!System.IO.Directory.Exists(Folder)) System.IO.Directory.CreateDirectory(Folder); if (!File.Exists(fileName)) { FileStream stream = System.IO.File.Create(fileName); stream.Close(); stream.Dispose(); } using (TextWriter fs = new StreamWriter(fileName, true)) { fs.Write(errMsg); fs.Close(); fs.Dispose(); } } catch { } } public static void AppendSerialLog(string errMsg) { try { string Folder = ".\\log\\"; string fileName = Folder + "Serial_" + DateTime.Now.ToString("yyyyMMdd") + ".txt"; if (!System.IO.Directory.Exists(Folder)) System.IO.Directory.CreateDirectory(Folder); if (!File.Exists(fileName)) System.IO.File.Create(fileName); using (TextWriter fs = new StreamWriter(fileName, true)) { fs.Write(errMsg); fs.Close(); fs.Dispose(); } } catch
CSharp 一些代码小结--串口操作
串口解析显示中文 private String SerialPortReadStr() { try { String str = null; int n = serialPort1.BytesToRead;//数据接收缓存区的字接数 byte[] buffer = new byte[n];//创建临时字节数组 serialPort1.Read(buffer, 0, n);//从缓存区读取数据 str = Encoding.GetEncoding("GB2312").GetString(buffer); if(!IsStopReadComData) { UpDateLogTextBox(str); } if (保存串口日志ToolStripM
CSharp 一些代码小结--datGirdView保存到csv文件
if (dataGridView1.Rows.Count == 0) { MessageBox.Show("No data available!", "Prompt", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } else { SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "CSV files (*.csv)|*.csv"; saveFileDialog.FilterIndex = 0; saveFileDialog.RestoreDirectory = true; saveFileDialog.CreatePrompt = true; saveFileDialog.FileName = null; saveFileDialog.Title = "Save path of the file to be exported"; if (saveFileDialog.ShowDialog() == DialogResult.OK) { Stream myStream = saveFileDialog.OpenFile(); StreamWriter sw = new StreamWriter(myStream, System.Text.Encoding.GetEncoding(-0)); string strLine = ""; try { //Write in the headers of the columns. for (int i = 0; i < dataGridView1.ColumnCount; i++) { if (i > 0) strLine += ","; strLine += dataGridView1.Columns[i].HeaderText; } strLine.Remove(strLine.Length - 1); sw.WriteLine(strLine); strLine = ""; //Write in the content of the columns. for (int j = 0; j < dataGridView1.Rows.Count; j++) {
CSharp读取json配置文件内容
步骤 读取配置文件转换成字符串,代码如下 string contents = System.IO.File.ReadAllText("config.json"); 注意:该语句会抛出文件不存在异常。 使用Newtonsoft.Json将json字符串转换成类的对象,完整代码如下所示 public class Init { public static InitInfo init = new InitInfo(); public Init(){ try { string contents = System.IO.File.ReadAllText("config.json"); //Shell.WriteLine("ini 配置文件\r\n" + JsonConvert.SerializeObject(init)); init = JsonConvert.DeserializeObject<InitInfo>(contents); S
Java 使用json 做配置文件
概述 经常会用到通过配置文件,去配置一些参数,java里面本来是有配置文件的,但是导入很麻烦的,自从我用了json之后,从此一切配置文件都见鬼去吧. 1.下载gson解析json文件的jar包 首先我们要导入一个解析json文件的jar包,下载连