本文整理汇总了C#中ICommsSerial.Read方法的典型用法代码示例。如果您正苦于以下问题:C# ICommsSerial.Read方法的具体用法?C# ICommsSerial.Read怎么用?C# ICommsSerial.Read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICommsSerial
的用法示例。
在下文中一共展示了ICommsSerial.Read方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: doConnect
public bool doConnect(ICommsSerial comPort)
{
try
{
Console.WriteLine("doConnect");
// setup a known enviroment
comPort.Write("ATO\r\n");
// wait
Sleep(1100, comPort);
comPort.DiscardInBuffer();
// send config string
comPort.Write("+++");
Sleep(1100,comPort);
// check for config response "OK"
log.Info("Connect btr " + comPort.BytesToRead + " baud " + comPort.BaudRate);
// allow time for data/response
byte[] buffer = new byte[20];
int len = comPort.Read(buffer, 0, buffer.Length);
string conn = ASCIIEncoding.ASCII.GetString(buffer, 0, len);
log.Info("Connect first response " + conn.Replace('\0', ' ') + " " + conn.Length);
if (conn.Contains("OK"))
{
//return true;
}
else
{
// cleanup incase we are already in cmd mode
comPort.Write("\r\n");
}
doCommand(comPort, "AT&T");
string version = doCommand(comPort, "ATI");
log.Info("Connect Version: " + version.Trim() + "\n");
Regex regex = new Regex(@"SiK\s+(.*)\s+on\s+(.*)");
if (regex.IsMatch(version))
{
return true;
}
return false;
}
catch { return false; }
}