Click here to Skip to main content
15,917,997 members
Home / Discussions / C#
   

C#

 
Questionupdate ConnectionString in App.config Pin
Jassim Rahma6-Oct-13 0:03
Jassim Rahma6-Oct-13 0:03 
AnswerRe: update ConnectionString in App.config Pin
OriginalGriff6-Oct-13 0:10
mveOriginalGriff6-Oct-13 0:10 
QuestionSimple cross threading question Pin
ve3tru5-Oct-13 17:55
ve3tru5-Oct-13 17:55 
AnswerRe: Simple cross threading question Pin
Abhinav S5-Oct-13 19:00
Abhinav S5-Oct-13 19:00 
GeneralRe: Simple cross threading question Pin
ve3tru6-Oct-13 16:03
ve3tru6-Oct-13 16:03 
AnswerRe: Simple cross threading question Pin
Dave Kreskowiak6-Oct-13 4:24
mveDave Kreskowiak6-Oct-13 4:24 
AnswerRe: Simple cross threading question Pin
Richard MacCutchan6-Oct-13 5:04
mveRichard MacCutchan6-Oct-13 5:04 
Questionget pixel color on image Pin
Member 102255295-Oct-13 4:51
Member 102255295-Oct-13 4:51 
AnswerRe: get pixel color on image Pin
BillWoodruff5-Oct-13 7:22
professionalBillWoodruff5-Oct-13 7:22 
AnswerRe: get pixel color on image Pin
Richard MacCutchan5-Oct-13 20:51
mveRichard MacCutchan5-Oct-13 20:51 
AnswerRe: get pixel color on image Pin
AngloThaiSolutions7-Oct-13 4:01
AngloThaiSolutions7-Oct-13 4:01 
QuestionFocus of the DevExpress DateEdit Pin
nhanlaptrinh3-Oct-13 22:10
nhanlaptrinh3-Oct-13 22:10 
AnswerRe: Focus of the DevExpress DateEdit Pin
Eddy Vluggen4-Oct-13 0:25
professionalEddy Vluggen4-Oct-13 0:25 
QuestionVisual Studio Add-in 2012 Pin
Shankarcodebase3-Oct-13 21:41
Shankarcodebase3-Oct-13 21:41 
AnswerRe: Visual Studio Add-in 2012 Pin
Eddy Vluggen4-Oct-13 0:25
professionalEddy Vluggen4-Oct-13 0:25 
GeneralRe: Visual Studio Add-in 2012 Pin
Shankarcodebase5-Oct-13 16:28
Shankarcodebase5-Oct-13 16:28 
GeneralRe: Visual Studio Add-in 2012 Pin
Eddy Vluggen6-Oct-13 0:41
professionalEddy Vluggen6-Oct-13 0:41 
SuggestionRe: Visual Studio Add-in 2012 Pin
Richard Deeming4-Oct-13 0:48
mveRichard Deeming4-Oct-13 0:48 
GeneralRe: Visual Studio Add-in 2012 Pin
Shankarcodebase4-Oct-13 4:07
Shankarcodebase4-Oct-13 4:07 
GeneralRe: Visual Studio Add-in 2012 Pin
Richard MacCutchan4-Oct-13 4:22
mveRichard MacCutchan4-Oct-13 4:22 
GeneralRe: Visual Studio Add-in 2012 Pin
Shankarcodebase5-Oct-13 16:29
Shankarcodebase5-Oct-13 16:29 
QuestionSerial Port communication in C# Pin
alfie.max153-Oct-13 5:59
alfie.max153-Oct-13 5:59 
I am trying to start with serial port communication using C# for my project. So even though i am familiar with the C# language i am new into I/O Port communication and i seem to be having some problem with my code

C#
using System;
using System.IO.Ports;

class Program
{
	public static void Main ()
	{
		string portName = @"\\.\COM10";
		_serialPort = new SerialPort (portName);
		_serialPort.Close ();
	}
}



i am getting an error :
Error	1	The name '_serialPort' does not exist in the current context	c:\users\alfie\documents\visual studio 2012\Projects\serial\serial\Serial_port.cs



Someone pls help me get started with this. .

Also i have tested with the following code and verified that the COM10 port is working and is of type "char"

C#
class Program
{
    static void Main (string[] args)
    {
        string portName = @"\\.\COM10";
        IntPtr handle = CreateFile (portName, 0, 0, IntPtr.Zero, 3, 0x80, IntPtr.Zero);
        if(handle == (IntPtr) (-1))
        {
            Console.WriteLine ("Could not open " + portName + ": " + new Win32Exception ().Message);
            Console.ReadKey ();
            return;
        }

        FileType type = GetFileType (handle);
        Console.WriteLine ("File " + portName + " reports its type as: " + type);

        Console.ReadKey ();
    }

    [DllImport ("kernel32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall, SetLastError = true)]
    public static extern IntPtr CreateFile (string lpFileName, uint dwDesiredAccess, uint dwShareMode, IntPtr SecurityAttributes, uint dwCreationDisposition, uint dwFlagsAndAttributes, IntPtr hTemplateFile);

    [DllImport ("kernel32.dll")]
    static extern FileType GetFileType (IntPtr hFile);

    enum FileType : uint
    {
        UNKNOWN = 0x0000,
        DISK = 0x0001,
        CHAR = 0x0002,
        PIPE = 0x0003,
        REMOTE = 0x8000,
    }
}

AnswerRe: Serial Port communication in C# Pin
Big Daddy Farang3-Oct-13 6:16
Big Daddy Farang3-Oct-13 6:16 
GeneralRe: Serial Port communication in C# Pin
alfie.max153-Oct-13 6:18
alfie.max153-Oct-13 6:18 
AnswerRe: Serial Port communication in C# Pin
OriginalGriff3-Oct-13 6:17
mveOriginalGriff3-Oct-13 6:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.