|
One big reason is case-sensitivity.
But mainly because it's a symptom of a bad design. Most times I see or would use a switch on a string, there's a better way. I much prefer to have an enumeration. As a plus, the enumeration Parse method accepts a boolean to do case-insensitive parsing.
It's for what my EnumTransmogrifier[^] was created.
|
|
|
|
|
I may be totally missing the point of your question (I usually do ) but wouldn't
Console.WriteLine("{0},{1}", x, y);
do that for you?
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Nope. See default .
|
|
|
|
|
I saw it.
Implementing value checking for assignments to 'x' and 'y', using properties perhaps, would obviate the necessity though.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
HI,
May i know,
What are the prerequisites to learn sharepoint?
Iam only C, C++, VC++ Programmer Having 5 years of IT Experiance.
Thanks & Regards,
Krishna Rayalu TV
|
|
|
|
|
Asking in this[^] forum would be a better bet.
|
|
|
|
|
As Pete has said posting to the SharePoint forum would have been better, however, since you've already begun.
First, since you have no background in .NET, start there. The default language for SharePoint is C# so dig in. After that, since SharePoint is based on ASP.NET you will need to learn and understand it. After, and ONLY AFTER, you have these foundations, then you can start learning SharePoint.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Sorry I made a mistake in the previous post. I highlight tho point in the code with the error with the bold characters.
Hello
I am writing very simple code with C# to read and write data from Rockwell Automation PLC through their communication server (OPC srever) RSLINX.
I can read data but I cannot write because executable exit with error when I call the
RSLinxOCgroup.SyncWrite(item, ref syncserverhandles, ref datatowritetoplcmemory, out SyncErrors)
(dll: RsiOPCAuto.OPCGroupClass.SyncWrite(Int32 NumItems, Array& ServerHandles, Array& Values, Array& Errors) )
error : Specified array was not of the expected type.
the error, I suppose, refers to the datatowritetoplcmemory
that is declared as :
System.Array datatowritetoplcmemory;
datatowritetoplcmemory = Array.CreateInstance(System.Type.GetType("System.Int32"), 10)
and then filled for example like this:
for (i = 0; i < 10; i++)
{ datatowritetoplcmemory.SetValue (i * i, i) }
Can somebody help me?
Thank you
Best regards
rodrigo
modified on Friday, December 10, 2010 10:49 AM
|
|
|
|
|
You didn't need to post again. You can edit your posts if they are incorrect. Please use the pre tags for code snippets and remove the other post as it serves no point.
|
|
|
|
|
I've been a Rockwell user for many years, sounds like a good project.
I'd think that your code should interface with any OPC server and not necessarily specific to RSLinx, that's the point right?
|
|
|
|
|
I think you addressed this to the wrong person.
|
|
|
|
|
Hello
Sorry for my late reply.
In this case the application is dedicated to the communication with RSLinx.
Here I attach the code where I cut many non intersting lines of code so it will not run if you try.
Then if yo need I can attach the complete version.
Anyway the lines that i am interested in are highlighted.
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
using System.Timers;
using RsiOPCAuto;
using System.Windows.Forms;
using System.IO;
using System.Threading;
namespace opc_ali
{
class Program
{
static RsiOPCAuto.OPCServer RSLinxOPCserver;
static RsiOPCAuto.OPCGroup RSLinxOPCgroup;
static RsiOPCAuto.OPCItem RSLinxOPCItem_1;
static RsiOPCAuto.OPCItem RSLinxOPCItem_2;
static RsiOPCAuto.OPCItem RSLinxOPCItem_3;
static RsiOPCAuto.OPCItem RSLinxOPCItem_4;
static int prec_sec_bl = 0;
static int prec_millis_bl = 0;
static int TimeNow_Sec, TimeNow_mSec;
static int tempo_p, tempo_s, delta;
static int[] DDE_IN_INT = new int[50];
static int[] DDE_OUT_INT = new int[50];
static double[] DDE_IN_DOU = new double[50];
static double[] DDE_OUT_DOU = new double[50];
static int numero_word_I;
static int numero_word_O;
static int tempo_campionamento;
static int numero_campioni;
static int new_line;
public static void Main(string[] args)
{
try
{
RSLinxOPCserver = new RsiOPCAuto.OPCServer();
RSLinxOPCserver.Connect("RSLinx OPC Server", "");
RSLinxOPCgroup = RSLinxOPCserver.OPCGroups.Add("Prova");
RSLinxOPCgroup.IsActive = true;
RSLinxOPCgroup.UpdateRate = 50;
RSLinxOPCgroup.IsSubscribed = true;
RSLinxOPCItem_1 = RSLinxOPCgroup.OPCItems.AddItem("[ali]Program:scrittura_dati_per_out.dde_OUT_INT[0],L1,C1", 1);
RSLinxOPCItem_2 = RSLinxOPCgroup.OPCItems.AddItem("[ali]Program:scrittura_dati_per_out.dde_OUT_INT[0],L" + numero_word_I + ",C1", 2);
RSLinxOPCItem_3 = RSLinxOPCgroup.OPCItems.AddItem("[ali]Program:scrittura_dati_per_out.dde_IN_INT[0],L1,C1", 3);
RSLinxOPCItem_4 = RSLinxOPCgroup.OPCItems.AddItem("[ali]Program:scrittura_dati_per_out.dde_IN_INT[0],L" + numero_word_O + ",C1", 4);
Lettura_scrittura_sincrona();
}
catch (Exception e)
{
MessageBox.Show(e.ToString(), "Errore",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
public static void Lettura_scrittura_sincrona()
{
int itemcount;
int i;
int num_file = 0;
int num_righe = 1;
System.Array SyncErrors;
System.Array SyncValues;
System.Array SyncErrors2;
Object SyncQualities = null;
Object SyncTime = null;
string fileName;
string rigafile = "";
int anno;
int mese;
int giorno;
string cod_file = "";
new_line = numero_word_I * 10 + 34;
Int32[] DatiRegistrati = new Int32[numero_word_I];
byte[] byte_riga = new byte[new_line * numero_campioni];
System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
try
{
itemcount = RSLinxOPCgroup.OPCItems.Count;
System.Array SyncServerHandles;
SyncServerHandles = Array.CreateInstance(System.Type.GetType("System.Int32"), 4);
System.Array DatiDaInviare;
DatiDaInviare = Array.CreateInstance(System.Type.GetType("System.Int32"), 1);
for (i = 0; i < itemcount; i++)
{
SyncServerHandles.SetValue(RSLinxOPCgroup.OPCItems.Item(i + 1).ServerHandle, i);
}
anno = DateTime.Now.Date.Year;
mese = DateTime.Now.Date.Month;
giorno = DateTime.Now.Date.Day;
TimeNow_Sec = DateTime.Now.Second;
TimeNow_mSec = DateTime.Now.Millisecond;
tempo_p = (prec_sec_bl * 1000) + prec_millis_bl;
tempo_s = (TimeNow_Sec * 1000) + TimeNow_mSec;
delta = tempo_s - tempo_p;
prec_sec_bl = TimeNow_Sec;
prec_millis_bl = TimeNow_mSec;
while (true)
{
num_file += 1;
num_righe = 1;
cod_file = "_" + anno.ToString() + "_" + mese.ToString() + "_" + giorno.ToString() +
"_" + num_file;
fileName = "C:\\Archivio_registrazioni_Ali\\registra" + cod_file + ".txt";
if (!File.Exists(fileName))
{
FileStream fs = File.Open(fileName, FileMode.Create, FileAccess.Write);
fs.Close();
}
for (num_righe = 1; num_righe < numero_campioni + 1; num_righe++)
{
for (i = 0; i < numero_word_I; i++)
{
DatiRegistrati[i] = 0;
}
RSLinxOPCgroup.SyncRead(1, 1, ref SyncServerHandles, out SyncValues,
out SyncErrors, out SyncQualities, out SyncTime);
DatiRegistrati = (Int32[])SyncValues.GetValue(1);
TimeNow_Sec = DateTime.Now.Second;
TimeNow_mSec = DateTime.Now.Millisecond;
rigafile = String.Format("{0:00000}", num_righe);
encoding.GetBytes(rigafile).CopyTo(byte_riga, ((num_righe - 1) * new_line) + 0);
for (i = 0; i < numero_word_I; i++)
{
if (DatiRegistrati[i] < 0)
{
rigafile = String.Format("{0:00000000}", DatiRegistrati[i]);
encoding.GetBytes(rigafile).CopyTo(byte_riga, ((num_righe - 1) * new_line) + 32 + (i * 10));
rigafile = ";";
encoding.GetBytes(rigafile).CopyTo(byte_riga, ((num_righe - 1) * new_line) + 41 + (i * 10));
}
else
{
rigafile = String.Format("{0:000000000}", DatiRegistrati[i]);
encoding.GetBytes(rigafile).CopyTo(byte_riga, ((num_righe - 1) * new_line) + 32 + (i * 10));
rigafile = ";";
encoding.GetBytes(rigafile).CopyTo(byte_riga, ((num_righe - 1) * new_line) + 41 + (i * 10));
}
}
rigafile = "\r\n";
encoding.GetBytes(rigafile).CopyTo(byte_riga, ((num_righe - 1) * new_line) + new_line - 2);
<big></big> <big>for (i = 0; i < numero_word_O; i++)
{
DatiDaInviare[i] = i;
}
RSLinxOPCgroup.SyncWrite(3, ref SyncServerHandles, ref DatiDaInviare, out SyncErrors2);</big> Thread.Sleep(tempo_campionamento);
}
if (File.Exists(fileName))
{
File.WriteAllBytes(fileName, byte_riga);
rigafile = "";
}
}
}
catch (Exception e)
{
MessageBox.Show(e.ToString(), "Errore",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
Regards
rodrigo
|
|
|
|
|
I need help on a project which requires me to make use of Expression Blend & WPF to create a software that can:
1. accept & analysis user ink input
2. search library/source/database for similar shape/character
3. display 4 results found
4. display user's choice on textbox
In case I didnt make myself clear, think of it as iPhone's chinese character writing software. Just that in my case im using some image symbols instead of chinese language. Im using Visual Studio 2008 & Expression Blend 2.
|
|
|
|
|
RokudouKaiser wrote: In case I didnt make myself clear
You didn't. What exactly are you expecting from us? What code have you written? What are you stuck on? What have you researched? All I see there is a vague set of requirements.
|
|
|
|
|
Perhaps you could start by posting this in the Silverlight/WPF forum?
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
You sound like you went to the Underpants Gnome[^] school of business.
Step 1: Land Contract to build system
Step 2: ?
Step 3: Profit!
|
|
|
|
|
hi. friends
small clarification in log4net.
i am new to log4net so any mistake correct me.
i have small program that uses log4net, and i have two appenders like
1.LogFileAppender (writes log to file)
2.ADONetAppender (writes log to DB)
then i have
<root>
<level value="DEBUG" />
<appender-ref ref="LogFileAppender" />
<appender-ref ref="ADONetAppender" />
</root>
when i use this config..my logs written in both
my question are
1. what is that "level value="DEBUG" or INFO " what dose it do and what is the different??
2. i have to write my write debug and info log to my log file and other error,fatal & warning logs to db how can i do that??
any idia of like???
thanks
joe
|
|
|
|
|
hi friends
i found the answer
1. it is to set the level like(debu,Info,Warn,Error,fatal)
2.it is possible by setting
(use any one of this code in said the specific appender)
this will set the top level
<threshold value="DEBUG"/>
this will filter the level
<filter type="log4net.Filter.LevelRangeFilter">
<levelMin value="DEBUG" />
<levelMax value="WARN" />
</filter>
Thanks
|
|
|
|
|
Hi,
I'm writing a generic DAL layer for my development team because we dont want to give access of connection to the developers. I'm stuck in terms of providing option to handle Transaction oriented queries. Could some one throw light?
So, lets say I've 3 queries which have to be executed under one transaction. Since developer dont have access to Connection they can not create transactions.
Shall I take array of queries and parameters from client and execute within the Transaction Block? Is it a right approach.
Note:- I'm not using ORM hence I can not use Command Patterns also.
Thanks
|
|
|
|
|
|
|
The application shouldn't know that multiple queries are required -- it should just call one API method and pass in the data. What happens inside that method might involve a transaction.
PlaceOrder ( Customer , Item )
Begin transaction
Insert order
Insert invoice
Adjust inventory
Commit transaction
|
|
|
|
|
I developed a DLL in C#
When I am trying to call it I get:
System.EntryPointNotFoundException: Unable to find an entry point named:
It means that DLL doens't export any methods visible from DLL. Dumpbin doesn't show any methods either:
dumpbin.exe -exports ActiveXTest.dll
Dump of file ActiveXTest.dll
File Type: DLL
Summary
2000 .reloc
2000 .rsrc
2000 .text
What's wrong????
The DLL looks ok.. according to documentation:
namespace Kosmala.Michal.ActiveXTest
public static void setHooks()
{
....
}
Here is how I call it:
namespace IWFHotkeyStarter
{
class Program
{
[DllImport("D:\\work\\iwf\\_ctrl-tab-modless_dlg_testing\\activex\\VSProjects\\AcriveXSourceCode\\bin\\Debug\\ActiveXTest.dll")]
public extern static void setHooks();
static void Main(string[] args)
{
Program p = new Program();
p.run();
}
private void run(){
Console.WriteLine("run<<");
setHooks();
Console.WriteLine("run>>");
}
}
}
Please help
|
|
|
|
|
Why are you using a DLLImport and an external function declaration? Why not just add a reference in Visual Studio in your IWFHotkeyStarter by right-clicking the References folder and clicking Add Reference, then browsing for the DLL.
Better yet add both projects to the same solution and use a Project Reference.
Forgive me if you're doing this for a specific reason, but I'm guessing it doesn't work because C# DLLs are not machine code. I've only ever seen DLLImport and extern used for native DLLs, whereas .NET DLLs are in IL, not native code.
Then you will have something like:
using Kosmala.Michal.ActiveXTest;
namespace IWFHotkeyStarter
{
class Program
{
static void Main(string[] args)
{
Program p = new Program();
p.run();
}
private void run(){
Console.WriteLine("run<<");
ActiveXTest.setHooks();
Console.WriteLine("run>>");
}
}
}
|
|
|
|
|
you seem confused. A DLL is one of these two:
1.
a bunch of managed code, invisible to DUMPBIN, no need for DllImport; just add reference, use a using statement, and use its public types as if they are part of your EXE itself. the DLL will be copied into your EXE's folder.
2.
a bunch of native code (hence not C#), visible to DUMPBIN; needs DllImport and C# prototypes; add reference is impossible, P/Invoke is required; the DLL gets located through the Windows PATH environment variable.
|
|
|
|
|