Click here to Skip to main content
Rate this: bad
good
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 4:12am
Edited 27-Mar-13 5:01am
_duDE_8.1K
v2
Comments
Jim Jos at 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 at 27-Mar-13 10:01am
   
Any specific reasons to use VB6?
—SA
CHill60 at 27-Mar-13 10:45am
   
He's trying to convert from VB6 to c#
Sergey Alexandrovich Kryukov at 27-Mar-13 10:58am
   
Ah, not I can see it; thank you.
—SA
ThePhantomUpvoter at 27-Mar-13 10:16am
   
You really need to look at the documentation for the SerialPort class.
Sergey Alexandrovich Kryukov at 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?
—SA

1 solution

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

Solution 1

SerialPort MSDN documentation here :
http://msdn.microsoft.com/en-us/library/system.io.ports.serialport.aspx[^]
 
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.
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 575
1 Kornfeld Eliyahu Peter 409
2 Maciej Los 369
3 DamithSL 196
4 OriginalGriff 188
0 OriginalGriff 6,353
1 DamithSL 4,854
2 Maciej Los 4,476
3 Kornfeld Eliyahu Peter 4,058
4 Sergey Alexandrovich Kryukov 3,917


Advertise | Privacy | Mobile
Web01 | 2.8.141223.1 | Last Updated 27 Mar 2013
Copyright © CodeProject, 1999-2014
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