Welcome, Guest. Please login or register.
Did you miss your activation email?
May 27, 2012, 09:52:29 AM

Login with username, password and session length
Search:     Advanced search
* Home Help Search Calendar Links Login Register
+  Machsupport Forum
|-+  Mach Discussion
| |-+  Mach SDK plugin questions and answers.
| | |-+  Communicate RS232 port
Pages: 1   Go Down
Print
Author Topic: Communicate RS232 port  (Read 804 times)
0 Members and 1 Guest are viewing this topic.
sams_n
Active Member

Offline Offline

Posts: 13


View Profile
« on: November 24, 2010, 03:14:48 AM »

Hi guys!

At first , sorry for my bad english , but i give my best Wink
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



















Logged
smurph
Active Member

Offline Offline

Posts: 244


View Profile
« 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
Logged
sams_n
Active Member

Offline Offline

Posts: 13


View Profile
« 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
Logged
Pages: 1   Go Up
Print
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!