Hello Guest it is March 28, 2024, 10:24:49 PM

Author Topic: Communicate RS232 port  (Read 3488 times)

0 Members and 1 Guest are viewing this topic.

Communicate RS232 port
« on: November 24, 2010, 03:14:48 AM »
Hi guys!

At first , sorry for my bad english , but i give my best ;)
I am a absolute beginner in C++, I saw the video tuturials and want to try it.
Simple things as SetDRO(Y_DRO,input_wert);  or DoButton(FEEDRATE_RESET);
are running without problems.

Now I am trying to write a plugin to use the serialport. for I/O's.
In the MachIncludes Folder I found the Headerfile serialport.h.
It comes from PJ Naugther. On the web I found the freeware MFC class for Win32 serial ports from him.
I added the serialport.cpp and the serialport.h to my projekt and tryed the following small
code for opening and close the port.

CSerialPort port;
port.Open(3, 19200, CSerialPort::NoParity, 8,
CSerialPort::OneStopBit,
CSerialPort::NoFlowControl);
port.Close();

Port3 is o.k. , I tested it with an other programm before, the compiler runs without errors.
But when i run it in mach3 the computer hangs.
My questions:
Is it a good way to use the serialport.cpp and serialport.h ?
What can I do to get it to run ?
Are there other (better) methodes to communicate with the RS232 port ?

Best regards, Gerhard



















Offline smurph

*
  • *
  •  1,544 1,544
  • "That there... that's an RV."
    • View Profile
Re: Communicate RS232 port
« Reply #1 on: December 11, 2010, 12:42:28 AM »
I would use the Windows API to do the serial port duties.  Have a look at CreateFile(), WriteFile(), ReadFile(), and DeviceIoControl();

CreateFile uses the NT namespace to open a device.  "\\.\COM1" would operate on COM1, etc...  Remember that the backslash is an escape character in C/C++, so in the code, the device path would be "\\\\.\\COM1"

Steve
Re: Communicate RS232 port
« Reply #2 on: December 13, 2010, 10:52:16 AM »
Hi,

i found the bug.
Now it's all o.k.
I had turned on the serial modbus in mach3 ,
so the serialport was opened when starting up mach3
and blocked for further use by my plugin.
A really silly mistake from me.

Best regards , Gerhard