|
I am making a program that needs to be able to control at least 8 devices through relays. It has to be through a serial port. The computer will run 24/7 checking the time and then changing the state of the devices being controled when they are supposed to be turned off and on. The problem. I don't know how I would control these 8 different rellays through one serial port. I need help on giving all of the rellays a seperate address so I can change them independently.
Can anyone help me?
|
|
|
|
|
This question should be asked in the hardware forum, it is not C# specific.
If you insist on using a single serial port, you will need some electronic skills, since it
will require additional electronics organized around some microcontroller, which has a serial
port, at least 8 digital outputs, and some code (assembly, C) to listen to the serial port,
and execute incoming commands.
There probably are commercially available solutions that offer 8 outputs from a serial port,
I don't have any specific info tho. Google does.
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.
|
|
|
|
|
Hello.. I am trying to create a new address book. I was wanting to know how to make it where you can create a new database and open existing databases to view. What I need to know is how to create a new database. I tried the source code from: http://support.microsoft.com/kb/307283
I keep getting that my sql server does not allow remote connections. It is locally though? Anyways I'm not asking anyone to write the code for me. If someone could refer me to a book that deals with C# and databases specially that would be much appreciated (or a website). I want to learn alot about databases and SQL. Thanks for the help in advance.
* EDIT *
By the website I meant one that explained each detail and how everything works. Thanks
|
|
|
|
|
Jacob Dixon wrote: sql server does not allow remote connections
By default it doesn't. You have to configure it through the Surface Area Configuration Manager ( or whatever it's called ) to allow "remote" connections.
"I guess it's what separates the professionals from the drag and drop, girly wirly, namby pamby, wishy washy, can't code for crap types." - Pete O'Hanlon
|
|
|
|
|
Ohhh.. now that I think about it, I was checking out a program called Contact Keeper and it did the same thing I'm wanting to do except it used Microsoft Access instead of SQL. Would you recommend a book for C# that teaches pretty much nothing but databases in C#?
|
|
|
|
|
Jacob Dixon wrote: Would you recommend a book for C# that teaches pretty much nothing but databases in C#?
Look around on Amazon. I think there are books out there dedicated to C# and databases, just don't remember any particular titles.
"I guess it's what separates the professionals from the drag and drop, girly wirly, namby pamby, wishy washy, can't code for crap types." - Pete O'Hanlon
|
|
|
|
|
Ok thanks, I'll check them out. I'm also going to Barnes and Noble tomorrow so I will check there also.
|
|
|
|
|
I was going to mention Barnes and Noble. They do have a book, I think it is from Apress, that is titled something like C# and Databases, or some variation like that. Alot of the C#/Database articles on this site are winners, too.
"I guess it's what separates the professionals from the drag and drop, girly wirly, namby pamby, wishy washy, can't code for crap types." - Pete O'Hanlon
|
|
|
|
|
I actually have Professional C# 2005 with .NET 3.0 by Wrox. It has some information about databases, but I was looking for something that got in more detail. I like knowing how every command works and the fuctions. They have one that is Beginning C# 2005 Databases that I am fixing to go check out. Thanks for your help! Hopefully soon I'll be the one helping instead of getting help!
|
|
|
|
|
Jacob Dixon wrote: Hopefully soon I'll be the one helping instead of getting help!
I am sure, in time
"I guess it's what separates the professionals from the drag and drop, girly wirly, namby pamby, wishy washy, can't code for crap types." - Pete O'Hanlon
|
|
|
|
|
I found a good manual in codeproject forum, if you want I can email it to you. But I don't remember where I found it.
Sourie
|
|
|
|
|
I have this code, but I need to find out how to make it so the program will check if its a prime number or not.
For Example:
If user types Number Is prime?
1 No – by definition
2 Yes – the only even prime! ?
3 Yes
4 No
5 Yes
7 Yes
17 Yes
18 No
629 ( = 17 * 37) No
static void Main(string[] args)
{
bool current = false;
int j;
Console.WriteLine("Enter any number/integer");
int num = Int32.Parse(Console.ReadLine());
for (int i = 2; i <= num; i++)
{
for (j = 2; j < i; j++)
{
if (i % j == 0)
{
current = true;
break;
}
}
if (current == false)
Console.Write("{0} ", j);
else
current = false;
}
Console.ReadLine();
}
}
}
|
|
|
|
|
Where are you stuck? People won't do your homework for you.
"I guess it's what separates the professionals from the drag and drop, girly wirly, namby pamby, wishy washy, can't code for crap types." - Pete O'Hanlon
|
|
|
|
|
There's something pretty screwy going on in that code. You can adapt this to suit your needs...
static void Main(string[] args)
{
Console.Write("Enter any integer: ");
int inputValue;
int.TryParse(Console.ReadLine(), out inputValue);
if (isPrimeNumber(inputValue))
{
Console.WriteLine(inputValue + " is a prime number.");
}
else
{
Console.WriteLine(inputValue + " is not a prime number.");
}
Console.Write("Any key to exit... ");
Console.ReadKey();
}
public static bool isPrimeNumber(int num)
{
if (num < 2)
{
return false;
}
for (int i = 2; i < num; i++)
{
if (num % i == 0)
{
return false;
}
}
return true;
}
Paul... I'm not doing his homework - he was nearly there by himself (unless that was a non working example that he was given to fix)
|
|
|
|
|
DaveyM69 wrote: Paul... I'm not doing his homework
No worries. Your code looks like something the OP can work off of and get some well valued learning experience out of
"I guess it's what separates the professionals from the drag and drop, girly wirly, namby pamby, wishy washy, can't code for crap types." - Pete O'Hanlon
|
|
|
|
|
yep.
a major performance improvement can be obtained by replacing
for (int i = 2; i < num; i++) by
if (num==2) return true;
for (int i = 3; i*i <= num; i+=2)
i.e. only test odd dividers less/equal the square root of num.
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 a lot. I appreciate a lot. It's not a homework, because I'm learning C# by a book and there was a problem and I could not figure out. Thanks a lot Davey.
|
|
|
|
|
I wrote a prime class for myself some time ago - so I just dug this out of my archives.
It's not the best algorithm, in terms of speed, however it works.
Make sure you understand how it works because when your tutor comes to ask you how it works...
class Prime
{
public static bool isPrime(double numIn)
{
double testNum;
double testLimit;
testLimit = numIn;
testNum = 3;
if (0 == testLimit % 2)
{
return false;
}
while (testLimit > testNum)
{
if (0 == numIn % testNum)
{
return false;
}
testLimit = numIn / testNum;
testNum += 2;
}
return true;
}
}
You always pass failure on the way to success.
|
|
|
|
|
why would you use doubles both in the API and inside the method, when the problem at hand
is basically an integer one?
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 Pattyn wrote: why would you use doubles both in the API and inside the method, when the problem at hand
is basically an integer one?
Possible reasons:
Because it was nearing midnight when I dug out this class that I wrote as I was learning C#.
My gerbils wrote the code.
Not all primes have yet been discovered - I may actually discover a non whole prime.
(Embarassed clearing of throat )
You always pass failure on the way to success.
|
|
|
|
|
Thanks a lot. It was very helpful.
|
|
|
|
|
Determining whether or not each number is prime as it's entered seems inefficient.
As is holding a huge Sieve that may not get fully used.
So what about a more dynamic Sieve that you only extend when a new highest number is entered?
Might that work?
|
|
|
|
|
So far the linear sieve has not been mentioned nor shown in code in this thread, and it is
not the way I would recommend to have a program determine primality for a specific number.
The sieve methods are fine to explain the concept, and to execute by hand (i.e. for small
numbers) since no divisions are required at all; successive division attempts are the normal
first-order attempt in a program.
For large numbers (say above 100 digits) completely different techniques are available
and are getting refined all the time to investigate primality; most of them use shortcuts
that reduce the computational effort tremendously at the expense of a little uncertainty
(false positives for some tests, false negatives for other tests). And special libraries
("big integer" or "multiple precision" are used to operate on those numbers).
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.
|
|
|
|
|
hi
is that anyWay or any Compiler or ... that convert or transfer my c# code to IC or MicroController ?
thanks ..
|
|
|
|
|
Yes - it's still zeros and ones at the end of the day so could be stored on an eeprom.
What use it would be I don't know as it will never run without the Operating System plus .net framework. You would need to develop a hardware driver as well to communicate between your eeprom/microcontroller and the operating system/framework.
If you want it as a standalone thing without a computer connected then no as the operating system and .net framework need a PC to run plus attempting to copy them would be highly illegal.
|
|
|
|