在Qt中选择串口(Linux)(Selecting serial port in Qt(Linux))
我有很多串口,但是我想选择一个特定的端口,即/ dev / ttyUSB0来发送和接收数据,如何将端口设置为/ dev / ttyUSB0,我不希望用户从多个可用端口中选择,我只想使用/ dev / USB0。
I have many serial ports, but i want to select a particular one i.e /dev/ttyUSB0 to send and receive data, how to set port as /dev/ttyUSB0, i don't want user to select from a number of available ports, i just want to use /dev/USB0 only.
原文:https://stackoverflow.com/questions/17489424
最满意答案
for the SqlDataReader.GetString Method, No conversions are performed; therefore, the data retrieved must already be a string.
Call IsDBNull to check for null values before calling this method.
将您的代码更改为此,它应该工作
cmdRoute.CommandText = "SELECT id, name FROM routes"; using (var rdrRoute = cmdRoute.ExecuteReader()) { if(rdrRoute.Read()) { var route = new Route(); route.Id = rdrRoute["id"]; if (!rdrRoute.IsDBNull(rdrRoute.GetOrdinal("name"))) { route.Name = rdrRoute["name"].ToString(); //route.Name = rdrRoute.GetString(rdrRount.GetOrdinal("name")); //may not work in .Net 4.0 } } }
.NET 4.0 GetString()可能会导致.NET 4.0中的错误/错误我会尝试将项目滚动到版本3.5或创建一个使用代码示例的项目并将其创建为.NET 3.5,如果这适用于
GetString()
我发现.net 4.0中存在一些错误,我不确定KB Fix何时发布
for the SqlDataReader.GetString Method, No conversions are performed; therefore, the data retrieved must already be a string.
Call IsDBNull to check for null values before calling this method.
Change you code to this and it should work
cmdRoute.CommandText = "SELECT id, name FROM routes"; using (var rdrRoute = cmdRoute.ExecuteReader()) { if(rdrRoute.Read()) { var route = new Route(); route.Id = rdrRoute["id"]; if (!rdrRoute.IsDBNull(rdrRoute.GetOrdinal("name"))) { route.Name = rdrRoute["name"].ToString(); //route.Name = rdrRoute.GetString(rdrRount.GetOrdinal("name")); //may not work in .Net 4.0 } } }
.NET 4.0 GetString() may cause errors / bugs in .NET 4.0 I would try rolling the project back to ver 3.5 or create a project that uses the code sample and create it as .NET 3.5, if this works with the
GetString()
I have found that there are some bugs in .net 4.0 and I am not sure when the KB Fix is going to release
相关问答
更多-
你必须让int接受null值=> int? row.Field
("Presently_Available") == null ? 0 : row.Field ("Presently_Available") ; 这是可为空类型的链接 you have to make int accept null value => int? row.Field ("Presently_Available") == null ? 0 : row.Field ("Presently_Ava ... -
FileHelperEngine构造函数 - InvalidcastException(FileHelperEngine constructor - InvalidcastException)[2021-10-08]
正如Adriano建议的那样,使用[FieldNullValue(null)]而不是[FieldNullValue(typeof(int?),null)]修复了问题。 As Adriano suggested, using [FieldNullValue(null)] instead of [FieldNullValue(typeof(int?), null)] fixed the problem. -
你犯了两个错误: 1)您已使用DataTable.NewRow()创建新的DataRow 2)设置DataRow您必须使用DataTable.Rows.Add(youDataRow)将其添加到DataTable 。 更新您的代码并尝试: foreach (string line in File.ReadLines(filePathStudent)) { DataRow row = studentDataTable.NewRow(); string[] fields ...
-
您想做什么。 你想检查所有这些都是"" 。 然后这样做: If string.isNullOrEmpty(CustID) and _ string.isNullOrEmpty(FirstName) And string.isNullOrEmpty(SecondName) Then MsgBox("Please enter a term to search by") End If 或者你想检查其中一个是否是"" 。 然后这样做: If string.isNullOrEmp ...
-
为什么这个ExecuteQuery导致InvalidCastException?(Why is this ExecuteQuery causing InvalidCastException?)[2023-05-13]
尝试: IF OBJECT_ID('{0}', 'U') IS NOT NULL SELECT 1 ELSE SELECT 0 结果是一个字符串,并且演员显然失败了。 如果你可以做一个Convert.ToBool("true|false")它会起作用。 Both of the following two formats work properly. The core of the challenge appears to be what type is returned by ExecuteQuery. ... -
如果我删除ComponentModel DLL,那将成为例外 什么成为例外? 您获得的异常是100%明确的:您的项目引用的两个不同的程序集定义相同的类型System.ComponentModel.DescriptionAttribute 。 此类型记录为在System.dll中定义 。 所以System.ComponentModel.Primitives.dll程序集似乎是可疑的。 一点网页搜索引导我到这个System.ComponentModel.Primitives NuGet包 。 从此描述中,这似乎 ...
-
如果查看InvalidCastException的文本,它将在其中包含一个行号。 它提到的行号是InvalidCastException的来源。 If you look at the text of the InvalidCastException it will include a line number inside it. The line number it mentions is the source of the InvalidCastException.
-
避免使用SELECT * FROM mytable但要更明确地了解您所选择的内容。 例如,写这样的查询代替: SELECT NameOfColumn1, NameOfColumn2, ... FROM mytable Select *可能Select *列数多于您期望的2列(如果您的表有更多列,则会选择所有列)。 因此,铸件破裂。 Avoid using SELECT * FROM mytable but try being more explicit about what you are selecti ...
-
那是因为在你的表达中你正在访问一个Field。 该例外告诉您正在访问某个字段。 创建查询时不评估表达式。 它仅在您执行后执行。 此时,它需要解决该领域。 解决方法是首先将表达式放入局部变量: private static string GetSomething(IQueryable
things) { var expression = Program.ConvertToString; var ret = things .AsExpandable() ... -
字符串字段中的sqlite数值导致InvalidCastException(sqlite numeric value in string field causes InvalidCastException)[2022-06-18]
for the SqlDataReader.GetString Method, No conversions are performed; therefore, the data retrieved must already be a string. Call IsDBNull to check for null values before calling this method. 将您的代码更改为此,它应该工作 cmdRoute.CommandText = "SELECT id, name FROM ro ...