Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
1.00/5 (1 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:
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.
Posted
Updated 27-Mar-13 4:01am
v2
Comments
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?
—SA
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.
—SA
[no name] 27-Mar-13 10:16am    
You really need to look at the documentation for the SerialPort class.

1 solution

SerialPort MSDN documentation here :
http://msdn.microsoft.com/en-us/library/system.io.ports.serialport.aspx[^]

C#
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;

comm.Open();

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

use comm.Write to write data.
 
Share this answer
 

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



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