Usually we say PC controls other hardware work, refers to the PC to the corresponding hardware to send instructions to control the corresponding hardware. At the same time, after sending the instruction may receive the corresponding feedback message, tell the PC current hardware status and parameters and other data, this is the common PC and hardware communication. PMaC has helped us to encapsulate this communication process, directly call the relevant function, where the host computer to the PMAC to send instructions to control motor motion or set parameters or return the current specified parameter values.
PMAC provides Pmacgetresponse and Pmacgetresponseex to the PMAC to send instructions. This process is very similar to the terminal in which we manually send instructions to PMAC, where the two functions that support sending commands are also online commands entered in terminal.
Let's look at some of the simplest examples, add several buttons and their response functions to the dialog, and add code to the response function to do the following:
1. Setting parameters
<pre name= "code" class= "CPP" ><pre name= "code" class= "CPP" >//link Pcomm32.dll function library, Note the introduction of Myruntimelink header file Openruntimelink ();//Open PMaC Card connection openpmacdevice (0); TCHAR Szres[max_path]; TCHAR szcmd[max_path];/*****************************************************/lstrcpy (SZCMD, "p1=1");// Send instructions and receive a postback command to populate Szrespmacgetresponse (0,szres,max_path,szcmd);/************************************************ Close the PMaC card connection closepmacdevice (0);//freelibrarycloseruntimelink ();
2. Get parameter values
Link Pcomm32.dll function Library, note the introduction of Myruntimelink header file Openruntimelink ();//Open PMaC Card connection openpmacdevice (0); TCHAR Szres[max_path]; TCHAR szcmd[max_path];/*****************************************************/lstrcpy (SZCMD, "P1");// Send instructions and receive a postback command to populate Szrespmacgetresponse (0,szres,max_path,szcmd);/************************************************ Display the current parameter value AfxMessageBox (szres);//close PMaC Card connection closepmacdevice (0);//freelibrarycloseruntimelink ();
3. Control Motor Point Movement
Link Pcomm32.dll function Library, note the introduction of Myruntimelink header file Openruntimelink ();//Open PMaC Card connection openpmacdevice (0); TCHAR Szres[max_path]; TCHAR szcmd[max_path];/*****************************************************/lstrcpy (SZCMD, "#6j +");// Send instructions and receive a postback command to populate Szrespmacgetresponse (0,szres,max_path,szcmd);/************************************************ Close the PMaC card connection closepmacdevice (0);//freelibrarycloseruntimelink ();
4. Control program operation
Link Pcomm32.dll function Library, note the introduction of Myruntimelink header file Openruntimelink ();//Open PMaC Card connection openpmacdevice (0); TCHAR Szres[max_path]; TCHAR szcmd[max_path];/*****************************************************/lstrcpy (SZCMD, "&1b20r");// Send instructions and receive a postback command to populate Szrespmacgetresponse (0,szres,max_path,szcmd);/************************************************ Close the PMaC card connection closepmacdevice (0);//freelibrarycloseruntimelink ();
Note that the axis number and program number are consistent with the program you have written and downloaded.
See, in the/**/note is not very familiar with, in fact, we PEWin32 in the terminal window sent instructions, before and after the/**/is actually to establish and release the operating environment process. Many times, for the host computer program, we even need to call Pmacgetresponse and Pmacgetresponseex is enough to meet our needs .
5. Demo Program
For the overall presentation, let's integrate the above common functions into the following interface:
The corresponding operation code and the above demo code, here in order to demonstrate the convenience of each sending instructions to establish the environment and the connection to PMAC, send instructions, disconnect and release the environment, in the actual project, only need to re-instantiate or window instantiation when the environment and the connection of PMAC, Disconnect and release the environment when the window is closed or the program exits. The code is as follows:
Send instruction void Ctest1dlg::onsend () {//link Pcomm32.dll function Library, note introduction of Myruntimelink header file Openruntimelink ();// Open the PMaC card connection openpmacdevice (0); TCHAR Szres[max_path]; TCHAR szcmd[max_path];//get input to send instruction string GetDlgItemText (Ide_command, Szcmd, MAX_PATH);// Send instructions and receive a postback command to populate Szrespmacgetresponse (0,szres,max_path,szcmd);//Show Accept command Setdlgitemtext (ide_receive, szres);// Close the PMaC card connection closepmacdevice (0);//freelibrarycloseruntimelink ();} Moving in the positive direction void Ctest1dlg::onmovepos () {//link Pcomm32.dll function Library, note the introduction of Myruntimelink header file Openruntimelink ();// Open the PMaC card connection openpmacdevice (0); TCHAR Szres[max_path]; TCHAR szcmd[max_path];lstrcpy (Szcmd, "#6j +");//Display the input command string Setdlgitemtext (Ide_command, szcmd);// Send instructions and receive a postback command to populate Szrespmacgetresponse (0,szres,max_path,szcmd);//Show Accept command Setdlgitemtext (ide_receive, szres);// Close the PMaC card connection closepmacdevice (0);//freelibrarycloseruntimelink ();} Negative direction move void Ctest1dlg::onmoveneg () {//link Pcomm32.dll function Library, note introduction of Myruntimelink header file Openruntimelink ();// Open the PMaC card connection openpmacdevice (0); TCHAR Szres[max_path]; TCHAR szcmd[max_path];lstrcpy (Szcmd, "#6j-");//Display the incoming command to be sentString Setdlgitemtext (Ide_command, szcmd);//Send instruction and accept the command to be sent back to Szrespmacgetresponse (0,szres,max_path,szcmd);// Show Accept instruction Setdlgitemtext (ide_receive, szres);//close PMaC Card connection closepmacdevice (0);//freelibrarycloseruntimelink ();} stop void Ctest1dlg::onstopmove () {//link Pcomm32.dll function Library, note the introduction of Myruntimelink header file Openruntimelink ();// Open the PMaC card connection openpmacdevice (0); TCHAR Szres[max_path]; TCHAR szcmd[max_path];lstrcpy (Szcmd, "#6k");//Display the input command string Setdlgitemtext (Ide_command, szcmd);// Send instructions and receive a postback command to populate Szrespmacgetresponse (0,szres,max_path,szcmd);//Show Accept command Setdlgitemtext (ide_receive, szres);// Close the PMaC card connection closepmacdevice (0);//freelibrarycloseruntimelink ();} Back to 0 void Ctest1dlg::onhome () {//link Pcomm32.dll function Library, note the introduction of Myruntimelink header file Openruntimelink ();//Open PMAC Card connection Openpmacdevice (0); TCHAR Szres[max_path]; TCHAR szcmd[max_path];/************************************************************************//* Activating motor *//************************************************************************/lstr CPY (SZCMD, "#6j/#8j/");//Display the incoming instruction string setdlgitemtext (Ide_command, szcmd);//send instruction and receive a postback instruction to populate Szrespmacgetresponse (0, SZRES,MAX_PATH,SZCMD);//Show Acceptance instruction Setdlgitemtext (ide_receive, szres); Sleep (1000);/************************************************************************//* Call back 0 program, note here own back 0 program number *//************************************************************************/lstrcpy (SZCMD, "&1b20r") ///Display the input to send instruction string Setdlgitemtext (Ide_command, szcmd);//send instruction and accept a postback command to populate Szrespmacgetresponse (0,szres,max_path, SZCMD);//Display Accept instruction Setdlgitemtext (ide_receive, szres);//close PMaC Card connection closepmacdevice (0);//freelibrarycloseruntimelink () ;} Run program void Ctest1dlg::onrunprog () {//link Pcomm32.dll function Library, note introduction of Myruntimelink header file Openruntimelink ();// Open the PMaC card connection openpmacdevice (0); TCHAR Szres[max_path]; TCHAR szcmd[max_path];lstrcpy (Szcmd, "&1b40r");//display input to send instruction string Setdlgitemtext (Ide_command, szcmd);// Send instructions and receive a postback command to populate Szrespmacgetresponse (0,szres,max_path,szcmd);//Show Accept command Setdlgitemtext (ide_receive, szres);// Turn off the PMAC card to connect CLOsepmacdevice (0);//freelibrarycloseruntimelink ();} Stop program void Ctest1dlg::onstopprog () {//link Pcomm32.dll function Library, note the introduction of Myruntimelink header file Openruntimelink ();// Open the PMaC card connection openpmacdevice (0); TCHAR Szres[max_path]; TCHAR szcmd[max_path];lstrcpy (Szcmd, "&1b40a");//display input to send instruction string Setdlgitemtext (Ide_command, szcmd);// Send instructions and receive a postback command to populate Szrespmacgetresponse (0,szres,max_path,szcmd);//Show Accept command Setdlgitemtext (ide_receive, szres);// Close the PMaC card connection closepmacdevice (0);//freelibrarycloseruntimelink ();}
Program Demo code Download link
Original, reprint please indicate from http://blog.csdn.net/wenzhou1219
9.PMAC PC-Host computer send instructions