串口操作类
using System;
using System.IO.Ports;
using System.Threading;
namespace TripodDemo
{
public class SerialTripo : IDisposable
{
private object objComm = new object();
private SerialPort com;
private bool disposed = false;
SerialPort
Dispose & Close
发送数据
/// <summary>
/// 操作设备(如开闸)
/// </summary>
/// <param name="macno">机号</param>
/// <returns>是否执行成功</returns>
public bool OpenStorbe(byte macno)
{
int retLen = 5;
byte[] br;
//构建命令
byte b1 = 0xEB;
byte b3 = 0x50;
byte b4 = 0x01;
byte xor = (byte)(b1 ^ macno ^ b3 ^ b4);
byte[] bw = { b1, macno, b3, b4, xor };
bool bRet = SendData(bw, retLen, out br, 1000);
if (bRet)
{
if (br[2] == 0xC0 && br[3] == 0x00)
{
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
}
}
using System.IO.Ports;
using System.Threading;
namespace TripodDemo
{
public class SerialTripo : IDisposable
{
private object objComm = new object();
private SerialPort com;
private bool disposed = false;
SerialPort
Dispose & Close
发送数据
/// <summary>
/// 操作设备(如开闸)
/// </summary>
/// <param name="macno">机号</param>
/// <returns>是否执行成功</returns>
public bool OpenStorbe(byte macno)
{
int retLen = 5;
byte[] br;
//构建命令
byte b1 = 0xEB;
byte b3 = 0x50;
byte b4 = 0x01;
byte xor = (byte)(b1 ^ macno ^ b3 ^ b4);
byte[] bw = { b1, macno, b3, b4, xor };
bool bRet = SendData(bw, retLen, out br, 1000);
if (bRet)
{
if (br[2] == 0xC0 && br[3] == 0x00)
{
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
}
}