|
You are correct, you did not implement a Singleton. However it is an instance so your assertion that it isn't is still wrong.
led mike
|
|
|
|
|
From your link:
the singleton pattern is a design pattern that is used to restrict instantiation of a class to one object
I don't, in any way, restrict the instantiation of XmlSerializer or MyConfigClass to one object. Other part of the application can instantiate other instances of XmlSerializer. In a Singleton pattern, this is not possible. I just hide the XmlSerializer instance I use to deserialize the object.
Anyway, I just wanted to know if the XmlSerializer.(De)Serialize methods were thread-safe.
|
|
|
|
|
hi everybody,
i can't change the axe X in excel with C# i know with vb serialcollection.XValue= but i need the information for c#
thanks
<br />
public void Excel_Graphic(int Lig, int col)<br />
{<br />
string upperLeftCell = "A3";<br />
int endRowNumber = System.Int32.Parse(upperLeftCell.Substring(1))<br />
+ Lig - 1;<br />
char endColumnLetter = System.Convert.ToChar(<br />
Convert.ToInt32(upperLeftCell[0]) + col - 1);<br />
string upperRightCell = System.String.Format("{0}{1}",<br />
endColumnLetter, System.Int32.Parse(upperLeftCell.Substring(1)));<br />
string lowerRightCell = System.String.Format("{0}{1}",<br />
endColumnLetter, endRowNumber);<br />
<br />
Worksheet ws = (Worksheet)app.ActiveSheet;<br />
<br />
Object Graph1 = new Object(); <br />
<br />
ChartObjects GraphObjs = (ChartObjects)ws.ChartObjects(Type.Missing);<br />
ChartObject GraphtObj = GraphObjs.Add(100, 20, 300, 300);<br />
<br />
Chart xlChart = GraphtObj.Chart;<br />
<br />
Range chartRange = ws.get_Range("A2", lowerRightCell);<br />
Range AxeY = ws.get_Range("A2", "A16");<br />
Range AxeX = ws.get_Range("B2", "B16");<br />
<br />
xlChart.SetSourceData(AxeY, Type.Missing);<br />
xlChart.ChartType = XlChartType.xlXYScatterLines;<br />
xlChart.Location(XlChartLocation.xlLocationAsNewSheet, Graph1);<br />
<br />
}</code> <br />
<br />
<div class="ForumSig">jere</div>
|
|
|
|
|
Hello,
I realized nobody answered this, and even if its been so long I will try to give an answer.
To change the X values, you need to get the series, and set the series X values to your "AxeX". Like this:
xlChart.SetSourceData(AxeY, Type.Missing);
Excel.Series series = (Excel.Series)xlChart.SeriesCollection(1);
series.XValues = AxeX;
|
|
|
|
|
I want to write a function to change the color property of all the controllers from an XML. XML tags are same as the controller names.
public void LoadProperties(Control control)
{
string name = control.Name;
control.ForeColor = ColorTranslator.FromHtml(xDoc1.SelectSingleNode("COLOR/Settings/" + (Name + "/ForeColor").InnerText.Trim());
}
So if the name exist in the XML it will retrieve the color info of fore and back color and and overwrite with the default ones.
XML:
<color> <settings>
<label1>
<forecolor>#FFFFFF
<backcolor>#330000
therefore under InitializeComponent(); when I run :
this.label1.ForeColor = System.Drawing.SystemColors.ActiveCaption;
// LoadProperties(this.label1);
LoadProperties will overwrite the default ForeColor with #FFFFFF
Right now it doesnt work. Do I have a logical mistake?
Thanks
|
|
|
|
|
cant copy/paste the xml here for some reason but its like:
-COLOR-
-Settings-
<label1>
<forecolor>#FFFFFF
<backcolor>#330000
-/COLOR-
-/Settings-
|
|
|
|
|
s3rro wrote: for some reason
Not for "some" reason. The reason is, you have NOT READ the CodeProject Posting guidelines and instruction which explain how to post messages containing less than and greater than symbols. NOT READING is likely also the reason you can't solve your own software development problem.
led mike
|
|
|
|
|
Hi there,
I will try to explained my problem.
I have an old lab balance attached to a PC via rs232 com port1 and need to interrogate the balance for data when an item has been weighted.
The balance does not send data to the PC input buffer I need to go get the info from its buffer.
The SerialPort class in C# does allow read/write to the PC buffer and that I know how to do but I do I question the balance for data that i don't.
The annoying thing is that I have a very old QBasic application that does the trick fine but I am unable to do it in C#.
Thanks
|
|
|
|
|
If you have the qbasic code then you can translate that. If not, you'll have to use a serial port sniffer to see what values are transmitted and received between the port and hardware so you can code these into your app.
Dave
|
|
|
|
|
Thanks Dave.
The QBasic lines are as follow
349 Open "COM1:1200,O,7,1,ASC,CD0,CS0,DS0,OP0,RS,TB2048,RB2048" For Random As 2
350 Print #2, Chr$(27); "P"
The user needs to press return at line 348 then the balance value is displayed on the console.
I suppose "For Random As 2" does the job but I can't see how it would translate to C#.
I will investigate the port sniffer you mentioned.
Scalpa
|
|
|
|
|
Hi,
the code you have shown is not complete.
line 349 simply opens the serial port, and sets a lot of settings, but it does not
do any actual input/output; AFAIK RANDOM does not make for serial ports, and the
"As 2" simply means input and output statements will use a #2 to refer to it.
line 350 sends an escape (ESC) character and a letter P to the device (probably
followed by a CR/LF)
the actual input and display code must follow that. the command looks like ASCII,
so chances are the return data is a text string too, making things rather easy.
You will need some investigative work here:
- first find out what all the options in line 349 amount to, and find the equivalent
in the SerialPort class; I guess (please check all!) 1200 Baud, no parity, 7 data bits,
1 stop bit, ASCII, and the polarity of a lot of control lines;
I also guess TB and RB set buffer sizes and don't really matter.
- I don't think a sniffer would really help here, it too would require all the correct
settings
- now you could try to use a terminal emulator (such as HyperTerminal, part of Windows);
when all parms are set correctly, you could simply type ESC P (and possibly ENTER)
and read what got returned. Once this works, start coding with SerialPort.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
Hey thanks a lot for your interest.
Here is the complete QBasics
10 Rem field bean program to recieve weights from sartorius balance
60 INPUT "DO YOU WANT HELP (Y/N)", H$
70 If H$ = "Y" Then GoTo 480
80 H$ = "N"
90 Close All
120 Print "ENTER PLOT NUMBER AS A 3 DIIGIT NUMBER 001"
121 Close #1
130 INPUT "PLOT NO ", B$
131 B$ = B$ + ".DER"
133 On Error GoTo 139
134 OPEN "I", 1, B$
136 Print "THIS PLOT HAS ALREADY BEEN MEASURED"
137 PLAY "AABBCC"
138 GoTo 120
139 Rem CLOSE #1
140 OPEN "O", 1, B$
150 Rem INPUT "ENTER NO OF VARIETIES ", V
160 C = 0
170 Rem IF C = V THEN CLOSE ALL: GOTO 880
180 C = C + 1
190 Rem FOR J = 1 TO 4
200 P = 0
210 PLAY "F"
220 Rem PRINT "VARIETY "; C: PRINT "REP "; J
230 Rem PRINT "ENTER PLOT HEADING IN FOLLOWING FORMAT"
240 Rem INPUT " PLOT NO'372' ?", PH$
250 Rem INPUT "AFPNO ?", AFP$
260 Rem PLAY "A"
280 Rem PRINT #1, PH$
285 Rem PRINT #1, AFP$
286 Let ch2$ = "1 20": Print #1, ch2$
290 Let ch$ = "29"
295 Let ch1$ = "SEEDWT"
296 Let ct$ = ch$ + ch1$
297 Print #1, ct$
300 If P = 20 Then GoTo 440
305 TIMEOUT = 10000
310 Rem Balance routine****************************
315 Print P + 1
320 INPUT "PUT SEED ON SCALES PRESS RETURN THEN TARE SCALES TO ZERO", CR$
330 P = P + 1
340 Open "COM1:1200,O,7,1,ASC,CD0,CS0,DS0,OP0,RS,TB2048,RB2048" For Random As 2
350 Print #2, Chr$(27); "P"
360 Line Input #2, W$
370 W = Val(W$): Rem W = real format of weight:REM W$ = String format of weight
380 Close #2
390 Rem End of balance routine*********************
400 Print W
410 W1$ = Mid$(W$, 7, 4)
411 If W1$ <> "0.00" Then GoTo 420
412 W1$ = "-1"
420 Print #1, W1$
430 GoTo 300
440 P = 0
450 Rem NEXT J
451 PLAY "EAG"
453 INPUT " ANOTHER PLOT Y/N ", A$
454 If A$ = "N" Then GoTo 471
460 Print "NEXT VARIETY": PLAY "B"
465 Close #1
470 RUN 90
471 Close #1
472 Cls
473 End
480 Rem HELP
490 Print " HELP FILE"
500 Print " ---- ----"
510 Print "IN ORDER FOR BALANCE.BAS TO WORK AND THE CABLE FROM BALANCE TO COMPUTER MUST BE CONNECTED PROPERLY SEE DIAG"
520 INPUT "PRESS RETURN TO CONTINUE", RT$
530 Cls
540 Print " "; " "; "-----------------"
550 Print " "; " "; "! !"
560 Print "___________________"; " "; "! !"
570 Print "! BALANCE !"; " "; "! COMPUTER !"
580 Print "! (BACK) !"; " "; "! (BACK) !"
590 Print "! !"; " "; "! !"
600 Print "! !"; " "; "! !"
610 Print "!_________________!"; " "; "!_______________!"
620 Print " __________"; " "; "___________________________________"
630 Print " ! !PLUG! !"; " "; "! !"
640 Print " ! !PORT! !"; " "; "! !!MOUSE!! !"
650 Print " !--------!"; " "; "! !"
660 Print " ^ "; " "; "! !!BALANCE!! !"
670 Print " ^ "; " "; "!--------- ^ ---------------------!"
680 Print " ^============================^"
690 INPUT "PRESS RETURN TO CONTINUE", RT$
700 Print: Print
740 Print " TO LOAD THE BALANCE PROGRAM YOU MUST BE IN C: DRIVE THEN SIMPLE TYPE": Print " 'GWBASIC BALANCE' FOLLOWED BY RETURN"
750 Print "THE PROGRAM THEN ASKS IF YOU NEED HELP TYPE 'Y' OR 'N' THEN RETURN"
760 Print "THE PROGRAM THEN ASKS FOR A FILENAME IN THE FORMAT C:\WS\FABA\filename"
770 Print "eg C:\WS\FABA\TEST.DAT"
780 Print "THE PROGRAM THEN ASKS FOR THE NUMBER OF VARIETIES"
790 Print "THE PROGRAM THEN ASKS FOR THE PLOT NUMBER IN THE CORRECT FORMAT"
800 Print "THE PROGRAM WILL BEEB IF THIS IS ENTERED INCORRECTLY."
810 Print "YOU ARE NOW READY TO WEIGH A SAMPLE OF SEED."
820 Print "SIMPLE PUT ONE SEED ON SCALES THEN PRESS RETURN WHEN HAPPY WITH WEIGHT"
830 Print "THEN TARE SCALES TO ZERO AND PUT NEXT SEED ON."
840 Print "CONTINUE FOR 20 SEEDS WHEN THE COMPUTER WILL BEEP YOU FOR NEXT REP OF VARIETY"
850 INPUT "PRESS RETURN TO CONTINUE", CR$
860 Cls
870 GoTo 80
880 PLAY "FACE": INPUT "DO YOU WANT ANOTHER RUN (Y/N) ?", R$
890 If R$ = "Y" Then GoTo 10
900 If R$ = "" Then GoTo 880
910 R$ = "N": Stop
as for Hyperterm I am unable to enter any commend in it when the balance is connected to my PC
Thanks for your help.
Scalpa
|
|
|
|
|
Scalpa wrote: 360 Line Input #2, W$
370 W = Val(W$): Rem W = real format of weight:REM W$ = String format of weight
Nice. Line 360 just reads a string, so the device outputs text, which you can look at
with HyperTerminal.
And Line 370 turns the text into a number, in C# that would be something like
int.TryParse() or float.TryParse().
As I said before, it's time to google and experiment about the control lines;
your PC probably must set some lines high/low otherwise the device may not respond.
Alternatively, you could just give it a try, open HyperTerminal, open a connection
at 1200 baud, and type ESC P ENTER, just to see what if anything comes in...
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
Luc, I really do appreciate your time an effort.
I have been on this for 2 days, hours on googles etc...
The thing is we also have a MFC application that works (not the source code though) fine but I need to do it in the .net framework for loading onto handheld devices.
I will investigate further and post the answer if even, when ever I find it.
Thanks again.
|
|
|
|
|
You're welcome.
One more idea: if your serial cable is not a commercial one, but something someone
assembled from scrap, then you might be able to see the actual number of conductors
used; the fewer there are, the fewer things you have to worry about. So if there
are only three conductors, it should always work in HyperTerminal.
If on the other hand all 9 (I presume it's a DB-9 connector) pins are wired, then
chances are you have to set all output control lines (about 3 or so) to the right
polarity.
Apart from that, there really should be no problem at all.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
A bit of searching found this - hope it helps. With the source code you have you should be able to recreate it - Good luck
OPEN "COM1:[speed],[parity],[data],[stop]" FOR [FILEMODE] AS #FileNumber
CD0 = zero milliseconds timeout on the data carrier detect line (DCD)
CS0 = zero milliseconds timeout on the clear to send line (CTS)
DS0 = zero milliseconds timeout on the data set ready line (DS)
RS = suppress detection of request to send (RTS)
Dave
|
|
|
|
|
that is useful info, if only Scalpa gets to see it, you did reply it to me...
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
thanks to you both.
Scalpa
|
|
|
|
|
Ok, I was trying to connect a PC(XP pro) to a SARTORIUS lab balance model BP3210S and also model 1413. Via Serial rs232
I finally made it work.
The main problem was the escape sequence sent to the port.
Here is the code.
Create a Windows C# project with 1 textbox and 1 button and drop this code behind form1.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using System.IO.Ports;
namespace AnotherSerial
{
public partial class Form1 : Form
{
SerialPort sp = new SerialPort("COM1", 1200, Parity.Odd, 7, StopBits.One);
public Form1()
{
InitializeComponent();
//Subscrib deleguate to even
sp.DataReceived += new SerialDataReceivedEventHandler(port_DataReceived);
}
private void sendButton_Click(object sender, EventArgs e)
{
try
{
textBox1.Text = "";
char cCHR27 = (char)27;
sp.ReadTimeout = 500;
if (sp.IsOpen) sp.Close();
sp.Open();
sp.DtrEnable = true;
sp.Write(cCHR27 + "P"); 'Escape
}
catch (System.Exception ex)
{
textBox1.Text = ex.Message;
}
}
private void ReadButton_Click(object sender, EventArgs e)
{
try
{
//clear the text box
textBox1.Text = "";
//read serial port and displayed the data in text box
if (sp.IsOpen) sp.Close();
sp.Open();
//textBox1.Text = sp.Read() + " Received";
}
catch (System.Exception ex)
{
textBox1.Text = ex.Message;
}
}
private void port_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
// Event for receiving data
// Read the buffer to text box.
this.Invoke(new EventHandler(DoUpdate));
}
private void DoUpdate(object s, EventArgs e)
{
textBox1.Text = textBox1.Text + sp.ReadExisting();
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
It works
Thanks all.
|
|
|
|
|
Hi!
I'm creating an application using C# and I need to display one or more markers in a webBrowser object using Google Maps.
The problem is that I was thinking to create only one HTML file that I could change automatically everytime I need to display something. Like this I need to edit this file with the right code (HTML and JavaScript) and than open it in the webBrowser object. This file would be located on local disk and not on a public website.
Do you think that this is the best way to do this? If not, what do you think i should do?
If it is, how can I edit a HTML file using C#?
Here's an example:
http://www.uploadhouse.com/viewfile.php?id=1267023[^]
Thanks in advance !!!
|
|
|
|
|
|
Thanks for the tip!
I'm going to take a look at the MSDN code that you post it.
Looks to me that it can help me.
However, I still don't know if this is best way to do this kind of implementation.
Any suggestions will be welcome.
Thanks!
|
|
|
|
|
I had to do the same thing last year. What I intended to be a c# application turned out to be mostly a javascript application. The only part that was c# was building the coordinate file to be used by the javascript.
MrPlankton
|
|
|
|
|
Hi, thanks for your post!
And you made it like this or not?
Can you explain me, in a very brief way, how did you implement this?
Thanks!
|
|
|
|
|
Hello!
I'm having a strange problem with a combobox I have added into my DataGridView object.
While runing my program, rows are added in to the DataGridView. When I check in the ComboBox, I can't see or use my collections items which i entered in the Edit Columns property window! Why is this happening?
I also want to know how to insert own items to the collection while running the program.
Hope someone have some answers!
/Mc_Topaz - It's Mc, not Mac. I'm not scottish!
|
|
|
|
|