本文整理汇总了C#中System.IO.Ports.SerialPort.WriteLine方法的典型用法代码示例。如果您正苦于以下问题:C# SerialPort.WriteLine方法的具体用法?C# SerialPort.WriteLine怎么用?C# SerialPort.WriteLine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.Ports.SerialPort
的用法示例。
在下文中一共展示了SerialPort.WriteLine方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: connectDisplay
public static bool connectDisplay(SerialPort serial)
{
if (serial == null || !serial.IsOpen)
{
throw new Exception(StringResource.E00001);
}
string accessString = "";
try
{
accessString = serial.ReadLine();
}
catch (Exception)
{
//if Display is idle. Try to close it and reconnect
serial.WriteLine("close:");
try
{
accessString = serial.ReadLine();
}
catch (TimeoutException)
{
return false;
}
}
if (accessString == DisplayToAppAccessString)
{
serial.WriteLine(AppToDisplayAccessString);
return true;
}
return false;
}
示例2: identify
private bool identify(ref Dictionary<string, Arduino> _ArduinoMap, string _potentialArduino) {
if (!_ArduinoMap.ContainsKey(_potentialArduino)) {
SerialPort temp;
try {
temp = new SerialPort(_potentialArduino);
temp.Open();
string toWrite = Arduino_Codes.IDENTITY_QUERY;
temp.DiscardOutBuffer();
temp.DiscardInBuffer();
Thread.Sleep(100);
temp.WriteLine(toWrite);
Thread.Sleep(200);
temp.WriteLine(toWrite);
Thread.Sleep(200);
string ID = temp.ReadExisting();
if (ID.Contains(Arduino_Codes.ARM_IDENTITY_RESPONSE))
{
_ArduinoMap.Add(Arduino_Codes.ARM_IDENTITY, new Arduino(temp, Arduino_Codes.ARM_IDENTITY));
return true;
}
else if (ID.Contains(Arduino_Codes.HAND_IDENTITY_RESPONSE))
{
_ArduinoMap.Add(Arduino_Codes.HAND_IDENTITY, new Arduino(temp, Arduino_Codes.HAND_IDENTITY));
return true;
}
else if (ID.Contains(Arduino_Codes.DRIVEFRONT_IDENTITY_RESPONSE))
{
_ArduinoMap.Add(Arduino_Codes.DRIVEFRONT_IDENTITY, new Arduino(temp, Arduino_Codes.DRIVEFRONT_IDENTITY));
return true;
}
else if (ID.Contains(Arduino_Codes.DRIVEBACK_IDENTITY_RESPONSE))
{
_ArduinoMap.Add(Arduino_Codes.DRIVEBACK_IDENTITY, new Arduino(temp, Arduino_Codes.DRIVEBACK_IDENTITY));
return true;
}
else if (ID.Contains(Arduino_Codes.PT_IDENTITY_RESPONSE))
{
_ArduinoMap.Add(Arduino_Codes.PT_IDENTITY, new Arduino(temp, Arduino_Codes.PT_IDENTITY));
return true;
}
temp.Dispose(); //Gets rid of safe handle issue! Or at least appears to!
}
catch {
return false;
}
}
return false;
}
示例3: setLCDText
public static void setLCDText(SerialPort serial, string text)
{
if (serial == null || !serial.IsOpen)
{
throw new Exception(StringResources.E00001);
}
string[] splitedStr = text.Split('\n');
serial.WriteLine("lcd:print:" + splitedStr.Length);
serial.WriteLine(splitedStr[0]);
if (splitedStr.Length > 1)
{
serial.WriteLine(splitedStr[1]);
}
}
示例4: getIP
//ready
//c_G?RS??FjS? fJ[??
//[Vendor: www.ai-thinker.com Version:0.9.2.4]
//OK
//ready
//FAIL
private static string getIP(SerialPort sp)
{
string cmd = "AT+CIFSR";
string result;
string tmp;
while (true) {
do {
tmp = sp.ReadExisting();
Console.WriteLine(tmp);
} while (tmp != "");
sp.WriteLine(cmd);
Thread.Sleep(1000);
int end = 0, findMsg = 0; ;
int resultReadCnt = 10;
while ((findMsg == 0 || end == 0) && resultReadCnt-- > 0) {
result = sp.ReadExisting();
if (result.Contains(cmd)) findMsg = 1;
Console.WriteLine(result);
if (findMsg != 0 && ( result.Contains("192.168.16.") || result.Contains("192.168.137.") || result.Contains("192.168.10."))) return result; //Nieładnie, ale na razie - czekamy na IP
if (findMsg != 0 && result.Contains("0.0.0.0")) { Thread.Sleep(1000); break; } //Ponawiamy
Thread.Sleep(1000);
}
Thread.Sleep(5000);
}
return null;
}
示例5: Main
public static void Main(String[] Arguments)
{
foreach (var _COMPort in SerialPort.GetPortNames())
Console.WriteLine(_COMPort);
COMPort = new SerialPort("COM14", 9600, Parity.None, 8, StopBits.One);
COMPort.DataReceived += (s, e) => Console.Write(COMPort.ReadExisting());
COMPort.ReadTimeout = 4000;
COMPort.WriteTimeout = 6000;
try
{
COMPort.Open();
}
catch (UnauthorizedAccessException e)
{
Console.WriteLine(e.Message);
}
do
{
var CursorLeftPosition = Console.CursorLeft;
var line = Console.ReadLine();
Console.SetCursorPosition(CursorLeftPosition, Console.CursorTop -1);
COMPort.WriteLine(line);
Thread.Sleep(250);
} while (true);
}
示例6: SMSDevice_Status
public static string SMSDevice_Status(string comPort)
{
SerialPort port = new SerialPort();
String operatorString = "Error";
try
{
port.PortName = comPort;
if (!port.IsOpen)
{
port.Open();
}
port.WriteLine("AT+CREG?\r");
Thread.Sleep(2000);
operatorString = port.ReadExisting();
return operatorString;
}
catch
{
return operatorString;
}
finally
{
port.Close();
}
}
示例7: initComm
public void initComm(string portname)
{
if (ComPort != null)
{
ComPort.Close();
state = State.notConnected;
}
this.portname = portname;
try
{
ComPort = new SerialPort(this.portname, this.baudrate);
ComPort.Open();
state = State.connected;
ComPort.WriteLine(RESET);
state = State.reset;
ComPort.DataReceived += new SerialDataReceivedEventHandler(ComPort_DataReceived);
}
catch (Exception)
{
OnIncomingErrorEvent("WrongComPort");
try { ComPort.Close(); } catch (Exception) { } // probeer om de ComPort wel te sluiten.
state = State.notConnected;
}
}
示例8: HamegOsziAdapter
public HamegOsziAdapter(string port, int baudrate)
{
try{
log.Info("Try to connecto to measurment device on port " + port + " with baud rate " + baudrate.ToString());
dataPort = new SerialPort(port, baudrate);
dataPort.Open();
if(!dataPort.IsOpen)
{
log.Error("Could not open comport on " + port + " with baudrate " + baudrate);
dataPort.Close();
return;
}
dataPort.WriteLine("*IDN?");
System.DateTime start = DateTime.Now;
while(dataPort.BytesToRead == 0)
{
if((DateTime.Now - start).TotalMilliseconds > 1000)
{
log.Error("No device response to *IDN? within 1s!");
dataPort.Close();
return;
}
}
deviceInfo = dataPort.ReadExisting();
log.Info("Connected to device " + deviceInfo);
}
catch(Exception ex)
{
log.Error(ex);
}
}
示例9: Connect
public void Connect()
{
try
{
m_serialPort = new SerialPort(Properties.Settings.Default.LambdaZupAddress);
m_serialPort.BaudRate = 9600;
m_serialPort.Parity = Parity.None;
m_serialPort.DataBits = 8;
m_serialPort.StopBits = StopBits.One;
m_serialPort.Handshake = Handshake.XOnXOff;
m_serialPort.ReadTimeout = 2000;
m_serialPort.WriteTimeout = 1000;
m_serialPort.DtrEnable = true;
m_serialPort.RtsEnable = true;
m_serialPort.Open();
m_serialPort.WriteLine(":ADR01;:MDL?;");
}
catch (Exception ex)
{
throw new SBJException("Cannot Connect to LambdaZup device", ex);
}
}
示例10: JanelaPrincipal
public JanelaPrincipal()
{
InitializeComponent();
// Atribui o valor zero a posição
posicao = 0;
/* Cria um novo objeto SerialPort
* Que conecta a porta "COM3"
* E utiliza um Baud Rate (Taxa de Transmissão de dados) de 9600
*/
porta = new SerialPort("COM3", 9600);
//Verifica se a porta não está aberta
if (!porta.IsOpen)
{
// Abre a porta
porta.Open();
/* Envia o valor "000", para que o
* motor volte para a possição 0
*/
porta.WriteLine("000");
}
}
示例11: ToggleLight
public void ToggleLight(SerialPort oCon)
{
oCon.NewLine = "\r\n";
oCon.ReadTimeout = 1500;
oCon.WriteLine("ToggleLight!");
}
示例12: Main
static void Main(string[] args)
{
//SerialPort com4 = new SerialPort("COM4", 4800, Parity.None, 8, StopBits.One);
_com4 = new SerialPort("COM4", 38400, Parity.None, 8, StopBits.One);
_com4.DataReceived += (sender1, e1) =>
{
SerialPort port = sender1 as SerialPort;
string line = port.ReadLine();
Console.WriteLine(line);
};
_com4.Open();
//drive one reading from each measure available
Exec("$ID");
Console.ReadLine();
Console.WriteLine("start reading:");
Exec("$MM,2"); //slope distance
Exec("$GO");
Exec("$MM,4"); //height
Exec("$GO");
Console.ReadLine();
Exec("$MM,5");
Exec("$MM");
Exec("$GO");
Console.WriteLine("done");
Console.ReadLine();
string input;
while ((input = Console.ReadLine()) != null)
{
_com4.WriteLine(input + "\r\n");
}
}
示例13: clearLED
public static void clearLED(SerialPort serial)
{
if (serial == null || !serial.IsOpen)
{
throw new Exception(StringResources.E00001);
}
serial.WriteLine("led:clear:");
}
示例14: Main
/// <summary>
/// This is the zMain method.
/// </summary>
/// <remarks>
/// Some more info about zMain.
/// </remarks>
public static void Main()
{
string name;
string message;
StringComparer stringComparer = StringComparer.OrdinalIgnoreCase;
Thread readThread = new Thread(Read);
// Create a RegistryKey, which will access the HKEY_USERS
// key in the registry of this machine.
RegistryKey rk = Registry.LocalMachine;
RegistryKey sk = rk.OpenSubKey("SYSTEM\\CURRENTCONTROLSET\\ENUM\\USB");
// Print out the keys.
// UPrintKeys(" ", sk);
// Create a new SerialPort object with default settings.
_serialPort = new SerialPort( "COM6" );
// Set the read/write timeouts
_serialPort.ReadTimeout = 1000;
_serialPort.WriteTimeout = 1000;
_serialPort.Open();
_continue = true;
readThread.Start();
Console.Write("Name: ");
name = Console.ReadLine();
Console.WriteLine("Type QUIT to exit");
while (_continue)
{
message = Console.ReadLine();
if (stringComparer.Equals("quit", message))
{
_continue = false;
}
else
{
try
{
_serialPort.WriteLine(
String.Format("<{0}>: {1}", name, message));
}
catch
{
Console.WriteLine("Write Timeout");
}
}
}
readThread.Join();
_serialPort.Close();
}
示例15: close
public static void close(SerialPort serial)
{
if (serial.IsOpen)
{
clearLED(serial);
serial.WriteLine("close:");
serial.Close();
}
PSCloseDevice();
}