|
Sorry, I failed to understand last statement.
You indicated that you use com3 event to drive “real time” animation. Can you provide more details?
|
|
|
|
|
example ... 3 GPS-GSM that trasfer horse position in real time. I connect a modem receiver to my PC, open a COM PORT for it, ad using, in real time, a sentences that I receive. For any horse.
Alex
|
|
|
|
|
Sounds as horse position is embedded inside com3 message. Am I right?
|
|
|
|
|
Hi:
I just write a simple example for you. I hope it was useful for you.
<br />
class MultiThread<br />
{<br />
Thread td_example = null;<br />
System.Windows.Forms.Control _ctl;<br />
public MultiThread(System.Windows.Forms.Control ctl)<br />
{<br />
td_example = new Thread(new ThreadStart(CalledMethod));<br />
_ctl = ctl;<br />
}<br />
<br />
public void startThread()<br />
{<br />
td_example.Start();<br />
}<br />
<br />
public void suspendThread()<br />
{<br />
td_example.Suspend();<br />
}<br />
<br />
public void abortThread()<br />
{<br />
td_example.Abort();<br />
}<br />
<br />
int i = 0;<br />
private void CalledMethod()<br />
{<br />
while (true)<br />
{<br />
i++;<br />
System.Windows.Forms.MessageBox.Show(i.ToString());<br />
<br />
Thread.Sleep(1000);<br />
}<br />
}<br />
}<br />
good luck!
|
|
|
|
|
the class is 1 for all the 3 istance?
Alex
|
|
|
|
|
You can instantiate the class to a variable. Then use the variable which instantiated to open each files.
I just write a simple example for you. And, this is only a guiding idea. I consider that the more problems solved by oneself the more he/she learned.
There was an old sentence, in our country, said that,"Teaching someone fishing than giving he/she fishes."
I suggest that trying each one's answer and google it,I think you will learn more by yourself.
I am sorry for my poor English.
Good Luck!
|
|
|
|
|
Hi,
I fail to see what MultiThread is bringing, it only exposes some methods of Thread.
BTW: it is a bad idea to abort a Thread, threads should be canceled in a cooperative way as much as possible; and Thread.Suspend is obsolete.
Anyway, the heart of the matter will be reading and timing the COM ports as accurately as possible, which depends on the protocol or message format being used.
|
|
|
|
|
Is something like this what you are looking for? (this example will allow you to read as many files as you like)
using System;
using System.IO;
using System.Threading;
using System.Windows.Forms;
namespace MultiThreadedFileRead
{
public partial class Form1 : Form
{
private readonly object _syncRoot = new object();
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
listBox1.Items.Add(openFileDialog1.FileName);
}
}
private void button2_Click(object sender, EventArgs e)
{
foreach (object file in listBox1.Items)
{
ThreadPool.QueueUserWorkItem(ThreadFunc, file);
}
}
private void WouldBeEventHandler(string s)
{
if (InvokeRequired)
{
Action<string> d = WouldBeEventHandler;
BeginInvoke(d, new object[]{s});
return;
}
lock (_syncRoot)
{
listBox2.Items.Add(s);
}
}
private void ThreadFunc(object state)
{
string filename = state as string;
if (!string.IsNullOrEmpty(filename))
{
using (StreamReader fs = File.OpenText(filename))
{
while (!fs.EndOfStream)
{
WouldBeEventHandler(fs.ReadLine());
Application.DoEvents();
}
}
}
}
}
}
|
|
|
|
|
thanks ... this is ok, but if i need to process in real time (string in file passed from PORT COM in real time...)?
Alex
|
|
|
|
|
This is a serialport example, since you keep mentioning COM PORTS I am supposing this is what you are looking for. I will be happy to help out more, but if this still isn't what you need, a better description of what you need in is order.
using System;
using System.IO.Ports;
using System.Threading;
using System.Windows.Forms;
namespace MultiThreadedFileRead
{
public partial class Form1 : Form
{
private readonly object _syncRoot = new object();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
serialPort1.DataReceived += SerialPort1DataReceived;
serialPort2.DataReceived += SerialPort2DataReceived;
serialPort3.DataReceived += SerialPort3DataReceived;
}
private void SerialPort1DataReceived(object sender, SerialDataReceivedEventArgs e)
{
ThreadPool.QueueUserWorkItem(ThreadFunc, sender);
}
private void SerialPort2DataReceived(object sender, SerialDataReceivedEventArgs e)
{
ThreadPool.QueueUserWorkItem(ThreadFunc, sender);
}
private void SerialPort3DataReceived(object sender, SerialDataReceivedEventArgs e)
{
ThreadPool.QueueUserWorkItem(ThreadFunc, sender);
}
private void ThreadFunc(object state)
{
SerialPort port = state as SerialPort;
if (port != null)
{
try
{
}
catch (Exception)
{
}
}
}
}
}
|
|
|
|
|
Hi,
I am passing a VBScript Object to a C# assembly and am getting the following error output:
"Unable to cast COM object of type 'Agents.AgentClass' to interface type 'Agents._Agent'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{315DF678-45D7-4A60-9A50-C9E83672A5E5}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE))."
I'd appreciate it if someone can explain what is going on here and how I can fix it? I am confused...
Note: I have tried changing the method header to accept type Agents._Agent but that causing the method call in vbscript to fail completely. Changing the type to Agents.Agent (another available type) generates a similar error.
Kind Regards,
Dave
Regards,
Dave
|
|
|
|
|
Hi,
I see there's no reply to this. Do I need to provide more information?
Regards,
Dave
|
|
|
|
|
That error indicates that it doesn't know what an Agent is. I assume that it's correctly installed, registered, and that you can create an agent using VBScript.
Does the C# assembly have references to the correct versions of the AgentObjects.dll and AxAgentObjects.dll?
I are Troll
|
|
|
|
|
[^]
This Might be helpful for you
|
|
|
|
|
You replied to the wrong post - the TS would have gotten an email-notification if you'd replied on the original question I are Troll
|
|
|
|
|
Hi!
I'm triying to read a card using a magnetic card reader. Now it's working perfectly in a quite simple way: reader it is pluged USB, and recognized as a HID, like a keyboard. I.E.: If I have focused a TextBox, and I pass a card, readed text is puted there (all three tracks, one after another, CR/LF inserted), directly.
But I need to TRAP and read the text when no TextBox or simmilar is focused. I don't need any help about magnetic stripe encodig. I have this info. Just need to know how to get that text.
Could you help me, please?
Thanks!
modified on Friday, January 15, 2010 6:56 AM
|
|
|
|
|
If it only emulates a keyboard, you probably can't.
It's going to depend on the card reader - it may be possible to switch it to a delimited format (and then you can trap the delimiters) or use it as a standard serial interface.
Either way, your best bet is to look at the manufactureer details, or talk direct to them and explain your problem - it can't be something they haven't met before!
All those who believe in psycho kinesis, raise my hand.
|
|
|
|
|
A card reader emulates a keyboard - any DOS text program can accept input from one. I used to have fun with customers at Ace Hardware when I worked there for a while by opening Notepad, scanning their credit cards, and showing them exactly what information the stripes contained.
You should be able to use the CON device as input for a text stream, and capture the data from that. I've never tried it, mind you, but that's where I'd start looking. When you solve it, this would make a nice article for CP, by the way. This is a useful bit that many members would probably find helpful.
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
|
|
|
|
|
How can I get list of Application Domains?
Following code not get created domain when call from different Win Application.
private static AppDomain GetAppDomain(string pFriendlyName)
{
IntPtr p_Handle = IntPtr.Zero;
//CorRuntimeHostClass Assembly --> C:\Windows\Microsoft.NET\Framework\v2.0.50727\mscoree.tbl
CorRuntimeHostClass runtime = new CorRuntimeHostClass();
try
{
runtime.EnumDomains(out p_Handle);
do
{
object domain = null;
runtime.NextDomain(p_Handle, out domain);
if (domain == null)
{
break;
}
AppDomain appDomain = (AppDomain)domain;
if (appDomain.FriendlyName.Equals(pFriendlyName))
{
return appDomain;
}
} while (true);
}
finally
{
runtime.CloseEnum(p_Handle);
Marshal.ReleaseComObject(runtime);
runtime = null;
}
return null;
}
|
|
|
|
|
You can get a list of the application domains by formatting your bloody code when you post it!!!
|
|
|
|
|
dataminers wrote: Following code not get created domain when call from different Win Application.
That code works, but only for AppDomains created from your executable. AFAIK, it won't retrieve the AppDomain of another process. You can test it by feeding it AppDomain.CurrentDomain.FriendlyName , you'll see that it returns the current AppDomain.
Are you trying to use it for communication between two applications?
I are Troll
|
|
|
|
|
Actualy I want to create singleton class for each application. (Cross AppDomain Singleton)
|
|
|
|
|
How about a Mutex [^] instead?
I are Troll
|
|
|
|
|
How can I create cross appDomain singleton class using with Mutex?
I think Mutex Class not related about my problem.
Best Regards...
|
|
|
|
|
dataminers wrote: Following code not get created domain when call from different Win Application.
It's not allowed to simply "peek" in the memory of another application. You can retrieve a reference to any AppDomain within your application, but you'd have to use some form of interprocess-communication if the data has to cross the application boundary.
dataminers wrote: I think Mutex Class not related about my problem.
You said you wanted a singleton; you can create on by setting a mutex in the constructor, and releasing the mutex in the destructor. There are lots of other ways to ensure that only a single instance is created, but this would be my favorite
I are Troll
|
|
|
|