|
Hi!
Need somexamples how I can make a COM comunication over USB.
Or maybe some basic documantation about USB- comunication in C#.
modified on Monday, December 10, 2007 7:04:00 PM
|
|
|
|
|
When I bought my USB-to-serial cable, it came with a CD-ROM containing a driver.
When I installed it, it turned the port into a regular serial port, so it shows up
in all serial port enumerations, and most/all serial apps can use it, whether
HyperTerminal or some .NET based app using SerialPort class.
The app never is aware the USB-based serial port is connected in a different manner,
all the nasty details are hidden by Windows and the device drivers.
BTW: there are minor differences between such a USB-to-serial cable and a regular
serial port, mainly in timing; it is not able to achieve very high speed in toggling the
control lines, which for most applications is irrelevant; if however the attached
hardware requires very short pulses on say the DTR/DSR/RTS pins, the motherboard-
based serial port might be able to deliver and the USB-to-serial might not, due to the
fact USB communication requires data packets, which must be transmitted and
interpreted, whereas a direct port is much "closer" to the CPU.
|
|
|
|
|
Luc, read your sig: I'm currently not getting ANY email notifications. I suspect it's been the website/database overhaul they are doing. Hopefully notifications are back on track now!
|
|
|
|
|
Today I am getting an e-mail notification on most of the replies I am getting, but not all of them.
That is why I have put the warning in my sig.
The funny thing is, whenever I reply to one of my replies (or send an e-mail to my own reply)
I am sure NOT to get an e-mail.
|
|
|
|
|
Wow, they totally listened to my suggestion then, about not receiving notifications for your own replies... alternitavely, they where already going to do that.
Or somehting is still up with the e-mail server. Whichever.
My current favourite word is: Bauble!
-SK Genius
|
|
|
|
|
SK Genius wrote: about not receiving notifications for your own replies
well I don't really need mail notifications when replying to myself, but it is and should continue
to be an easy way to check whether notifications still work (after the CP earthquake I had none
for several days). Why would you suggest to filter them out???
|
|
|
|
|
Hey now, at least one other person agreed, they said so!
Anyways, its just uneccesary to receive one of my own messages in my inbox. Besides, think of all the e-mail notifications it could save... like 5 or perhaps even 10!
And on a side note, where have you been these last few days? I usually see you hangin' around here alot, but the last few days.. not so much.
My current favourite word is: Bauble!
-SK Genius
|
|
|
|
|
SK Genius wrote: where have you been these last few days?
with a site that is getting upgraded for good reasons, but in the process recently:
- has been and sometimes still is hampered by performance problems
- offers almost no search facilities
- has hidden some of its forums
- is attracting fewer people, hence fewer questions
- is not always giving notifications
my response time has increased and my contributions indeed have been less frequent.
Newtons third law applies to all of us.
|
|
|
|
|
The problem is that we have to program our own driver for the USB.
So I wanted to know how to send bit in C#
|
|
|
|
|
You may get more/better replies if you tell us more about what it is you want to achieve
and why you feel you need to develop a driver? your own hardware? ...
|
|
|
|
|
It is a project for our university. We got an processor, and now we have to program an driver for the USB port, and a C# application which can comunicate with it (one byte would be enough).
|
|
|
|
|
Do you mean to say the microprocessor has a USB port and a serial port, and your task is to
actually turn it into a USB-to-serial cable?
if one byte is enough, let the microprocessor be powered through the USB port, and have it
output "Hello World!" as soon as it exits power-up reset!
Writing an actual Windows driver is not a simple task. You will need the right DDK (Driver
Development Kit), which I expect comes with some examples.
Hint: your microprocessor vendor may hold the solution for you; he probably has an elementary
solution for this kind of application.
BTW: which processor is it?
|
|
|
|
|
Hi guys,
I know how to open a file using the OpenFileDailog control or by drag-drop it on the object.
What I'm curious about is, how to associate a file type with my application or right-click on that file and select my application from the open-with list?
any ideas on how to get the file path will be appreciated
|
|
|
|
|
Hi,
1.
to associate a file extension with an app you can:
- use Windows Explorer, menu Tools/Folder Options/File Types
- modify the registry with regedit or write some code (search CodeProject for details)
- or easiest: double-click, and let the Explorer dialogs guide you (make sure to check "Always...")
2.
for Open With, I expect the same possibilities but don't have the experience.
3.
if your file extension is associated to your app, then double-clicking the file will launch
the app and pass the full file path as command line arguments; see the arguments of your static
main() method and/or Environment.GetCommandLineArgs().
4.
Once you have all this in place you will probably want the double-click to reuse your app
if it is already open; if so search CP for "singleton application".
|
|
|
|
|
|
I need to have a sound play in response to some internal event. I know how to play .wav files of any sort, but I don't want to play a .wav file..just send a beep. I think there's some unicode command that will do it, but if anybody could give me a tip on how to do it, that would be, well, helpful.
Thanks.
|
|
|
|
|
|
Write a character 7, or use System.Console.Beep which allows specifying the frequency and duration of the beep.
|
|
|
|
|
In .NET:
using System.Media;<br />
<br />
SystemSounds.Beep.Play()
You can also play any of the other Windows sounds.
|
|
|
|
|
|
Hi,
I'd like to know if casting based on a Type object is possible. Consider the following example:
using System;
namespace ConsoleApplication1
{
class BaseClass
{
}
class ClassA : BaseClass
{
}
class ClassB : BaseClass
{
}
class Program
{
static void Main(string[] args)
{
BaseClass obj1 = new ClassA();
BaseClass obj2 = new ClassB();
Program prog = new Program();
prog.TreatAnything(obj1);
prog.TreatAnything(obj2);
}
public void TreatAnything(BaseClass obj)
{
if (obj is ClassA)
TreatClass((ClassA)obj);
else if (obj is ClassB)
TreatClass((ClassB)obj);
else
{
}
}
private void TreatClass(ClassA obj)
{
}
private void TreatClass(ClassB obj)
{
}
}
}
The TreatAnything function receives a BaseClass object, and is forced to check its type by the is operator before casting it and calling the appropriate function. Now, I know the example looks simplistic, but imagine there are tens of classes derived rom BaseClass. Sure, I could make tens of if clauses and call the correct function each time... What I would really love to do, though, is turn the TreatAnything function into something like this:
public void TreatAnything(BaseClass obj)
{
Type t = obj.GetType();
TreatClass(SomeHypotheticalCastingFunction(t, obj));
}
So the tens of if clauses would be reduced to a small number of statements. Is there any way to do this kind of thing?
In case you want to know what I'm trying to do: I made a socket that parses what is receives and builds an object which is then passed around various methods. I have a Message base class, and then several derived classes. Each derived class represents a specific type of message, whose reception puts in motion very different actions on the server side. No, I don't think it's feasible to make a virtual method Treat() on the Message class and override it on each derived class, as the actions involved require much interaction with other objects the messages know nothing about.
I thank you in advance for any suggestions you might have.
Leonardo Pelisoli
|
|
|
|
|
Hi
You could use Reflection to invoke the appropriate method. something like this:
public class Program
{
public Program()
{
}
public void DoStuff()
{
BaseClass obj1 = new ClassA();
BaseClass obj2 = new ClassB();
ProcessObject(obj1);
ProcessObject(obj2);
}
void ProcessObject(BaseClass obj)
{
Console.WriteLine("BaseClass");
GetType().GetMethod("ProcessObject",System.Reflection.BindingFlags.NonPublic|System.Reflection.BindingFlags.Instance,null,new Type[]{obj.GetType()},null).Invoke(this,new object[]{obj});
}
void ProcessObject(ClassA obj)
{
Console.WriteLine("ClassA");
}
void ProcessObject(ClassB obj)
{
Console.WriteLine("ClassB");
}
}
public class BaseClass
{
}
public class ClassA:BaseClass
{
}
public class ClassB:BaseClass
{
}
|
|
|
|
|
I'm not sure you need to cast at all in that case, have you tried it without casting? And why have the TreatAnything method at all?
Well, once again I've spoken too soon. But there should still be a simpler way...
modified on Monday, December 10, 2007 7:09:54 PM
|
|
|
|
|
OK, here's another way, using Reflection as m@u suggested, but rather than going to Reflection for each incoming message (which is very costly) I do it once in a static constructor and populate a static dictionary (my latest favourite toy). It's still not as clean as I'd like, but it's fun!
namespace ConsoleApplication1
{
class BaseClass { }
class ClassA : BaseClass { }
class ClassB : BaseClass { }
class Program
{
private static readonly System.Collections.Generic.Dictionary<System.Type,System.Reflection.MethodInfo> dic ;
static Program
(
)
{
System.Reflection.ParameterInfo[] pi ;
System.Type pt ;
dic = new System.Collections.Generic.Dictionary<System.Type,System.Reflection.MethodInfo>() ;
foreach
(
System.Reflection.MethodInfo mi
in
typeof(Program).GetMethods()
)
{
if ( ( mi.Name == "TreatClass" ) && ( mi.ReturnType == typeof(void) ) )
{
pi = mi.GetParameters() ;
if ( pi.Length == 1 )
{
pt = pi [ 0 ].ParameterType ;
if ( pt.IsSubclassOf ( typeof(BaseClass) ) )
{
dic.Add
(
pt
,
mi
) ;
}
}
}
}
}
static void Main(string[] args)
{
BaseClass obj1 = new ClassA();
BaseClass obj2 = new ClassB();
Program prog = new Program();
prog.TreatAnything(obj1);
prog.TreatAnything(obj2);
}
public void TreatAnything(BaseClass obj)
{
if ( dic.ContainsKey ( obj.GetType() ) )
{
dic [ obj.GetType() ].Invoke ( this , new object[] { obj } ) ;
}
}
public void TreatClass(ClassA obj)
{
System.Console.WriteLine ( "A" ) ;
}
public void TreatClass(ClassB obj)
{
System.Console.WriteLine ( "B" ) ;
}
}
}
|
|
|
|
|
My thanks to you both, PIEBALDconsult and m@u. That's effectively a very elegant solution to my problem.
Best regards,
Leonardo Pelisoli
|
|
|
|