本文整理汇总了C#中ICommsSerial.ReadByte方法的典型用法代码示例。如果您正苦于以下问题:C# ICommsSerial.ReadByte方法的具体用法?C# ICommsSerial.ReadByte怎么用?C# ICommsSerial.ReadByte使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICommsSerial
的用法示例。
在下文中一共展示了ICommsSerial.ReadByte方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Serial_ReadLine
string Serial_ReadLine(ICommsSerial comPort)
{
StringBuilder sb = new StringBuilder();
DateTime Deadline = DateTime.Now.AddMilliseconds(comPort.ReadTimeout);
while (DateTime.Now < Deadline)
{
if (comPort.BytesToRead > 0)
{
byte data = (byte)comPort.ReadByte();
sb.Append((char)data);
if (data == '\n')
break;
}
}
return sb.ToString();
}
示例2: Upload
public static void Upload(string firmwarebin, ICommsSerial comPort)
{
var fs = new FileStream(firmwarebin, FileMode.Open);
var len = (int)fs.Length;
len = (len % 128) == 0 ? len / 128 : (len / 128) + 1;
var startlen = len;
int a = 1;
while (len > 0)
{
if (LogEvent != null)
LogEvent("Uploading block " + a + "/" + startlen);
XModem.SendBlock(fs, comPort, a);
// responce ACK
var ack = comPort.ReadByte();
while (ack == 'C')
ack = comPort.ReadByte();
if (ack==ACK)
{
len--;
a++;
if (ProgressEvent != null)
ProgressEvent(len / startlen);
}
else if (ack==NAK)
{
CustomMessageBox.Show("Corrupted packet. Please power cycle and try again.\r\n", "Warning",
MessageBoxButtons.OK, MessageBoxIcon.Warning);
len = 0;
}
}
// boot
comPort.Write("b");
}
示例3: upload_xmodem
bool upload_xmodem(ICommsSerial comPort)
{
// try xmodem mode
// xmodem - short cts to ground
try
{
uploader_LogEvent("Trying XModem Mode");
//comPort.BaudRate = 57600;
comPort.BaudRate = MainV2.comPort.BaseStream.BaudRate;
comPort.ReadTimeout = 1000;
Thread.Sleep(2000);
var tempd = comPort.ReadExisting();
Console.WriteLine(tempd);
comPort.Write("U");
Thread.Sleep(1000);
var resp1 = Serial_ReadLine(comPort); // echo
var resp2 = Serial_ReadLine(comPort); // echo 2
var tempd2 = comPort.ReadExisting(); // posibly bootloader info / use to sync
// identify
comPort.Write("i");
// responce is rfd900....
var resp3 = Serial_ReadLine(comPort); //echo
var resp4 = Serial_ReadLine(comPort); // newline
var resp5 = Serial_ReadLine(comPort); // bootloader info
uploader_LogEvent(resp5);
if (resp5.Contains("RFD900"))
{
// start upload
comPort.Write("u");
var resp6 = Serial_ReadLine(comPort); // echo
var resp7 = Serial_ReadLine(comPort); // Ready
if (resp7.Contains("Ready"))
{
comPort.ReadTimeout = 3500;
// responce is C
var isC = comPort.ReadByte();
var temp = comPort.ReadExisting();
if (isC == 'C')
{
XModem.LogEvent += uploader_LogEvent;
XModem.ProgressEvent += uploader_ProgressEvent;
// start file send
XModem.Upload(@"SiK900x.bin",
comPort);
XModem.LogEvent -= uploader_LogEvent;
XModem.ProgressEvent -= uploader_ProgressEvent;
return true;
}
}
}
}
catch (Exception ex2)
{
log.Error(ex2);
}
return false;
}
示例4: Sleep
void Sleep(int ms, ICommsSerial comPortT)
{
DateTime start = DateTime.Now;
Console.WriteLine("sleep in");
while (start.AddMilliseconds(ms) > DateTime.Now)
{
while (comPortT.BytesToRead > 0)
{
Console.Write((char)comPortT.ReadByte());
}
System.Threading.Thread.Sleep(1);
}
Console.WriteLine("sleep out");
}