|
What you want is IPC (Inter process communication). There is a section here on CP about that, and one project I like is NetMQ[^], a C# port of ZeroMQ. NetMQ can be used as an IPC system, and handles a lot of the things needed for that for you, making it a lot simpler to, for example, send messages with multiple parts (refered to as 'Frames' in NetMQ).
Depending on the size and complexity of the project, this may be overkill, but it may be useful in other places as well.
What do you get when you cross a joke with a rhetorical question?
The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism.
Do questions with multiple question marks annoy you???
|
|
|
|
|
Hello,
many thanks for the quick answers.
They gave me valuable hints which I think will allow me
to solve my problem.
Just for your information: the problem is:
I want to control a flatbed scanner (any make).
I want to scan strips of a cine film which should be moved
through the scanner (in sections of about 4 to 20 cm - depending on the width of the scanners TPU) using a (custom built) transport mechanism with a stepper motor controlled by an Arduino UNO board.
The controlling program (FeederControl), which can be invoked by most scanning programs via a function that allows to show just scanned images with a defined image viewer (e.g. IrfanView) by triggering the specified program (in this scenario it will be not an image viewer but the FeederControl) providing the URL/URI of the just scanned image.
If the FeederControl program is invoked, it has to do the move and than has to press the "SCAN" button of the idling scanning program to start a new scanning process.
Than it has to wait until a new request is coming from the ScannerProgram and start the whole thing over again.
if you are interested:
see CineToVidWiki
I have to do the new program, because the old ScanController mentioned in the Wiki does not work successfully under Windows 10 and I have no idea why. It must be a TWAIN problem. And the envisaged solution would avoid to invoke the twain driver as it is done by the ScanController.
This will then only be done by the various Scanner programs.
Another advantage would be: the Scannerprogram can stay open and must not be invoked seperately for each scan, as currently the ScanController does. That means: the whole workflow is driven by the ScannerProgram and not by the FeederControl (which will be a pretty small program).
Many many thanks again
Wolfgang
|
|
|
|
|
Take a look at "single instance application". When you start the application again while an instance is already running, the command line parameters can be passed to the running application.
|
|
|
|
|
static void Main(string[] args)
{
int a;
int b;
int c;
HOME:
Console.WriteLine("Enter Any Number");
a = Int32.Parse(Console.ReadLine());
if
(a <= 0)
do
Console.WriteLine("Number must be greater than 0");
while (a > 0) ;
else
Console.WriteLine("Enter Second Number");
now question is that I want to repeat code until the value of "a" is greater than "0" (zero. how to do this?
|
|
|
|
|
First off, don't use int.Parse - use int.TryParse instead:
int a;
if (!int.TryParse(Console.ReadLine(), out a))
{
...
}
else
{
...
} That way your code won't crash if you mistype a number - int.Parse will throw an exception.
Second, look at your code:
if(a <= 0)
do
Console.WriteLine("Number must be greater than 0");
while (a > 0) ;
If you value is greater than zero it won't even get to the loop!
And if it did, all it would do is print the same line forever...
Probably what you want is something like:
if (a > 0)
{
while (a > 0)
{
...
a--;
}
}
else
{
...
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
sorry bro... but i think u prolly didnt get what he is up to..
he needs that the program should not proceed till the user dosent enter a number which is greater than zero..
have a look at my answer
|
|
|
|
|
using System;
namespace blahblah
{
class blah
{
static int a=0;
public static void Main()
{
HOME:
Console.WriteLine("Enter any number:");
a = Convert.ToInt32(Console.ReadLine());
if(a <= 0)
{
Console.WriteLine("The number must be greater than zero");
a = 0;
Main();
}
}
}
}
^^ this works fine
But you gota remove all the parameters in the main function.
this gives the following output:
Enter any number:
0
The number must be greater than zero
Enter any number:
..... so on
|
|
|
|
|
You created an unneccessary and unhelpful recursion. If you do the same if the second value gets entered wrongly the user would have to also enter the first value again.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
lol really...
|
|
|
|
|
What happens when the user keeps entering invalid inputs and the stack runs out of space?
|
|
|
|
|
We all get sucked into a hell dimension?
This space for rent
|
|
|
|
|
Hell is other people's code
|
|
|
|
|
lol this is a command line application.... the console will keep on scrolling down and never run out of space... the space is infinite.
|
|
|
|
|
Much to learn you still have, young padawan.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
I wasn't talking about the console but the stack. The correct answer to my question was that you'll get a stack overflow exception and your app will terminate.
|
|
|
|
|
I hadn't realised that Console applications rewrote the laws of the stack. Dagnabit, from now on, all my applications are going to be console applications if that's all it takes to avoid stack issues.
This space for rent
|
|
|
|
|
Please do use braces (brackets). As a beginner you shouldn't yet "experiment" with omitting them.
Please do not use labels ("HOME:"). Labels only make sense with the keyword goto and you should never, ever use goto until you exactly understand why I write this and are able to identify the 0,00001% case where goto might be excusable.
I assume you haven't yet learned about creating and calling own methods (which would be the best solution to letting the user retry entering a value).
So here's a comparatively good-style snippet for allowing the user to re-enter a value greater than zero if he entered a wrong value the first time or repeatedly:
Console.WriteLine("Enter any number greater than 0: ");
string input = Console.ReadLine();
int value1;
while (!Int32.TryParse(input, out value1) || value1 <= 0)
{
Console.WriteLine("Invalid input. Enter any number greater than 0: ");
input = Console.ReadLine();
}
Sidenote: In C#, local identifiers should be declared where you first need them, not all at the top of a method.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
Sascha Lefèvre wrote: you should never, ever use goto until you exactly understand why I write
Gets my vote!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Sascha Lefèvre wrote: Sidenote: In C#, local identifiers should be declared where you first need them, not all at the top of a method. I wonder where this habit comes from. I always declare vars at the top of the method.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I think it makes sense from a semantic point of view: You see a declaration and you know it's the first occurence of that identifier. It also saves some lines of code. Why do you prefer the top-declaration?
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
I think it may have come from the days when it was possible to declare a variable multiple times, VB5 allowed that and possibly 6, my milk languages. I think I have broken most of the old habits, annoying to realise some are still in use.
I do recall declaring and enum called Date with a value of 2, screwed up so many things. It was a long time ago!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Int a = -1;
Int hhhhhh = 0;
While (a <= 0)
{
Console.write("tell me " + hhhhhh.ToString() + "nd number ");
a = int.Parse(Console.ReadLine());
hhhhhh++;
}
Console.WriteLine("homework complete");
modified 3-Apr-16 13:42pm.
|
|
|
|
|
I haven't used any
Console.WriteLine to display "Input string was not in a correct format" . I am trying to get data from database and save it in a double 2D array. One row in each array entry. This is my code :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
namespace Outliers2010_Console
{
class Program
{
static void Main(string[] args)
{
try
{
double[][] rawData = new double[20][];
string con = @"Data Source=Kitty-PC\SQLEXPRESS;Initial Catalog=kitty12;Integrated Security=True";
SqlConnection sql = new SqlConnection(con);
string cms = "SELECT TOP 20 * FROM churn_or";
SqlCommand cmd = new SqlCommand(cms,sql);
sql.Open();
SqlDataReader dt = cmd.ExecuteReader();
int i = 0;
if (dt.HasRows)
{
Console.WriteLine("datareader has rows");
while (dt.Read())
{
Console.WriteLine("read from dt");
rawData[i] = new double[] {Convert.ToDouble (dt[0]), Convert.ToDouble(dt[1]), Convert.ToDouble(dt[2]), Convert.ToDouble(dt[3]), Convert.ToDouble(dt[4]), Convert.ToDouble(dt[5]), Convert.ToDouble(dt[6]), Convert.ToDouble(dt[7]), Convert.ToDouble(dt[8]), Convert.ToDouble(dt[9]), Convert.ToDouble(dt[10]), Convert.ToDouble(dt[11]), Convert.ToDouble(dt[12]), Convert.ToDouble(dt[13]), Convert.ToDouble(dt[14]), Convert.ToDouble(dt[15]), Convert.ToDouble(dt[16]), Convert.ToDouble(dt[17]), Convert.ToDouble(dt[18]), Convert.ToDouble(dt[19]), Convert.ToDouble(dt[20]), Convert.ToDouble(dt[21]), Convert.ToDouble(dt[22]), Convert.ToDouble(dt[23]), Convert.ToDouble(dt[24]), Convert.ToDouble(dt[25]), Convert.ToDouble(dt[26]), Convert.ToDouble(dt[27]), Convert.ToDouble(dt[28]), Convert.ToDouble(dt[29]), Convert.ToDouble(dt[30]), Convert.ToDouble(dt[31]), Convert.ToDouble(dt[32])};
Console.WriteLine(rawData[i]);
i++;
}
}
sql.Close();
}
catch()
{}
}
}
}
I am not getting any error nor exception nor even a message, but in output instead of getting value of rawData which I need to be printed. I am getting "Input string was not in a correct format" . I have extensively googled and even tried the suggestions but all are talking about exceptions and errors which are not solving my issue. haven't found any content like that
modified 2-Apr-16 8:20am.
|
|
|
|
|
Use the debugger.
Put a breakpoint on the line
Console.WriteLine("read from dt");
and run your app.
When it hits the line, it will stop and let you look at exactly what is happening.
Look at each of the values in your DataReader - at least one of them is not a string representation of a double value.
We can't do that for you: we don't have your data!
BTW: Two things.
1) You should use a using block for SqlConnections, SqlCommands, and so forth to ensure they are correctly disposed.
2) Unless you specify a sort order in your SQL query via a ORDER BY clause, SQL is at liberty to return rows in any order it feels like - so you may not get the same values in two consecutive runs. Always specify the order if you want to return specific rows!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
I am working on a C# project which is related to Write/Read RFID NXP tag. Reader model is Feig obid i-scan MR102. This is USB device. They provided SDK. I can read default serial number of NXP tag with this SDK. My problem is, I need to Write ISBN of a book in NXP tag and Turn security ON when the book indoor into library. When the book will be issued, I need to Read the ISBN of this book and Turn security OFF. I am attaching the SDK, if you know how to do this, please give me solution. Thanks.
SDK : <a href="https://drive.google.com/file/d/0B5vXfWlYNNbVVkxDWnEyLTBuZEU/view?usp=sharing">ID_ISC.SDK.NET_V04.06.10.zip - Google Drive</a>
|
|
|
|