web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Unanswered

Serial Port - problem with Write()

(0) ShareShare
ReportReport
Posted on by

Hello All, 

I trying send text via serial port and I have a problem with Write function. When this function is running, application stop and I must close app from task menager.

AX2012 is running on server, I connect via RDP with ports inherit.

What is wrong?

My code:

static void Job2(Args _args)
{
System.IO.Ports.SerialPort SerialPort;

SerialPort = new System.IO.Ports.SerialPort();

SerialPort.set_PortName("COM4");
SerialPort.set_BaudRate(9600);
SerialPort.set_Parity(System.IO.Ports.Parity::None);
SerialPort.set_DataBits(8);
SerialPort.set_StopBits(System.IO.Ports.StopBits::One);
SerialPort.Open();

SerialPort.Write("something");

}

I have the same question (0)
  • Martin Dráb Profile Picture
    237,880 Most Valuable Professional on at

    Which applications stops? The client? Jobs are normally executed on client, therefore I guess that's the case.

    What did you find when you debugged your code? Where does it gets stuck?

    What do you mean by the remark about "ports inherit"? That the serial port is on your local machine, not the machine where you're running your code?

    By the way, please always use Insert > Insert Code (in the rich-formatting view) to paste source code. It preserves indentation, making code easier to read.

    This is your code, but formatted and with handling of CLR exceptions (otherwise CLR exceptions are not shown in UI):

    System.IO.Ports.SerialPort serialPort;
    
    try
    {
    	serialPort = new System.IO.Ports.SerialPort();
    
    	serialPort.set_PortName("COM4");
    	serialPort.set_BaudRate(9600);
    	serialPort.set_Parity(System.IO.Ports.Parity::None);
    	serialPort.set_DataBits(8);
    	serialPort.set_StopBits(System.IO.Ports.StopBits::One);
    	serialPort.Open();
    
    	serialPort.Write("something");
    }
    catch (Exception::CLRError)
    {
    	throw error(AifUtil::getClrErrorMessage());
    }

  • Andriej Profile Picture
    on at

    Yes, client application stops.

    Debugging show nothing... App stops on 14 line (in your code).

    pastedimage1611590573147v2.png

    Port inherit - in RDP connection:

    pastedimage1611590370287v1.png

    I have device connect to USB on my computer and connect to desktop with AX via RDP connection.

  • Martin Dráb Profile Picture
    237,880 Most Valuable Professional on at

    What device do you have in the USB port? Some kind of USB-to-SerialPort converter?

    What if you run your from the local machine? Maybe you can simply install AX client there, or create a simple console application and try it from both machines.

  • Andriej Profile Picture
    on at

    I have adruino device with other addins. I connected it only via USB, but now I think that maybe i should use RS232 to USB conventer?

    I will try to use AX client on my computer, as you say.

  • Martin Dráb Profile Picture
    237,880 Most Valuable Professional on at

    Okay, then you seem to be using an USB to COM bridge.

    Please try the suggestion to test commnication from a simple console application, before trying to run it from AX and through a remote desktop connection. Also, check once more that you're connection to the right port.

  • Andriej Profile Picture
    on at

    Maybe I had the wrong approach to this case from the beginning.

    I want send some information form AX2012 via serial port to my device. How it should works?

    Maybe need I some dll library?

  • Martin Dráb Profile Picture
    237,880 Most Valuable Professional on at

    You're already using a DLL file (System.IO.Ports.dll). You surely can use a different library, but it's not clear in which respect it should be different.

    Have you considered my suggest to test the logic in a simple console application before trying to integrate it to AX 2012 and nefore trying to call the integrated solution via RDP? If you test many things at once, than you don't know which one failed.

  • Andriej Profile Picture
    on at

    I am sorry, yes, I tested the communication outside the AX2012 on a local computer and it worked without a problem.

    I was sending a message from the serial port console, which my device received.

  • Martin Dráb Profile Picture
    237,880 Most Valuable Professional on at

    Then the code seems to be fine and it doesn't need replacing.

    The next step is running it from an AX client installed on the local machine. I assume it'll work and the problem is your attempt of doing it via RDP. But please test this hypothesis.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 611 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 529 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 285 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans