【文件属性】:
文件名称:C#读取电子秤重量
文件大小:49KB
文件格式:RAR
更新时间:2022-05-02 05:06:40
C# .NET 电子秤 串口
///
/// 执行AT指令并返回 成功失败
///
/// AT指令
/// AT指令标准结束标识
///
private void ATCommand3(string ATCmd, string StCmd)
{
string response = "";
response = ATCommand(ATCmd, StCmd);
}
///
/// 执行AT指令并返回结果字符
///
/// AT指令
/// AT指令标准结束标识
///
private string ATCommand(string ATCmd, string StCmd)
{
string response = "";
int i;
if (!ATCmd.EndsWith("\x01a"))
{
if (!(ATCmd.EndsWith("\r") || ATCmd.EndsWith("\r\n")))
{
ATCmd = ATCmd + "\r";
}
}
Sp.WriteLine(ATCmd);
//第一次读响应数据
if (Sp.BytesToRead > 0)
{
response = Sp.ReadExisting();
//去除前端多可能多读取的字符
if (response.IndexOf(ATCmd) > 0)
{
response = response.Substring(response.IndexOf(ATCmd));
}
else
{
}
if (response == "" || response.IndexOf(StCmd) < 0)
{
if (response != "")
{
if (response.Trim() == "ERROR")
{
//throw vError = new UnknowException("Unknown exception in sending command:" + ATCmd);
}
if (response.IndexOf("+CMS ERROR") >= 0)
{
string[] cols = new string[100];
cols = response.Split(';');
if (cols.Length > 1)
{
string errorCode = cols[1];
}
}
}
}
}
//读第一次没有读完的响应数据,直到读到特征数据或超时
for (i = 0; i < 3; i++)
{
Thread.Sleep(1000);
response = response + Sp.ReadExisting();
if (response.IndexOf(StCmd) >= 0)
{
break;
}
}
return response;
}
【文件预览】:
TEXTCOM
----TEXTCOM.sln(1KB)
----Backup()
--------TEXTCOM.sln(910B)
----.vs()
--------TEXTCOM()
----UpgradeLog.htm(31KB)
----TEXTCOM()
--------Form1.cs(8KB)
--------Program.cs(466B)
--------Form1.resx(6KB)
--------Properties()
--------Form1.Designer.cs(6KB)
--------obj()
--------bin()
--------TEXTCOM.csproj(3KB)
----TEXTCOM.suo(21KB)