Automation and Events

denilia
Member Posts: 23
hi all
I wonder is it possible to make a Navision client sit and listen for event from external module without a loop? I have a DLL that gets the data from the serial communication, process it, and set ready for use.
Right now, I have Navision in infinite loop waiting for the data. What I need is some sort of event trigger from Navision and i'm not sure how to do so.
Thank you
I wonder is it possible to make a Navision client sit and listen for event from external module without a loop? I have a DLL that gets the data from the serial communication, process it, and set ready for use.
Right now, I have Navision in infinite loop waiting for the data. What I need is some sort of event trigger from Navision and i'm not sure how to do so.
Thank you
0
Comments
-
Your automation variable has a property "WithEvents"0
-
Ok, I found that property. i started to search the forums to find some examples how it's implemented. But I cannot see my triggers like some people say.
This is a stripped DLL code:using System; using System.Collections.Generic; using System.Text; using System.IO.Ports; using System.Runtime.InteropServices; namespace Navision { [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)] public interface iSerial { [DispIdAttribute(1)] void OpenSerialPort(); void CloseSerialPort(); string GetString(); } [ClassInterface(ClassInterfaceType.None)] public class Serial : iSerial { private SerialPort sp; private string SerialString; public Serial() { } public void OpenSerialport() { try { sp = new SerialPort("COM1", 9600, Parity.None, 8, StopBits.One); sp.DataReceived += new SerialDataReceivedEventHandler(this.sp_DataReceived); sp.ReceivedBytesThreshold = 1; sp.Handshake = Handshake.None; sp.ReadTimeout = 200; sp.Open(); } catch { } } private void sp_DataReceived(object sender, SerialDataReceivedEventArgs e) { if (e.EventType == SerialData.Chars) { SetString = Data; } } public string SetString { get { return SerialString; } set { SerialString = value; } } public string GetString() { string tmp = SetString; return tmp; } public void StopSerialGun() { sp.Close(); } } }
What am I doing wrong? and Where in C/AL I can see that WithEvents trigger?0 -
You have to generate event in your DLL.
In your code is nothing to fire any event which can send a data to Navision. By the way, I think that safer way is to save the received data into a file and create timer loop in Navision to check for that file(s).0 -
Well, it needs to be real time, so i cannot use the file. however I did revise the code, and now i can see the triggers in Navision. But it does not fire the event. I can see that the event function is called, but nothing in Navision
using System; using System.Collections.Generic; using System.Text; using System.IO.Ports; using System.Runtime.InteropServices; namespace NAV_Serial_Port { [ComVisible(false)] public delegate void GetSerialtring(); [InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIDispatch)] public interface SerialEvents { [DispIdAttribute(1)] event GetSerialString MyEvent; void FireEvent(); } [InterfaceType(ComInterfaceType.InterfaceIsIDispatch)] public interface iSerial { [DispIdAttribute(2)] void OpenSerialPort(); void StopSerialport(); string GetString(); } [ClassInterface(ClassInterfaceType.None)] [ComSourceInterfaces(typeof(SerialEvents))] public class Serial : iSerial { private SerialPort sp; private string SerialString; public event GetSerialString MyEvent; public Serial() { } public void FireEvent() { if (MyEvent != null) MyEvent(); } public void CallEvent() { Serial s = new Serial(); s.MyEvent += new GetSerialString(f); s.FireEvent(); s.MyEvent -= new GetSerialString(f); } public void f() { } public void OpenSerialPort() { try { sp = new SerialPort("COM1", 9600, Parity.None, 8, StopBits.One); sp.DataReceived += new SerialDataReceivedEventHandler(this.sp_DataReceived); sp.ReceivedBytesThreshold = 1; sp.Handshake = Handshake.None; sp.ReadTimeout = 200; sp.Open(); } catch { } } public void sp_DataReceived(object sender, SerialDataReceivedEventArgs e) { if (e.EventType == SerialData.Chars) { SetString = Data; callEvent(); } } public string SetString { get { return GunString; } set { GunString = value; } } public string GetString() { string tmp = SetString; return tmp; } public void StopSerialport() { try { sp.Close(); sp.Dispose(); } catch {} } } }
0 -
I figured it out. Thanks0
-
what was wrong?0
-
I am facing the same problem. How did you solve it, Denilia?0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions