i need to open a serial port send command 00 00 F0 00 00 and then receive the data from the port if he command received is F1 and data received is F1 D6 i need to open a file and write the data. and then again send the command F1 and if command received is F2 i need to close the file.
Asked
Active
Viewed 1,668 times
-2
-
similar question http://stackoverflow.com/questions/1243070/how-to-read-and-write-from-the-serial-port-in-c-sharp – Vamsi Aug 11 '12 at 07:10
2 Answers
1
You can use the SerialPort Class in .NET to accomplish this. Use Read(...)
and Write(...)
methods to accomplish your task.

Madushan
- 6,977
- 31
- 79
0
Firstly, you add serialPort1 tools in your form and after using
if (!sensport.IsOpen)
{
foreach (string port in SerialPort.GetPortNames())
{
sensport.PortName = port;
sensport.BaudRate = 9600;
MessageBox.Show(port + " is open");
}
label1.Text = "";
try
{
sensport.Open();
}
catch (Exception)
{
MessageBox.Show("Please control your connection");
}
}
that codes to open your port.
After that you need Write() and Read() method in serialPort1.

rhsn
- 51
- 1
- 7