|
Hi,
Sir what Book mean ?
Regards
|
|
|
|
|
Head First C#[^], or anything similar.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Down vote countered.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
string w = "ST12.5127";
float f1 = float.Parse( w.Substring( 2, 4 ) );
float f2 = float.Parse( w.Substring( 6, 3 ) );
Console.WriteLine( "f1: {0}", f1 );
Console.WriteLine( "f2: {0}", f2 );
modified 2-May-15 1:18am.
|
|
|
|
|
Thank you Sir this is good method
Regrds
|
|
|
|
|
Hi ,
this code is work but I have one problem
the problem in
ledArray1.SetValues(state_data,0,4)
this take Boolean array the c# message say cannot convert from byte[] to bool[] what can be doing?
this code is work
private void button1_Click(object sender, EventArgs e)
{
int baud_rate;
baud_rate = Convert.ToInt32(comboBox2.Text);
MessageBox.Show("" + baud_rate);
Port.Close();
Port = new SerialPort(comboBox1.Text, baud_rate);
Port.DataReceived += new SerialDataReceivedEventHandler(Port_DataReceived);
Port.Open();
button1.BackColor = Color.Lime;
}
string w;
private void Port_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
byte[] temp_read;
temp_read = new byte[6];
byte[] state_read;
state_read = new byte[4];
string w;
w = Port.ReadTo("ST");
if (w != string.Empty)
{
temp_read[0] = (byte)w[0];
temp_read[1] = (byte)w[1];
temp_read[2] = (byte)w[2];
temp_read[3] = (byte)w[3];
temp_read[4] = (byte)w[4];
state_read[0] = (byte)w[5];
state_read[1] = (byte)w[6];
state_read[2] = (byte)w[7];
state_read[3] = (byte)w[8];
string ff = Encoding.UTF8.GetString(temp_read, 0, 5);
float kk = Convert.ToSingle(ff);
string ff1 = Encoding.UTF8.GetString(state_read, 0, 4);
float kk1 = Convert.ToSingle(ff1);
thermometer1.Value = kk;
label1.Text = "" + kk1;
}
}
modified 1-May-15 14:27pm.
|
|
|
|
|
Seriously, when Eddie suggested that you need to read a book, he wasn't joking.
You seem to be trying to code by guesswork instead of from knowledge, and that's as likely to succeed in development as it is in driving. To continue the analogy, you seem to be trying to drive across the USA in a 40 ton articulated lorry when you haven't yet mastered riding a bicycle!
It doesn't work - it's clear from your questions that you don't understand the basics enough to do complex code yet. Please, for your own sake: go back and learn the early stuff.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Thank you Sir
For me study course about C# before that but I have some Ambiguity in some point for me I writing the code and is work but I try choice anther method to obtain the same result
look her this my code again Sir I need only choice anther method
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.IO.Ports;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ADC_and_display_value_in_computer
{
public partial class Form1 : Form
{
private string[] Ports;
private byte[] r_data;
public Form1()
{
InitializeComponent();
Control.CheckForIllegalCrossThreadCalls = false;
Ports = SerialPort.GetPortNames();
foreach (string port in Ports)
{
comboBox1.Items.Add(port);
}
}
private void button1_Click(object sender, EventArgs e)
{
int baud_rate;
baud_rate = Convert.ToInt32(comboBox2.Text);
MessageBox.Show("" + baud_rate);
Port.Close();
Port = new SerialPort(comboBox1.Text, baud_rate);
Port.DataReceived += new SerialDataReceivedEventHandler(Port_DataReceived);
Port.Open();
button1.BackColor = Color.Lime;
}
string w;
private void Port_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
byte[] temp_read;
temp_read = new byte[6];
byte[] state_read;
state_read = new byte[4];
string w;
w = Port.ReadTo("ST");
if (w != string.Empty)
{
temp_read[0] = (byte)w[0];
temp_read[1] = (byte)w[1];
temp_read[2] = (byte)w[2];
temp_read[3] = (byte)w[3];
temp_read[4] = (byte)w[4];
state_read[0] = (byte)w[5];
state_read[1] = (byte)w[6];
state_read[2] = (byte)w[7];
state_read[3] = (byte)w[8];
string ff = Encoding.UTF8.GetString(temp_read, 0, 5);
float kk = Convert.ToSingle(ff);
string ff1 = Encoding.UTF8.GetString(state_read, 0, 4);
float kk1 = Convert.ToSingle(ff1);
thermometer1.Value = kk;
label1.Text = "" + kk1;
}
}
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
button1.Enabled = true;
}
}
}
|
|
|
|
|
thank you for all
now final code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.IO.Ports;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ADC_and_display_value_in_computer
{
public partial class Form1 : Form
{
private string[] Ports;
private byte[] r_data;
public Form1()
{
InitializeComponent();
Control.CheckForIllegalCrossThreadCalls = false;
Ports = SerialPort.GetPortNames();
foreach (string port in Ports)
{
comboBox1.Items.Add(port);
}
}
private void button1_Click(object sender, EventArgs e)
{
int baud_rate;
baud_rate = Convert.ToInt32(comboBox2.Text);
MessageBox.Show("" + baud_rate);
Port.Close();
Port = new SerialPort(comboBox1.Text, baud_rate);
Port.DataReceived += new SerialDataReceivedEventHandler(Port_DataReceived);
Port.Open();
button1.BackColor = Color.Lime;
}
string w;
private void Port_DataReceived(object sender, SerialDataReceivedEventArgs e)
{
string w;
w = Port.ReadTo("ST");
if (w != string.Empty)
{
float f1 = float.Parse(w.Substring(0, 5));
float f2 = float.Parse(w.Substring(5, 3));
thermometer1.Value = f1;
label1.Text = "" + f2;
ledArray1.SetValues(sheimy_Converter1.Convert_byte_to_boolarry((byte)f2));
}
}
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
button1.Enabled = true;
}
}
}
|
|
|
|
|
Hello,
I am trying to find a code to find all the references of the property defined in a class which is very similar to 'Find All References' function available in Visual Studio environment. But I want to have it in code during run time. How to do it?
e.g
=>Property 1
private int _Salary;
public int Salary()
{
get{return _Salary;}
set{_Salary = value;}
}
=> Property 2
private int _Bonus;
public int Bonus()
{
get{return Salary * 2;}
}
Like in the above example I have two properties Salary & Bonus. Bonus is calculated from salary. As soon as I set a value to Salary, value of Bonus gets updated.
Similarly I want to get reference of all other properties or methods in the class or program which are affected when value of Salary is changed through code.
Conclusion - I want to have a method or function, so that whenever I set a value to some property in a class, I want to have a list of all the other properties(List<Property>) or methods which are affected and in which the changed property is referenced.
Please help me to achieve this.
Siddharth.Shinde
|
|
|
|
|
There is no functionality in the .NET framework that will check all your code to see where it is used. It is part of Visual Studio, and not of the framework.
You could do it yourself; you'd have to loop though all code (yes, means looking inside methods), in either binary or source-form, and make a list of all the places where it is used.
--edit
You're looking for a wrong solution to a known problem. Things might be simpeler if you implement INotifyPropertyChanged[^]
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I think you're on a wrong track. Why do you think you need this? I'm pretty sure there's a better approach to what you're trying to achieve with that.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
I have an array in the main class:
static void Main(string[] args)
here is the array
Contact[] contactArray;
contactArray = new Contact[2];
contactArray[0] = contact1;
contactArray[1] = contact2;
Contact is a class of it's own and contact 1 has been initialized in the main class.
I need to access this array from a UI class and iterate through it and display the content
I'm stuck. thanks.
|
|
|
|
|
One way to do this is to create a View Model class, and have all global data accessible via the view model. In the XAML file, you set the DataContext element to a static instance of the View Model class.
You create all UI classes in the View Model class, not in main(). When creating a UI class, one of the parameters to the constructor should be the VM instance.
A Google on "WPF View Model" and "XAML DataContext" should give you plent of examples of this technique.
If you have an important point to make, don't try to be subtle or clever. Use a pile driver. Hit the point once. Then come back and hit it again. Then hit it a third time - a tremendous whack.
--Winston Churchill
|
|
|
|
|
|
From time to time, I have faced the same requirement. I found that the simplest solution was to promote the object to class scope and mark it as both static and public. Thereafter, other classes reference it as Program.MyObject.
For example:
static public Contact[] contactArray;
static void Main(string[] args)
contactArray = new Contact[2];
contactArray[0] = contact1;
contactArray[1] = contact2;
In your form, you refer to contactArray as follows.
Contact Contact1 = Progarm.contactArray[0];
|
|
|
|
|
Ok i am really struggling with this, if any one can help it'd be appreciated (lanuguage c#):
Example string:
[[[['1'],'2'],'3'],[[[[[[['0015,15','bob'],'99'],'98'],'97','96'],'95'],[[[['Ra','sa','pa'],'01-01-2001','bob ',''],'']],'0045',''],'1',[['300','80','Ends, Here','0015',''],['300','84','Start','0015','']],'','0045','N','0045','']]
Requirement:
I need a function to split the above string into some sort of indexable array/tree using:
[] as start/stop node delimiters
, as a field delimiter within the node
The string is dynamic and could have multiple values in each child and have different amounts of childs/subchildren. I see this as being similar to parsing xml/creating a tree but i may be wrong....
Example usage (using above string):
if i were to reference node 1,3 i would return a '1' ([[[['1']..]..]..]
if i were to reference node 1,2,4 i would return '97','96'[ [,,[,,[,,]]] [[[[[[[..]..]..]'97','96']..]..]..] ..]
So basically i need something that will dynamically create the tree structure that i can ref through co-ordinates.
If your wondering - this is a webserver response so i have no control over what is returned, this is needed to allow me to identify a set of values for the applicable page section.
Any help appreciated - i am especially after code that i can copy paste to get a solution
|
|
|
|
|
This looks very much like something that would be trivially represented in LISP !!
A recursive descent parser would handle this pretty easily.
You need to define your "output" representation.
I'd suggest a structure like a class that could be used like a LISP cons cell:
class Node
{
public string Value;
public Node Head = null;
public Node Tail = null;
public bool HasValue = false;
public Node(string value, Node tail=null)
{
Value = value;
HasValue = true;
Tail = tail;
}
public Node(Node head=null, Node tail=null)
{
Head = head;
Tail = tail;
}
}
Value and Head should be properties that keep the HasValue correct in their setters. (Left as an exercise.)
A positive attitude may not solve every problem, but it will annoy enough people to be worth the effort.
|
|
|
|
|
Another possibility that occurs to me is to begin with a regular expression to split the string at the square bracket delimiters. Bear in mind, of course, that the square brackets must be escaped, since they are, themselves, regular expression tokens. The substrings would inhabit a Matches collection, of which each substring would them be a well formed CSV, easily split by way of string.split.
|
|
|
|
|
The regular expression ([[]]|[^[]]+) will tokenize the input to a Matches collection of the square brackets and everything else.
It is tempting to include the comma in this process, but there are two cases in the example provided where the comma is inside (unescaped) of the quoted (single quotes) string. This is not well formed CSV.
Further, some of the "everything else" strings either begin or end with the comma depending on their location in the ultimate tree structure.
It isn't apparent that this would be any more efficient than just scanning the input string during the recursive descent parsing.
A positive attitude may not solve every problem, but it will annoy enough people to be worth the effort.
|
|
|
|
|
I suggested a regex just to stir the pot a bit. Since regular expression parsing can consume quite a bit of memory, and aren't necessarily "efficient," you are probably right about recursive descent parsing being more efficient. Earlier today, I posted an article about the CSV parser that I wrote almost a year ago, which handles badly formed CSV strings by way of a simple, but effective state machine, which is similar to your recursive descent parser, but without the burden and potential risk associated with a recursive algorithm.
IMO, while there are circumstances in which a recursive algorithm truly is the best solution, in many cases, there is a non-recursive algorithm that achieves the same result more safely.
|
|
|
|
|
function [bestParameter1,bestParameter2] = ransac_demo(data,num,iter,threshDist,inlierRatio)
% data: a 2xn dataset with #n data points
% num: the minimum number of points. For line fitting problem, num=2
% iter: the number of iterations
% threshDist: the threshold of the distances between points and the fitting line
% inlierRatio: the threshold of the numer of inliers
%% Plot the data points
figure;plot(data(1, ,data(2, ,'o');hold on;
number = size(data,2); % Total number of points
bestInNum = 0; % Best fitting line with largest number of inliers
bestParameter1=0;bestParameter2=0; % parameters for best fitting line
for i=1:iter
%% Randomly select 2 points
idx = randperm(number,num); sample = data(:,idx);
%% Compute the distances between all points with the fitting line
kLine = sample(:,2)-sample(:,1);
kLineNorm = kLine/norm(kLine);
normVector = [-kLineNorm(2),kLineNorm(1)];
distance = normVector*(data - repmat(sample(:,1),1,number));
%% Compute the inliers with distances smaller than the threshold
inlierIdx = find(abs(distance)<=threshDist);
inlierNum = length(inlierIdx);
%% Update the number of inliers and fitting model if better model is found
if inlierNum>=round(inlierRatio*number) && inlierNum>bestInNum
bestInNum = inlierNum;
parameter1 = (sample(2,2)-sample(2,1))/(sample(1,2)-sample(1,1));
parameter2 = sample(2,1)-parameter1*sample(1,1);
bestParameter1=parameter1; bestParameter2=parameter2;
end
end
%% Plot the best fitting line
xAxis = -number/2:number/2;
yAxis = bestParameter1*xAxis + bestParameter2;
plot(xAxis,yAxis,'r-','LineWidth',2);
|
|
|
|
|
What have you tried?
What problems have you met?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
With which line do you need help?
I doubt that anyone is going to convert the complete procedure, just for the fun of it
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
|