|
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
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"
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,
}
}
|
|
|
|
|
The error message you are getting is telling us that you are using a variable called "_serialPort" but it is never defined. There needs to be a definition of that variable somewhere. Something like:
SerialPort _serialPort;
BDF
The internet makes dumb people dumber and clever people cleverer.
-- PaulowniaK
|
|
|
|
|
Thanx... That worked like a charm...
Sorry for my silly question....
|
|
|
|
|
Well, you could start by declaring the variable...
using System;
using System.IO.Ports;
class Program
{
private SerialPort _serialPort = null;
public static void Main ()
{
string portName = @"\\.\COM10";
_serialPort = new SerialPort (portName);
_serialPort.Close ();
}
}
The only instant messaging I do involves my middle finger.
|
|
|
|
|
OriginalGriff wrote: using System;
using System.IO.Ports;
class Program
{
private SerialPort _serialPort = null; public static void Main ()
{
string portName = @"\\.\COM10";
_serialPort = new SerialPort (portName);
_serialPort.Close ();
}
}
I tried this code... but i am getting this error...
An object reference is required for the non-static field, method, or property 'Program._serialPort'
|
|
|
|
|
Sorry, my bad!
I forgot that Main is a static method!
Add the word "static" between "private" and "SerialPort"
The only instant messaging I do involves my middle finger.
|
|
|
|
|
thanx.... that did the trick...
|
|
|
|
|
You're welcome!
The only instant messaging I do involves my middle finger.
|
|
|
|
|
|
If you look at the OP, there are two sections of code: the first using SerialPort is the one he has problems with, and the second is labeled as a test to prove the serial port works.
The only instant messaging I do involves my middle finger.
|
|
|
|
|
how can Read/write directly to a specific sector in a hard disk
with c#
Please help me if anybody know
|
|
|
|
|
|
Hi
I Saw this sample but it doesnt tell how can i write in sector, this sample just show total size of sector in disk
|
|
|
|
|
It shows how to read from the disk, so it should not be too difficult to figure out from that how to write to it.
Veni, vidi, abiit domum
|
|
|
|
|
rd.Read();
if (rd["allwid"].ToString() == "")
{
allwdet.Allowanceid = 1;
rd.Close();
}
else
{
allwdet.Allowanceid = int.Parse(rd["allwid"].ToString()) + 1;
rd.Close();
}
}
|
|
|
|
|
One doesn't modify generated code; if something is wrong, you'd fix it in the model you're generating from.
As for the output; I'd imagine the first record to not have a value for it's allwid-column, and values 12 and 13 for records 2 and 3. What was your expected result? And what are the actual values in the database?
Offtopic; It'd be nice if the subject-line of your post contained the subject - not a complete question. That goes in the post itself.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Troubleshooting the query might help find solve the problem.
|
|
|
|
|
what is the concept of teamviewer??
Can anyone just tell me what is the concept behind teamviewer???
I just need a simple concept to start....
Please someone help me in it...
|
|
|
|
|
The first page of a google search lead me to this[^] blog page.
|
|
|
|
|
I have a database that houses (amongst other things) data on defects and repairs, car repairs as an example. The way this db breaks down is this:
Table Defect holds the information about the defect (Damaged bumper, broken windshield, w/e)
Table Material holds information about materials used to repair (ex: new bumper)
Table Equipment holds information about equipment used to repair (ex: buffer)
Table Trade holds information about who is responsible for the repair and their wage (ex: mechanic)
There are three many to many tables that join defect with trade/eq/mat and have a quantity.
Long story short, I have a Scalar value UDF that returns the value of all of these costs together divided by a value in the defect table.
I decided to try to simplify it into a query (The simplification discussion is a TSQL issue outside the scope of this post) and in doing so had to ask myself, does this belong as a SQL query or should I write it as an additional property of the model in c#?
I could just as easily write a partial class that handles all of this craziness on the web server side. Is this all pedantic? Is it really a question of db server performance vs web server performance? I have read that scalar value functions in TSQL can be low performing due to threading issues, which is what sparked this thing in the first place.
Thoughts? Opinions?
Cheers, --EA
|
|
|
|
|
eddieangel wrote: Is it really a question of db server performance vs web server performance?
Probably. If it is in fact a 'better' application if this specific feature is 'faster' and the speed up is achieved by one or the other (probably via TSQL) then that would be the deciding factor.
Other than that it is conceptually business logic but given the complexity of the data entities then I would suspect that it is less complex (lower maintenance) to leave it in the database.
eddieangel wrote: I have read that scalar value functions in TSQL can be low performing
Which sounds irrelevant without information about the requirements, architecture, design and measured performance of the application (not benchmarks) related to this.
|
|
|
|
|
Thank you. You are right, "low performing" is immeasurable in the scope of my application. Because of the complexity of using a UDF with Entity Framework I am going to move the calculation to the web server side for the time being.
Cheers, --EA
|
|
|
|
|
I would be asking myself where you are consuming the result, if it is ONLY in your UI then doing the calc in the model is valid. If however you intend to use it in reports then the database should be used.
You may also consider storing the result somewhere if it is used in reports. Recalcing it every time you run a report may not be the best option.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
The question of storing the calculated field has been on my mind actually. In theory the calculation could happen one time (Only when the record is changed) and then stored. Otherwise it happens 1500 times (The number of records roughly) every time someone needs to access the data.
I think you are right that recalcing is not the best option, in spite of the fact that it has been done that way for a long time.
Thanks for the input, going to move it DB side, the amount of extra storage (1 field, 1500 to 3000 records) is negligible compared to the processing benefits.
Cheers, --EA
|
|
|
|
|
Hi,
From my experience SQL is extremely powerful on data manipulation, and if I understood it right that what you doing here...
I see no reason (maybe conformance ) to do it in C#, not even in a hosted CLR...
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is (V).
|
|
|
|