Click here to Skip to main content
15,893,668 members

Serial Port Comunication in C#

Lucas Lo Faro asked:

Open original thread
Hello, It's the first time I make a post here, everyone tells me that is the best place to ask for help..
I'm making a project in C# (Windows Forms) about an intelligent house with facial recognition, fingerprints detector, an alarm system and access to the DVR (videocameras manager) and stuff like that.

The problem is that I have an electronical interface that I made myself which reads from the alarm's sensors and sends strong electrical signals using the Serial Port (USB Adapter). (For example, to turn on the lights in a room, the air conditioning, or reading data from the sensor of the alarm)
I used to have it working with a VB6 code that I'll give you next in another project..
It's made using the MSCOMM32.OCX library, I didn't make the code, but I understand it..
The thing is that I need to convert this code using the Serial Component used nowadays in .NET which has different properties that I can't assimilate.

This is the code in VB6:
VB
Private Sub Form_Load()
//MScomm Configuration.
MSComm1.CommPort = 1
MSComm1.Settings = "9600,n,8,1"
MSComm1.InputLen = 0
MSComm1.Handshaking = comNone
MSComm1.RThreshold = 1
MSComm1.SThreshold = 1
MSComm1.DTREnable = True
MSComm1.PortOpen = True

outputs = 0
Text1.Text = outputs
MSComm1.Output = Chr(&H31)
MSComm1.Output = Chr(outputs)

command= &H37
MSComm1.Output = Chr(command)
Timer1.Enabled = True
index = &H80
Text2.Text = 253
Text3.Text = 200
Text4.Text = 400

End Sub


VB
Private Sub MSComm1_OnComm()

If MSComm1.CommEvent = comEvReceive Then
input = MSComm1.Input
 ......
End Sub


I just need to know what are the similar events and properties to configurate the Serial component..
It would be REALLY helpfull..
Thanks in Advance, Lucas.
Tags: C#, Visual Basic 6, Serial port, Serial

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900