Click here to Skip to main content
13,051,502 members (47,972 online)
Rate this:
Please Sign up or sign in to vote.
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:
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

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.
Posted 27-Mar-13 3:12am
Updated 27-Mar-13 4:01am
Jim Jos 27-Mar-13 9:40am
Did you try SerialPort class using the System.IO.Ports library? If you want we could work the new code using .NET ..
Sergey Alexandrovich Kryukov 27-Mar-13 10:01am
Any specific reasons to use VB6?
CHill60 27-Mar-13 10:45am
He's trying to convert from VB6 to c#
Sergey Alexandrovich Kryukov 27-Mar-13 10:58am
Ah, not I can see it; thank you.
ThePhantomUpvoter 27-Mar-13 10:16am
You really need to look at the documentation for the SerialPort class.
Sergey Alexandrovich Kryukov 27-Mar-13 11:00am
5! Will you post just the reference to the MSDN page on the class as a formal answer, to close the issue?

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

SerialPort MSDN documentation here :[^]

SerialPort comm = new SerialPort("COM1");
// 9600,n,8,1
comm.BaudRate = 9600;
comm.Parity = Parity.None;
comm.DataBits = 8;
comm.StopBits = StopBits.One;
// handShaking
comm.Handshake = Handshake.None;
comm.DtrEnable = true;

use comm.DataReceived event to be notified when data are received, and comm.Read to read it.

use comm.Write to write data.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170713.1 | Last Updated 27 Mar 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100