本文整理汇总了C#中ComPort.PortClear方法的典型用法代码示例。如果您正苦于以下问题:C# ComPort.PortClear方法的具体用法?C# ComPort.PortClear怎么用?C# ComPort.PortClear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ComPort
的用法示例。
在下文中一共展示了ComPort.PortClear方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadBMP
private void LoadBMP(ComPort port, ushort progPass, bool allow, string fpath)
{
lastFuncName = "LoadBMP";
NOM = 45;
byte[] binArr = null;
byte[] pass = Methods.GetByteArray((uint)progPass, 2);
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(fpath);
byte[] img = new byte[bmp.Width / 8 * bmp.Height];
byte oneByte = 0x00;
int k = 0;
int wo = 0;
for (int h = 0, w = 0; h < bmp.Height; h++)
for (w = 0; w < (bmp.Width / 8 * 8); w += 8)
{
for (wo = 0; wo < 8; wo++)
{
oneByte <<= 1;
if (bmp.GetPixel(w + wo, h).Name == "ff000000")
oneByte |= 1;
}
img[k] = oneByte;
k++;
}
k = img.Length / 64;
if (img.Length % 64 != 0)
k++;
object[] imgBlocks = new object[k];
long idx = 0;
byte cs = 0;
for (k = 0; k < imgBlocks.Length; k++)
{
if (idx + 64 < img.Length)
binArr = new byte[64];
else
binArr = new byte[img.Length - idx];
Array.Copy(img, idx, binArr, 0, binArr.Length);
cs = (byte)(0 - Methods.SumMas(binArr));
Array.Resize<byte>(ref binArr, binArr.Length + 1);
binArr[binArr.Length - 1] = cs;
imgBlocks[k] = binArr;
idx += 64;
}
//Creating data
DataForSend = new byte[2 + 1 + 2 + 2];
DataForSend[0] = pass[0];
DataForSend[1] = pass[1];
if (allow)
DataForSend[2] = (byte)1;
else
DataForSend[2] = (byte)0;
binArr = Methods.GetByteArray(bmp.Width / 8 * 8, 2);
DataForSend[3] = binArr[0];
DataForSend[4] = binArr[1];
binArr = Methods.GetByteArray(bmp.Height, 2);
DataForSend[5] = binArr[0];
DataForSend[6] = binArr[1];
//Making data
InputData = CreateInputData(NOM, DataForSend);
//sending and getting data
if (!port.IsOpen)
port.Open();
byte[] buffer = new byte[1];
uint rb = 20;
int totRd = 20;
bool enqDetected = false;
port.Write(InputData);
for (k = 0; k < imgBlocks.Length; k++)
{
totRd = 20;
enqDetected = false;
buffer = new byte[1];
while (true)
{
if (totRd < 0)
break;
port.Read(ref buffer, out rb);
if (buffer[0] == ENQ)
{
port.PortClear();
enqDetected = true;
break;
}
if (buffer[0] == SYN)
continue;
totRd--;
}
if (!enqDetected)
break;
//.........这里部分代码省略.........