本文整理汇总了C#中System.IO.Ports.SerialDataReceivedEventArgs类的典型用法代码示例。如果您正苦于以下问题:C# SerialDataReceivedEventArgs类的具体用法?C# SerialDataReceivedEventArgs怎么用?C# SerialDataReceivedEventArgs使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SerialDataReceivedEventArgs类属于System.IO.Ports命名空间,在下文中一共展示了SerialDataReceivedEventArgs类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: port_DataReceived
public static void port_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
if (e.EventType == SerialData.Chars)
{
receiveNow.Set();
}
}
示例2: ReceivedComData
private void ReceivedComData(object sender, SerialDataReceivedEventArgs e)
{
try
{
while (true)
{
int nCount = 1;
byte[] preamble = new byte[nCount];
iSerialPort.Read(preamble, 0, nCount);
if (preamble[0] == '!')
{
nCount = 6;
byte[] header = new byte[nCount];
int nBytes = iSerialPort.Read(header, 0, nCount);
if (nBytes != nCount)
{
iSerialPort.Read(header, nBytes, nCount-nBytes);
}
if (callback != null)
{
callback(header);
}
}
}
}
catch (System.Exception ex)
{
string msg = ex.Message;
}
}
示例3: Port_DataReceived
public static void Port_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
while(Port.IsOpen && Port.BytesToRead > 0)
{
int i = Port.ReadByte();
if (i != '\r')
{
if (i != '\n')
{
Line[Index++] = (char)i;
}
}
else
{
string line = new string(Line, 0, Index);
foreach (GRBL.LineReceivedHandler d in OnLineReceived.GetInvocationList())
{
d.Invoke(line);
}
Index = 0;
}
}
}
示例4: DataReceivedHandler
private static void DataReceivedHandler(
object sender,
SerialDataReceivedEventArgs e)
{
SerialPort sp = (SerialPort)sender;
string indata = sp.ReadExisting();
}
示例5: comport_DataReceived
void comport_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
// This method will be called when there is data waiting in the port's buffer
// Determain which mode (string or binary) the user is in
// Read all the data waiting in the buffer
try
{
string data = "";
data = comport.ReadLine();//.ReadExisting();
string s = "";
// Display the text to the user in the terminal
if (bUseHexDecode)
s = Utility.HexEncoding.ToMixedString(data);
else
s = data;
txtReceive.Invoke(new EventHandler(delegate { txtReceive.Text += "<" + s + "\r\n"; })); //added < to mark incoming data
}
catch (Exception ex)
{
txtReceive.Invoke(new EventHandler(delegate { txtReceive.Text += ex.Message + "\r\n"; }));
//MessageBox.Show(ex.Message);
}
//label2.Invoke(new EventHandler(delegate{label2.Text = data;}));
//Log(LogMsgType.Incoming, data);
}
示例6: port_DataReceived
void port_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
SerialPort port = (SerialPort)sender;
int layer = 0;
if (port.PortName == ports["1st"].PortName) layer = 0;
if (port.PortName == ports["2nd"].PortName) layer = 1;
if (port.PortName == ports["3rd"].PortName) layer = 2;
string code = port.ReadLine();
var result = from box in packs[layer]
where !box.HasBarcode
select box;
if (result.Count() > 0)
{ result.First().Barcode = code; }
else
{
if (layer > 0)
MessageBox.Show(string.Format("尚不存在需要赋码的{0}级包装,不准提前赋码!", layer + 1));
else
packs.Add(layer, new DrugBox(code, layer));
}
this.BeginInvoke(new MethodInvoker(
delegate
{
ShowPacks();
}));
}
示例7: serialPort_DataReceived
private void serialPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
RxString = serialPort.ReadExisting();
if (!serialIntercept)
{
if (oldEntry != RxString)
{
this.Invoke(new EventHandler(serialRecived));
oldEntry = RxString;
}
}
else
{
switch (FromIntecepted)
{
case "Add":
AddCard.TagAdd(RxString);
break;
case "Remove":
RemoveCard.TagAdd(RxString);
break;
default:
serialIntercept = false;
break;
}
}
}
示例8: Arduino_DataReceived
private void Arduino_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
try
{
rx_data = new byte[arduino.BytesToRead];
// read the data
read_count = arduino.Read(rx_data, 0, rx_data.Length);
lastMessage += Encoding.ASCII.GetString(rx_data, 0, read_count);
if (lastMessage.IndexOf("*") > -1)
{
message = lastMessage;
lastMessage = "";
this.Invoke(new EventHandler(WriteData));
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
示例9: arduino_DataReceived
void arduino_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
this.Invoke(new MethodInvoker(delegate
{
ReadCode(sender, e);
}));
}
示例10: DataReceived
private static void DataReceived(object sender, SerialDataReceivedEventArgs e)
{
var port = (SerialPort) sender;
while (port.BytesToRead > 0)
{
int b = port.ReadByte();
if (b == -1)
continue;
Command command = ToCommand(b);
if (command == Command.Unknown)
{
Debug.Print(b.ToString("X2"));
continue;
}
var led = (OutputPort) Led[command];
bool newValue = !led.Read();
led.Write(newValue);
string response = (char) b + "=" + (newValue ? "on" : "off") + "\r\n";
byte[] buffer = Encoding.UTF8.GetBytes(response);
port.Write(buffer, 0, buffer.Length);
}
}
示例11: serialPort_DataReceived
void serialPort_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
SerialPort sp = (SerialPort)sender;
string indata = sp.ReadExisting();
//output.Text += "Data Received:\r\n";
output.Text += indata; // +"\r\n";
output.SelectionStart = output.Text.Length;
output.SelectionLength = 0;
output.ScrollToCaret();
//if (IsLoadingLua)
//{
// output.SelectionStart = StartingLinePosition;
// output.SelectionLength = output.TextLength - StartingLinePosition;
// //output.Copy();
// //LuaCodeTextbox.Clear();
// //LuaCodeTextbox.Paste();
// Clipboard.Clear();
// Clipboard.SetText(output.SelectedText);
// LuaCodeTextbox.Clear();
// LuaCodeTextbox.Text = Clipboard.GetText();
// IsLoadingLua = false;
//}
lastSerialActivity = DateTime.Now;
}
示例12: DataRecievedHandler
private void DataRecievedHandler(object sender, SerialDataReceivedEventArgs e)
{
// returns the ID read from tag, provides easteregg.
var serp = (SerialPort) sender;
// var dbm = new DatabaseManager();
var DiagnosticID = "4510720867";
var BlueOysterID = "4519992145";
rfid = serp.ReadExisting().Trim();
Engine.QueueOfRfids.Enqueue(rfid);
//Console.WriteLine(rfid);
if (rfid == DiagnosticID)
{
// Play blue oyster soundtrack.
//Console.WriteLine("Dun duu du du duuu duu duuu");
//Diagnostic = true;
//if (Diagnostic)
// {
//// PrintDiagnosticData(DiagnosticID);
// }
//}
if (rfid == BlueOysterID)
{
// AudioPlayer ap = new AudioPlayer("Blue Oyster Bar.wav");
// ap.Play();
}
}
}
示例13: DataReceivedHandler
private void DataReceivedHandler(object sender,SerialDataReceivedEventArgs e)
{
SerialPort reader = (SerialPort)sender;
int buff=0;
List<byte> list = new List<byte>();
byte[] buffer_rd = new byte[reader.BytesToRead];
do
{
try
{
buff = reader.ReadByte();
}
catch (System.IO.IOException E)
{
//TODO: Handle
}
list.Add((byte)buff);
} while (reader.BytesToRead > 0);
//await reader.BaseStream.ReadAsync(buffer_rd, 0, buffer_rd.Length, System.Threading.CancellationToken.None);
//Debug.WriteLine("{0} Bytes recieved", list.Count);
list.AddRange(buffer_rd);
foreach (byte to_push in list)
{
parser.push_byte(to_push);
}
buff=0;
}
示例14: sp_DataReceived
public void sp_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
data = _serialPort.ReadExisting();
globald = data;
data = "";
this.BeginInvoke(new SetTextDeleg(si_DataReceived));
}
示例15: DataReceivedHandler
private static void DataReceivedHandler(object sender, SerialDataReceivedEventArgs e)
{
SerialPort sp = (SerialPort)sender;
string indata = sp.ReadExisting();
Console.Write("Data Received:");
Console.WriteLine(indata);
}