|
I have this Error: 'Proj.frmMain' does not contain a definition for 'Comm1' can someone help me solve this error ?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO.Ports;
namespace Proj
{
public partial class frmMain : Form
{
private string[] tx_data = new string[14];
private string[] rx_data = new string[10];
public int i;
public frmMain()
{
InitializeComponent();
InitializeComports();
}
private void InitializeComports()
{
comboBox1.Items.Clear();
foreach (string s in SerialPort.GetPortNames())
comboBox1.Items.Add(s);
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void label16_Click(object sender, EventArgs e)
{
}
private void label18_Click(object sender, EventArgs e)
{
}
private void button3_Click(object sender, EventArgs e)
{
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
}
private void dataGridView2_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void txtTxmID1_TextChanged(object sender, EventArgs e)
{
}
private void txtTxmID5_TextChanged(object sender, EventArgs e)
{
}
private void lblRx2_TextChanged(object sender, EventArgs e)
{
}
private void lblRx5_TextChanged(object sender, EventArgs e)
{
}
private void cmdRead_Click(object sender, EventArgs e)
{
SerialPort port1 = new SerialPort((comboBox1.Text), 4800, Parity.None, 8, StopBits.One);
//For i = 1 To 6
// lblRx(i).Caption = rx_data(i + 1)
//Next i
readID;
string OutString = null;
string Instring = null;
int y = 0;
port1.Open();
//If the port is opened...
if (port1.IsOpen)
{
//tx_data(0) = "R"
//tx_data(1) = "I"
//tx_data(2) = "D"
//For i = 0 To 2
// Comm1.Output = tx_data(i)
//Next i
OutString = "RID";
port1.NewLine = OutString;
}
}
private void Comm1_OnComm()
{
SerialPort port1 = new SerialPort((comboBox1.Text), 4800, Parity.None, 8, StopBits.One);
string Instring = null;
for (i = 0; i <= 7; i++)
{
Instring = port1.ReadLine;
if (Instring == "")
{
rx_data[i] = "00";
}
else
{
rx_data[i] = System.Convert.ToString(System.Convert.ToInt32(Instring[0]), 16).ToUpper();
}
}
port1;
for (i = 0; i <= 7; i++)
{
if (rx_data[i].Length < 2)
{
rx_data[i] = "0" + rx_data[i];
}
}
for (i = 1; i <= 6; i++)
{
lblRx[i].Caption = rx_data[i + 1];
}
}
public void Display_SysID()
{
SerialPort port1 = new SerialPort((comboBox1.Text), 4800, Parity.None, 8, StopBits.One);
port1.Open();
//If the port is opened...
if (frmMain.Comm1.PortOpen)
{
//tx_data(0) = "R"
//tx_data(1) = "M"
//tx_data(2) = "g"
//tx_data(3) = Char(5)
//tx_data(4) = Char(7)
//For i = 5 To 11
//tx_data(i) = 0
//Next i
//For i = 5 To 11
//tx_data(11) = tx_data(11) Xor tx_data(i)
//tx_data(i) = Char(tx_data(i))
//Next i
//For i = 0 To 11
// frmMain.Comm1.Output = tx_data(i)
//Next i
frmMain.Comm1.Output = "R" + "M" + "g" + (char)(5) + (char)(7) + '\0' + '\0' + '\0' + '\0' + '\0' + '\0' + '\0';
frmMain.Comm1.PortOpen = false;
}
}
private void Form_Unload(int Cancel)
{
System.Environment.Exit(1);
}
public void writeID(string SysID, string SchID, string DeptID, string BlkID, string LevelID, string ClkID)
{
string OutString = null;
OutString = "";
tx_data[0] = "R";
tx_data[1] = "P";
tx_data[2] = "g";
tx_data[3] =
tx_data[4] =
tx_data[5] =
tx_data[6] =
tx_data[7] =
tx_data[8] =
for (i = 0; i <= 12; i++)
{
OutString = OutString + tx_data[i];
}
open_port;
//If the port is opened...
if (Comm1.PortOpen)
{
Comm1.Output = OutString;
Comm1.PortOpen = false;
}
}
public object cvtHexDec(string txtID)
{
string firstnum = null;
string secnum = null;
int f = 0;
int s = 0;
if (txtID.Length == 2)
{
firstnum = txtID.Substring(0, 1).ToUpper();
secnum = txtID.Substring(1, 1).ToUpper();
}
else
{
firstnum = "0";
secnum = txtID.Substring(0, 1).ToUpper();
}
for (i = 65; i <= 70; i++) // check for A - F (Hex format)
{
if (f == (char)(i))
{
f = (i - 55) * 16;
break;
}
}
for (i = 48; i <= 57; i++) // check for 0 - 9 (Hex format)
{
if (f == (char)(i))
{
f = (i - 48) * 16;
break;
}
}
for (i = 65; i <= 70; i++) // check for A - F (Hex format)
{
if (s == (char)(i))
{
s = i - 55;
break;
}
}
for (i = 48; i <= 57; i++) // check for 0 - 9 (Hex format)
{
if (s == (char)(i))
{
s = i - 48;
break;
}
}
f = f + s; //add the total of firstnum & secnum dec
cvtHexDec = (char)(f); //convert back to char
}
public object cvtHexToDec(string txtID)
{
string firstnum = null;
string secnum = null;
byte f = 0;
byte s = 0;
if (txtID.Length == 2)
{
firstnum = txtID.Substring(0, 1).ToUpper();
secnum = txtID.Substring(1, 1).ToUpper();
}
else
{
f = Convert.ToByte(0);
s = Convert.ToByte(0);
}
if (Convert.ToInt32(firstnum[0]) >= 65)
{
f = Convert.ToByte((firstnum[0]) - 55);
}
else
{
f = Convert.ToByte((firstnum[0]) - 48);
}
f = Convert.ToByte(f * 16);
if (Convert.ToInt32(secnum[0]) >= 65)
{
s = Convert.ToByte((secnum[0]) - 55);
}
else
{
s = Convert.ToByte((secnum[0]) - 48);
}
f = Convert.ToByte(f + s); //add the total of firstnum & secnum dec
return (char)(f); //convert back to char
}
private void cmdWrite_Click(object sender, EventArgs e)
{
writeID(txtTxmID0.Text.ToUpper(), txtTxmID1.Text.ToUpper(), txtTxmID2.Text.ToUpper(), txtTxmID3.Text.ToUpper(), txtTxmID4.Text.ToUpper(), txtTxmID5.Text.ToUpper());
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
}
|
|
|
|
|
Try here and see if there's anything helpful...
http://msdn2.microsoft.com/en-us/library/system.io.ports.serialport(vs.80).aspx
Hope this solves it for you...
|
|
|
|
|
Sounds to me like Comm1 is not defined on your form. What makes you feel it should be ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
hi,
how to insert textbox values into datagridview???
pls. reply, ill appreciate it
jing
|
|
|
|
|
Try this:
http://www.thescripts.com/forum/thread247261.html
|
|
|
|
|
|
Hi All,
How to validate or extract values from the following ASP label,
"a href="Browse.aspx?s=cc&v=sc">SavingCreditCard(9) /a" ??
I would like to get that count SavingCreditCard(9) in some variable? i would be glad if nayone could help me out.
-- modified at 20:54 Thursday 10th May, 2007
|
|
|
|
|
u can do that in JS . Say document.getELementByID("ID") then open the watch window and check for options there . innerhtml or childrens or value can give u ur "SavingCreditCard(9)". U have to debug that in JS.
|
|
|
|
|
Dear Subrata,
i got your idea, it really helped me a lot.
My question is, " how to capture the innerhtml values, like [categoryIndex].value"?
|
|
|
|
|
I am trying to use a generic class to provide standard data access methods for DataSetS that were created using the wizards. I can't seem to define the TableAdaptor parameter correctly so that the generic recognizes the TableAdaptor Fill() method.
Calling program:
{
GenericIo genericIo =
new GenericIo<
SomeTableAdaptors.SomeTableAdaptor,
SomeDataSet.SomeDataTable>;
SomeTableAdaptors.SomeTableAdaptor tableAdaptor =
new SomeTableAdaptors.SomeTableAdaptor();
SomeDataSet.SomeDataTable dataTable =
new SomeDataSet.SomeDataTable();
genericIo.GetDataTable(tableAdaptor, dataTable);
}
Generic class:
public class GenericIo<t1, t2="">
where T1 : class, new()
where T2 : DataTable, new()
{
public void GetDataTable(T1 tableAdaptor, T2 dataTable)
{
tableAdaptor.Fill(dataTable);
}
}
Compiler error message:
'T1' does not contain a definition for 'Fill'
I have spent many hours trying different things with interfaces, abstract classes, generic constraints, etc. to tell the generic class that T1 does have a Fill method which works on a DataTable, but with no success.
It's either going to be a "no, it can't be done" or the slap-your forehead "Doh". Any guidance will be appreciated.
Thanks,
FShields
|
|
|
|
|
Again, with code cleaned up. My apologies.
<br />
Calling program:<br />
{<br />
GenericIo genericIo =<br />
new GenericIo<<br />
SomeTableAdaptors.SomeTableAdaptor,<br />
SomeDataSet.SomeDataTable>;<br />
<br />
SomeTableAdaptors.SomeTableAdaptor tableAdaptor =<br />
new SomeTableAdaptors.SomeTableAdaptor();<br />
SomeDataSet.SomeDataTable dataTable =<br />
new SomeDataSet.SomeDataTable();<br />
<br />
genericIo.GetDataTable(tableAdaptor, dataTable);<br />
}<br />
<br />
Generic class:<br />
public class GenericIo<T1, T2><br />
where T1 : class, new()<br />
where T2 : DataTable, new()<br />
{<br />
public void GetDataTable(T1 tableAdaptor, T2 dataTable)<br />
{<br />
tableAdaptor.Fill(dataTable);<br />
}<br />
}<br />
<br />
Compiler error message:<br />
'T1' does not contain a definition for 'Fill'<br />
|
|
|
|
|
This short bit of code works well for getting the VolumeSerialNumber using win32_logicaldisk:
ManagementObject disk=new
ManagementObject("win32_logicaldisk.deviceid='C:\'");
this.textBox2.Text = disk.Properties["VolumeSerialNumber"].Value.ToString();
However, I would like to get the manufacturer serial number. I know this is available in win32_PhysicalMedia, but I can't find anything that tells me precisely what the "serial number" is named.
|
|
|
|
|
A little Google goes a long way. All I did was search for "Win32_PhysicalMedia" and wallah[^]!!
It's called, oddly enough, SerialNumber . The problem you're going to run into is that there is nothing that says a manufacturer has to fill this field in. This field may come back empty for any given drive or media.
|
|
|
|
|
Yup. Did the Google thing. I always do before I bother all you hard working folks. Found the same thing you did, tried it, and my little app crashed -- thought maybe I hadn't found the right name after all.
I suppose, based on what you say, it might mean there is no serial for my harddrive.
Bummer.
|
|
|
|
|
The last time I did this, only 2 out of 6 of my drives filled in the Serial Number field...
|
|
|
|
|
That's too bad. It would sure make my life easier if it was a standard all manufacturers followed.
Thanks for the feedback.
|
|
|
|
|
i have written a c++ application now i want to override virtual event handlers in the c++ app with c#.
also i want to compile the c++ app - or part of it- as a dll that i can reference in c#. but i keep on getting an error saying it's not a com object...
problem
1. what type of project do i need to create for c++ to be accesible in c#
2. how do i override an event handler.
or
how do i call a c# method from c++ (instead of overriding the event handler. i'll call a c# method
in a different dll)
rather have something you don't need, than need something you don't have
|
|
|
|
|
ok i compiled the c++ with /clr now c# adds the reference
rather have something you don't need, than need something you don't have
|
|
|
|
|
got it working with dllimport but cannot get it to call a c++ method
c#code :
<br />
using System;<br />
using System.Collections.Generic;<br />
using System.Text;<br />
using System.Runtime.InteropServices;<br />
<br />
<br />
namespace ConsoleApplication2<br />
{<br />
class Program<br />
{<br />
static void Main(string[] args)<br />
{<br />
int mine = tester();<br />
Console.WriteLine(mine);<br />
<br />
}<br />
<br />
[DllImport("touchlib.dll", EntryPoint = "tester",<br />
ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]<br />
static extern int tester();<br />
}<br />
<br />
<br />
}<br />
c++ code
<br />
int Touchable::tester()<br />
{<br />
return 5;<br />
}
rather have something you don't need, than need something you don't have
|
|
|
|
|
Hi,
DllImport is used to call native code such as Win32 functions.
if your C++ dll is .NET code, just call the C++ class as if it were C#.
|
|
|
|
|
should i add a using <dllname.dll> ?
and for functions in a class do i need to call Class::function()?
rather have something you don't need, than need something you don't have
|
|
|
|
|
donsolms wrote: should i add a using ?
yes
donsolms wrote: for functions in a class do i need to call Class::function()?
no
calling any CLR compliant language obeys the rules of the calling language, hence
in C# you need a using statement, and call as class.method(args) or object.method(args).
|
|
|
|
|
i can't get the using to work. i have the c++ dll in a namespace named touchlib and then a class named Touchable.
<br />
using touchlib;<br />
doesn't work, i have added a reference to the dll. a i missing something, maybe in the compiling of the dll? how can i be sure that the dll is managed c++? what type of vc++ project is managed c++?
rather have something you don't need, than need something you don't have
|
|
|
|
|
Hi,
I dont remember the details for C++, but you did build the C++ dll, didnt you ?
so you know it is/isnt managed code.
if you were able to add a reference to it in your C# app, it must be managed code.
now Intellisense should show the available classes (C# and managed C++).
|
|
|
|
|
thanks a lot, it is working 100% now.
i might have referenced an older version of the dll somehow, and after a simple clean solution for the c++ dll and c# project made it work.
thanks again
rather have something you don't need, than need something you don't have
|
|
|
|
|