Previously said, the host computer control hardware is sent through instructions, this is one-way. Then in turn, the next computer hardware to the host computer send instructions how to achieve it? For PMaC, the most common scenario is to notify the current PC program that a motion has been completed when the PMAC is completed.
1. The lower machine notifies the host computer principle
As shown,
The PC gives the PMAC command to control what it does, when the motion program is finished interrupt notifies the host computer, at the same time to send a logo P100 indicates the completion of the program number, this indicates whether the 1th axis movement, or the 2nd axis movement finished. On the PC side there is an interrupt callback function, after the next computer send interrupt, will automatically jump to the function, interrupt function accept interrupt, according to the identity of P100 to determine the different situations different processing.
In layman's terms, this is the process:
Pc->pmac: Send an instruction to tell it what to do (&1b40r) PMAC: Done, wait for the PC to finish processing the previous notification (while (M613 = 1) wait) pmac->pc: When you're done, PC, you just look at the deal ( P100=1 m613=1) PC: For the PMAC notification of what type of decision and processing (according to P100 judgment) Pc->pmac: finished, the next computer can send a notification message (p100=0 m613=0)
As shown, M613 this is configured with a hardware jumper, specifying the current interrupt response channel, specific settings here. P100 is our designated upper and lower machine communication variables, this is defined by itself, it can be p1/p2/p3 and so on.
2. Lower machine code
&1close; Confirm that all buffers are closed open PROG 40CLEARTA (max) TS (0) F (y) Inclinearx (x) dwell; interrupt Sender segment while (M613 = 1) wait wait for the last interrupt response processing to complete p100=1; Indicates the currently completed program, can be 0, 1, 2 and other custom values m613=1; send interrupts close
3. Host computer processing code
Register the interrupt handler function:
BOOL Cinterruptdlg::connectpmac () {//link Pcomm32.dll function Library, note the introduction of Myruntimelink header if (NULL = = Pmacruntimelink (pmac_num)) { AfxMessageBox (TEXT ("link Pcomm32.dll function library and open PMAC card connection failed!")); return m_bisconnect = FALSE;} Interrupt function Binding if ( FALSE = = Pmacintrfunccallinit (pmac_num, INTERRUPTFUNC2, 0, 0xff1f)) {AfxMessageBox (TEXT (" PMaC function Interrupt initialization failed ")); return m_bisconnect = FALSE;} return m_bisconnect = TRUE;}
The corresponding interrupt function is handled as follows:
Interrupt processing void WINAPI INTERRUPTFUNC2 (DWORD msg, Pintrbuffer pbuffer) {extern Cinterruptapp Theapp; TCHAR Szres[max_path]; TCHAR szcmd[max_path];if (Pbuffer->dwinterrupttype = = ISR_IR6) {if (1 = = pmacgetvariable (pmac_num, ' P ', 100, 0)) { AfxMessageBox (TEXT ("Processing done!")); /Reset Interrupt lstrcpy (szcmd, "m613=0 p100=0"); Pmacgetresponse (0,szres,max_path,szcmd);}}}
The demo program source code, in the program click the motor starts back to 0, back to the 0 button grayscale. Until the next machine completes back 0 send interrupts to the host computer program, the upper computer program to determine after processing enable button. This program is the simplest interrupt handler, mainly to clarify the principle, and then the complex program is the same principle, based on this principle we can develop more complex upper and lower machine interaction program.
Note that this can not be done with the default installation after the Runtime.h, the original I tried to have a problem, I must put in the program source folder in the rewrite MyRuntime.h.
More PMAC code See my website, basically all the knowledge points involved in this series.
To this end, the use of PMaC basically finished, read this series, the basic PMAC programming and debugging should be no problem, the rest is read the fuck manual.
Original, reprint please indicate from http://blog.csdn.net/wenzhou1219
12.PMAC PC-Interrupt communication (lower machine notification host computer)