Machsupport Forum
Mach Discussion => Mach SDK plugin questions and answers. => Topic started by: sams_n 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
-
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
-
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