
Serial port communication in C# isn’t just another programming task—it’s your gateway to connecting with the physical world. I’ve spent countless hours debugging serial connections, and trust me, once you master this skill, you’ll unlock possibilities you never imagined.
Throughout this guide, I’ll walk you through everything from basic serial port detection to advanced data transmission techniques. Moreover, we’ll tackle the common pitfalls that trip up most developers.
What is Serial Port Communication in C#?
Serial port communication enables your C# applications to interact directly with hardware devices through COM ports. Whether you’re connecting to Arduino boards, industrial sensors, or legacy equipment, the .NET Framework provides robust built-in classes that make this communication seamless.
The beauty of C# serial port programming lies in its simplicity. You don’t need complex drivers or third-party libraries—everything you need comes standard with .NET.
Why Choose C# for Serial Communication?
C# dominates serial port programming for several compelling reasons:
- Built-in SerialPort class handles all low-level operations
- Cross-platform compatibility with .NET Core and .NET 5+
- Robust error handling mechanisms prevent application crashes
- Event-driven architecture supports asynchronous operations
- Strong typing reduces runtime errors significantly
Furthermore, C# serial port applications integrate seamlessly with Windows services, desktop applications, and even web APIs.
Essential Components for C# Serial Port Programming
Before diving into code, let’s understand the core components you’ll work with:
The SerialPort Class
The System.IO.Ports.SerialPort class serves as your primary interface. This powerful class encapsulates all serial communication functionality, from basic read/write operations to advanced buffer management.
Port Configuration Parameters
Every serial connection requires specific configuration:
- Baud Rate: Speed of data transmission (9600, 115200, etc.)
- Data Bits: Number of data bits per frame (typically 8)
- Parity: Error checking method (None, Even, Odd)
- Stop Bits: End-of-frame indicators (One, Two)
- Flow Control: Data flow management (None, Hardware, Software)
Detecting Available Serial Ports
First things first—you need to discover which ports exist on your system. I always start my serial applications with port detection because it prevents connection failures later.
using System;
using System.Collections.Generic;
using System.IO.Ports;
public class SerialPortManager
{
public List<string> GetAvailablePorts()
{
List<string> availablePorts = new List<string>();
foreach (string portName in SerialPort.GetPortNames())
{
availablePorts.Add(portName);
}
return availablePorts;
}
public void DisplayAvailablePorts()
{
var ports = GetAvailablePorts();
if (ports.Count == 0)
{
Console.WriteLine("No serial ports detected on this system.");
return;
}
Console.WriteLine($"Found {ports.Count} serial ports:");
foreach (string port in ports)
{
Console.WriteLine($"- {port}");
}
}
}Code language: PHP (php)This method returns port names like “COM1”, “COM2”, etc. However, sometimes you need more detailed information about each port.
Advanced Port Detection with WMI
When you need comprehensive port information including hardware details, WMI queries become invaluable:
using System.Management;
using System.Collections.Generic;
public class AdvancedPortDetection
{
public List<SerialPortInfo> GetDetailedPortInfo()
{
List<SerialPortInfo> portDetails = new List<SerialPortInfo>();
using (ManagementObjectSearcher searcher =
new ManagementObjectSearcher("SELECT * FROM Win32_PnPEntity WHERE ClassGuid=\"{4d36e978-e325-11ce-bfc1-08002be10318}\""))
{
foreach (ManagementObject port in searcher.Get())
{
if (port["Name"] != null && port["Name"].ToString().Contains("COM"))
{
var portInfo = new SerialPortInfo
{
Name = port["Name"]?.ToString(),
DeviceID = port["DeviceID"]?.ToString(),
Description = port["Description"]?.ToString()
};
portDetails.Add(portInfo);
}
}
}
return portDetails;
}
}
public class SerialPortInfo
{
public string Name { get; set; }
public string DeviceID { get; set; }
public string Description { get; set; }
}Code language: PHP (php)Establishing Serial Port Connections
Opening a serial port connection correctly prevents 90% of communication issues. I’ve learned this through trial and error, so let me save you the headache.
using System;
using System.IO.Ports;
public class SerialConnection
{
private SerialPort _serialPort;
public bool OpenConnection(string portName, int baudRate = 9600)
{
try
{
_serialPort = new SerialPort(portName)
{
BaudRate = baudRate,
DataBits = 8,
Parity = Parity.None,
StopBits = StopBits.One,
Handshake = Handshake.None,
ReadTimeout = 3000,
WriteTimeout = 3000
};
if (!_serialPort.IsOpen)
{
_serialPort.Open();
Console.WriteLine($"Successfully connected to {portName}");
return true;
}
}
catch (UnauthorizedAccessException)
{
Console.WriteLine($"Access denied to {portName}. Port may be in use.");
return false;
}
catch (ArgumentException)
{
Console.WriteLine($"Invalid port name: {portName}");
return false;
}
catch (InvalidOperationException)
{
Console.WriteLine($"Port {portName} is already open.");
return false;
}
return false;
}
public void CloseConnection()
{
if (_serialPort?.IsOpen == true)
{
_serialPort.Close();
_serialPort.Dispose();
Console.WriteLine("Serial connection closed successfully.");
}
}
}Code language: PHP (php)Notice how I set specific timeout values—this prevents your application from hanging indefinitely when devices don’t respond.
Sending Data Through Serial Ports
Data transmission forms the heart of serial communication. Nevertheless, different devices expect different data formats, so flexibility becomes crucial.
Sending String Data
Most serial devices accept human-readable string commands:
public class SerialDataSender
{
private SerialPort _port;
public SerialDataSender(SerialPort port)
{
_port = port;
}
public bool SendString(string data)
{
if (!_port.IsOpen)
{
Console.WriteLine("Port is not open for sending data.");
return false;
}
try
{
_port.WriteLine(data);
Console.WriteLine($"Sent: {data}");
return true;
}
catch (TimeoutException)
{
Console.WriteLine("Timeout occurred while sending data.");
return false;
}
catch (InvalidOperationException ex)
{
Console.WriteLine($"Error sending data: {ex.Message}");
return false;
}
}
}Code language: PHP (php)Sending Binary Data
Industrial devices often require precise binary commands. Here’s how I handle byte array transmission:
public class BinaryDataSender
{
private SerialPort _port;
public BinaryDataSender(SerialPort port)
{
_port = port;
}
public bool SendBinaryData(byte[] data)
{
if (!_port.IsOpen)
{
Console.WriteLine("Port is not open for binary transmission.");
return false;
}
try
{
// Clear buffers before sending
_port.DiscardInBuffer();
_port.DiscardOutBuffer();
_port.Write(data, 0, data.Length);
Console.WriteLine($"Sent {data.Length} bytes: {BitConverter.ToString(data)}");
return true;
}
catch (Exception ex)
{
Console.WriteLine($"Binary transmission failed: {ex.Message}");
return false;
}
}
public bool SendHexCommand(string hexString)
{
try
{
// Convert hex string to byte array
byte[] bytes = new byte[hexString.Length / 2];
for (int i = 0; i < bytes.Length; i++)
{
bytes[i] = Convert.ToByte(hexString.Substring(i * 2, 2), 16);
}
return SendBinaryData(bytes);
}
catch (Exception ex)
{
Console.WriteLine($"Hex command conversion failed: {ex.Message}");
return false;
}
}
}Code language: PHP (php)Receiving Data from Serial Devices
Data reception requires more finesse than sending because you never know exactly when devices will respond. Additionally, different devices send data in various formats.
Synchronous Data Reading
For simple request-response scenarios, synchronous reading works perfectly:
public class SerialDataReceiver
{
private SerialPort _port;
public SerialDataReceiver(SerialPort port)
{
_port = port;
}
public string ReadStringData(int timeoutMs = 3000)
{
if (!_port.IsOpen)
{
Console.WriteLine("Port is not open for reading.");
return null;
}
try
{
_port.ReadTimeout = timeoutMs;
string receivedData = _port.ReadLine();
Console.WriteLine($"Received: {receivedData}");
return receivedData.Trim();
}
catch (TimeoutException)
{
Console.WriteLine("Timeout occurred while reading data.");
return null;
}
catch (Exception ex)
{
Console.WriteLine($"Error reading data: {ex.Message}");
return null;
}
}
public byte[] ReadBinaryData(int expectedBytes, int timeoutMs = 3000)
{
if (!_port.IsOpen)
return null;
try
{
_port.ReadTimeout = timeoutMs;
byte[] buffer = new byte[expectedBytes];
int bytesRead = _port.Read(buffer, 0, expectedBytes);
if (bytesRead > 0)
{
byte[] actualData = new byte[bytesRead];
Array.Copy(buffer, actualData, bytesRead);
return actualData;
}
}
catch (TimeoutException)
{
Console.WriteLine("Timeout while reading binary data.");
}
return null;
}
}Code language: PHP (php)Asynchronous Data Reception
For continuous monitoring or real-time applications, event-driven reception becomes essential:
public class AsyncSerialReceiver
{
private SerialPort _port;
private bool _isListening = false;
public event EventHandler<string> DataReceived;
public event EventHandler<byte[]> BinaryDataReceived;
public AsyncSerialReceiver(SerialPort port)
{
_port = port;
_port.DataReceived += OnDataReceived;
}
private void OnDataReceived(object sender, SerialDataReceivedEventArgs e)
{
if (!_isListening)
return;
try
{
if (_port.BytesToRead > 0)
{
// Read as string
string stringData = _port.ReadExisting();
if (!string.IsNullOrEmpty(stringData))
{
DataReceived?.Invoke(this, stringData);
}
// For binary data reception
if (_port.BytesToRead > 0)
{
byte[] binaryData = new byte[_port.BytesToRead];
_port.Read(binaryData, 0, binaryData.Length);
BinaryDataReceived?.Invoke(this, binaryData);
}
}
}
catch (Exception ex)
{
Console.WriteLine($"Error in async data reception: {ex.Message}");
}
}
public void StartListening()
{
_isListening = true;
Console.WriteLine("Started listening for serial data...");
}
public void StopListening()
{
_isListening = false;
Console.WriteLine("Stopped listening for serial data.");
}
}Code language: PHP (php)Complete Serial Communication Example
Here’s a comprehensive example that demonstrates bidirectional communication with proper error handling:
using System;
using System.IO.Ports;
using System.Threading;
public class CompleteSerialExample
{
private SerialPort _serialPort;
private bool _isConnected = false;
public bool Initialize(string portName, int baudRate = 9600)
{
try
{
_serialPort = new SerialPort(portName)
{
BaudRate = baudRate,
DataBits = 8,
Parity = Parity.None,
StopBits = StopBits.One,
Handshake = Handshake.None,
ReadTimeout = 2000,
WriteTimeout = 2000
};
_serialPort.DataReceived += OnDataReceived;
_serialPort.Open();
_isConnected = true;
Console.WriteLine($"Serial communication initialized on {portName}");
return true;
}
catch (Exception ex)
{
Console.WriteLine($"Initialization failed: {ex.Message}");
return false;
}
}
public string SendCommand(string command, int responseTimeoutMs = 3000)
{
if (!_isConnected || !_serialPort.IsOpen)
{
Console.WriteLine("Serial port is not connected.");
return null;
}
try
{
// Clear buffers
_serialPort.DiscardInBuffer();
_serialPort.DiscardOutBuffer();
// Send command
_serialPort.WriteLine(command);
Console.WriteLine($"Sent command: {command}");
// Wait for response
DateTime startTime = DateTime.Now;
while ((DateTime.Now - startTime).TotalMilliseconds < responseTimeoutMs)
{
if (_serialPort.BytesToRead > 0)
{
string response = _serialPort.ReadExisting();
Console.WriteLine($"Received response: {response.Trim()}");
return response.Trim();
}
Thread.Sleep(10); // Small delay to prevent CPU spinning
}
Console.WriteLine("Response timeout occurred.");
return null;
}
catch (Exception ex)
{
Console.WriteLine($"Command execution failed: {ex.Message}");
return null;
}
}
private void OnDataReceived(object sender, SerialDataReceivedEventArgs e)
{
try
{
string data = _serialPort.ReadExisting();
Console.WriteLine($"Async data received: {data}");
}
catch (Exception ex)
{
Console.WriteLine($"Error in data reception: {ex.Message}");
}
}
public void Dispose()
{
if (_serialPort?.IsOpen == true)
{
_serialPort.Close();
}
_serialPort?.Dispose();
_isConnected = false;
Console.WriteLine("Serial connection disposed.");
}
}
// Usage example
class Program
{
static void Main()
{
var serialComm = new CompleteSerialExample();
if (serialComm.Initialize("COM3", 115200))
{
// Send test commands
string response1 = serialComm.SendCommand("AT");
string response2 = serialComm.SendCommand("AT+VERSION");
// Keep program running for async reception
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
}
serialComm.Dispose();
}
}Code language: PHP (php)Tip💡: Learn more about multithreaded programming c#.
Advanced Serial Port Techniques
Handling Different Line Endings
Different devices use various line ending conventions. Here’s how I handle this challenge:
public enum LineEnding
{
CR, // \r
LF, // \n
CRLF, // \r\n
None
}
public class LineEndingHandler
{
public static string ApplyLineEnding(string data, LineEnding ending)
{
switch (ending)
{
case LineEnding.CR:
return data + "\r";
case LineEnding.LF:
return data + "\n";
case LineEnding.CRLF:
return data + "\r\n";
default:
return data;
}
}
public static string RemoveLineEndings(string data)
{
return data.Replace("\r", "").Replace("\n", "");
}
}Code language: PHP (php)Custom Protocol Implementation
For complex devices, you’ll often need custom protocols:
public class CustomProtocolHandler
{
private const byte STX = 0x02; <em>// Start of text</em>
private const byte ETX = 0x03; <em>// End of text</em>
public byte[] CreateFrame(byte[] data)
{
// Calculate checksum
byte checksum = 0;
foreach (byte b in data)
{
checksum ^= b;
}
// Build frame: STX + Data + Checksum + ETX
byte[] frame = new byte[data.Length + 3];
frame[0] = STX;
Array.Copy(data, 0, frame, 1, data.Length);
frame[frame.Length - 2] = checksum;
frame[frame.Length - 1] = ETX;
return frame;
}
public bool ValidateFrame(byte[] frame, out byte[] data)
{
data = null;
if (frame.Length < 3 || frame[0] != STX || frame[frame.Length - 1] != ETX)
{
return false;
}
// Extract data and validate checksum
data = new byte[frame.Length - 3];
Array.Copy(frame, 1, data, 0, data.Length);
byte receivedChecksum = frame[frame.Length - 2];
byte calculatedChecksum = 0;
foreach (byte b in data)
{
calculatedChecksum ^= b;
}
return receivedChecksum == calculatedChecksum;
}
}Code language: PHP (php)Troubleshooting Common Issues
Port Access Denied
This happens frequently when multiple applications try to access the same port:
public static bool IsPortAvailable(string portName)
{
try
{
using (var port = new SerialPort(portName))
{
port.Open();
return true;
}
}
catch (UnauthorizedAccessException)
{
return false;
}
catch
{
return false;
}
}Code language: PHP (php)Buffer Overflow Prevention
Large data streams can overflow buffers. Here’s how I prevent this:
public class BufferManager
{
private SerialPort _port;
private const int MAX_BUFFER_SIZE = 4096;
public void MonitorBuffer()
{
if (_port.BytesToRead > MAX_BUFFER_SIZE * 0.8)
{
Console.WriteLine("Buffer approaching capacity. Clearing...");
_port.DiscardInBuffer();
}
}
}Code language: PHP (php)Performance Optimization Tips
- Use appropriate buffer sizes for your data volume
- Implement proper timeout values to prevent blocking
- Clear buffers regularly to prevent memory issues
- Use asynchronous methods for continuous monitoring
- Dispose connections properly to free system resources
Best Practices for Production Applications
Connection Management
Always implement proper connection lifecycle management:
public class ProductionSerialManager : IDisposable
{
private SerialPort _port;
private Timer _connectionWatchdog;
private bool _disposed = false;
public bool IsConnected => _port?.IsOpen ?? false;
public void StartWatchdog()
{
_connectionWatchdog = new Timer(CheckConnection, null,
TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(5));
}
private void CheckConnection(object state)
{
if (!IsConnected)
{
Console.WriteLine("Connection lost. Attempting reconnection...");
// Implement reconnection logic
}
}
public void Dispose()
{
if (!_disposed)
{
_connectionWatchdog?.Dispose();
_port?.Close();
_port?.Dispose();
_disposed = true;
}
}
}Error Logging
Implement comprehensive logging for production environments:
public class SerialLogger
{
private static readonly string LogPath = "serial_communication.log";
public static void LogError(string message, Exception ex = null)
{
string logEntry = $"[{DateTime.Now:yyyy-MM-dd HH:mm:ss}] ERROR: {message}";
if (ex != null)
{
logEntry += $"\nException: {ex.Message}\nStack Trace: {ex.StackTrace}";
}
File.AppendAllText(LogPath, logEntry + Environment.NewLine);
}
public static void LogInfo(string message)
{
string logEntry = $"[{DateTime.Now:yyyy-MM-dd HH:mm:ss}] INFO: {message}";
File.AppendAllText(LogPath, logEntry + Environment.NewLine);
}
}Code language: PHP (php)Conclusion
C# serial port communication opens up endless possibilities for hardware integration. From simple Arduino projects to complex industrial automation, the techniques covered in this guide will serve you well.
Remember these key takeaways:
- Always detect ports before attempting connections
- Implement proper error handling and timeout mechanisms
- Use asynchronous methods for continuous monitoring
- Clear buffers regularly to prevent data corruption
- Dispose resources properly to maintain system stability
The examples provided here form a solid foundation for any serial communication project. Moreover, the modular approach allows you to adapt these techniques to your specific requirements. Learn more about the SearialPort class on microsoft’s official documentaiton.
Start with basic connections and gradually implement advanced features as your project demands. Most importantly, test thoroughly with your target hardware—every device has its quirks that require fine-tuning.
With these tools in your arsenal, you’re ready to bridge the gap between software and hardware like never before. The physical world awaits your C# applications!
Discover more from CodeSamplez.com
Subscribe to get the latest posts sent to your email.


Thank You Very Much For This tutorial
I got The New Idea & Concepts To Connect Serial Port
Its Realy HelpFul.
Sandip Shinde
NetSolution Technogies
how to read com port with using .net?
i need code to read data from atmel 4 pin microcontroller and write data on it again it is on the board
i like this blog, lot of big things described in light manner..!!
Maybe you should write a little bit about the SerialObj and tmrComm, where did they came from ??
Hi, thanks for noticing. tmrComm should have been shown to be initialized earlier. It is of type “CommTimer” as given in the code. Also “SerialObj” is of type SerialPort
Were is the CommTimer type found??
Hi Phil, I am not sure what is your actually question is. However, there was a small issue in the c# code example as initialization of “tmrComm” variable of type “CommTimer” wasn’t done in proper way. I have modified it. But, if you have something else question, please explain.
Thanks for the reply, my question is what assembly is “CommTimer” in?
Oh yes. I very much appreciate your catch. I thought I did shared it too, but didn’t, just realised after your question. Thanks a lot. I just added that class definition as well. Hope this helps. Please let me know if you still having any issue/have more feedbacks.
Thanks very much for the additional code, its working now 🙂
Hi Rana,
Do you have a complete code rather than bits and pieces? I am trying to understand how you are calling SendReceiveData. Can you please revert with the entire code please. Unfortunately i am new in C#. Any help will be greatly appreciated.
Thanks
thanks a lot for the tutorial.Can you make a tutorial or guid me to writing device drivers for serial port devices?
You mean you want to write driver software for serial port accessible devices? If so, you must need to have the command set that the device accepts and what it replies in response. If you got that, you can even use this article to send and receive data.
WIN_SERIAL_OBJECT_NAME Where is this command form can’t find it sorry I’m a Nube. Is it a Placeholder or a Proper .Net Command
That is simply a constant where you will have to mention your target object name. Hope this helps.
here is an alternative explanation, with code and you can download to make tests
ps:if you have only USB ports you can “virtualize” a serial port using the USB port:
– connect with an adapter to de USB port
– install te drivers and select a new created virtualized serial port (in my case COM3)
– uninstall the printer in the control panel printer window (quit device)
– is very important to quit the printer because if not, the port is taken by the printer and when you’re trying to open the port will be an error (“The given port name does not start with COM/com or does not resolve to a valid serial port”)
try it. it works great.
http://msmvps.com/blogs/coad/archive/2005/03/23/SerialPort-_2800_RS_2D00_232-Serial-COM-Port_2900_-in-C_2300_-.NET.aspx%5B^]
not helpful, there are a lot of simpler ways to do this
There could be, for sure. Why don’t you just share some way/link, I will be happy to share with my readers.
Can we use serial port communication with AVR micro-controller?
Not sure about that, haven’t tried yet.
I am getting error at “Applicatio.DoEvent”. how to resolve it?
I am using WPF
You can try with this solution, this might help: http://stackoverflow.com/questions/19007288/alternative-to-application-doevents-in-wpf
Can you to get punch in and out data from PunchMachine using above code
showing error::: ‘Timer’ is an ambiguous reference between ‘System.Windows.Forms.Timer’ and ‘System.Timers.Timer’…what to do plz help
How can I send binary file to the GPS device via serial port communication, want to update firmware of device using C#..
can you please reply me I need your help..
Regards,
Abhi
Hello Md Ali Ahsan Rana
my problem is that i trying to get input from Weight machine ( Connection= USB, Company=DYMO Endicia Postage Technology,Item No=ES-7500UBLK) in web application in asp.net.Please give me any code if you have for this.
Thanks in advance
Please help me . Does it need all ping or which pings need mainly to receive and send data from computer and other device.
hi . i m working with rfeid serial module , i want to use with it .net apllication i want to know that which approach is better ?
1 : to open serial port when software is running at startup
2: or open serial port when needed after communication close it
please reply .
Its always wise to make connection on demand(when needed) always without unnecessarily keeping a connection open, unless some exceptional cases.
then why sometimes it give error that serial port cannot be opened after several communications ?
Hi i have a problem with communicating with a serial scale. If i use ReadLine() i get no values, but if i use ReadExisting() i get a constant string for e.g. 40 would show as 40404040404040
How do i get around this?
I have problem, it seems like i have nothing to read, it is always stuck here
while ((SerialObj.BytesToRead == 0) && (tmrComm.timedout == false))
I am using METEX ME 32 prahistoric device, which measures temperature, voltage.. i have been using using USB converter, it’sturned on, and shows value on it’s screen, but program doesnt seen it.
aoa . i have a project in which i draw in drawing and same thing is drawn in glcd. through serial communication ,
byte[] buffer_2_send = new byte[1];
byte data_2_send = 0;
data_2_send = Byte.Parse(textBox2.Text);//this way you will get the value 12 in your variable
//we will use a buffer because the serial_port.Write takes either a string or a buffer of data
buffer_2_send[0] = data_2_send;
MessageBox.Show(“” + buffer_2_send + ” ” + buffer_2_send.Length);
serialPort1.Write(buffer_2_send, 0, buffer_2_send.Length);
i basicaly send 12 or like this values on microcontroller
but at recieving side i cant recieve respective value so plz guide me
Thank You Great Work
If you have an application that writes to a serial port device through a USB adapter, and the application is hard-coded to use COM port 5, is there anything you can do so that moving a laptop that uses this application from one docking station to another will NOT cause Windows Plug and Play to assign a different COM port based on the VID of the second USB-to-serial device being different from the VID of the first USB-to- serial adapter?
The docking stations both use the same peripherals, all plugged into the same USB ports.
The users of these laptops don’t have administrative rights to change the COM port in Device Manager.
Some USB-to-serial adapters advertise ‘COM port retention’, but that only seems to make the laptop use the same COM port for the exact same USB-to-serial adapter (the very same one, not just one that ‘seems’ the same but has a different VID) each time the laptop is connected to that device.
Thanks,
hey.. i need to communicate with devices that are connected by usb in wpf application… can you please guide me in this.. i am newbie in this..
what assembly is “CommTimer” in?
System.IO.Ports.SerialPort myPort = new System.IO.Ports.SerialPort(“COM4”);
if (myPort.IsOpen == false) //if not open, open the port
myPort.Open()
error message:
A device attached to the system is not functioning.
thanks i ask you a question i have a software well working in serial port can i use this software over usb port without any change in software
Hi.excuse me for my bad English!I want to write a program in c# that print papers with Olivetti pr4sl slip printer.but I can’t communicate with this printer and don’t know how to send text directly to this printer in my program.can you help me for this?this printer connected to my pc with COM port and doesn’t have any driver.thanks
Good afternoon all,
I need to develop a LIMS(Lab integrated management system) using Asp.net and it should be bidirectional communication that means need to send the data of patient with tests,sample id,date etc to machine and need to get the results back to the computers from machines.Please help me how i can do
By SerialObj.DiscardInBuffer(); you are flushing data in the Serial Port buffer only. Data still remains in the base stream object, which will pop up on reading the port.
So, in addition, do SP.BaseStream.Flush() to really get rid af all existing data
Can u tell me how to code a program to record the exact time when serial port data arrives in visual studio in C#
I am getting error at “Applicatio.DoEvent”. how to resolve it?
Hello Can this code work with laboratory device????
where are these codes used? I am new to this. Are these codes used in MS-Dos ?
In what environment are these codes run in? I tried visual studio but get all kinds of errors. Are there included files that do not show in the codes documented here? Is this C#?