/* HWML Motion Controller Interface (C) Aryeh Eiderman */ #ifndef __HWML_H #define __HWML_H 1 #ifdef __cplusplus extern "C" { #endif /*** COMMUNICATION INTERFACE ***/ // SERIAL CONNECTION START // 1. Open serial port at desired baudrate (for example 921600), // 8 data bits, no parity, 1 stop bit, no handshaking, // DTR and RTS off // 2. Reset Controller // a. Set DTR on // b. Wait 0.1 second // c. Set DTR off // 3. Wait 1 second // 4. Send auto-baud initialization char - 0x41 ('A') // 5. Send carriage return char - 0x0D // 6. Receive carriage return char - 0x0D // BINARY COMMUNICATION INTERFACE // Query: // 1. Send binary prefix char - '\0' // 2. Send command char // 3. Send four long values (16 bytes), -2147483648 as dummy // Answer: // 1. Read one byte defining following data size (0 or 16) // 2. If data size is 16 read four long values (16 bytes) // LITERAL COMMUNICATION INTERFACE // Query: // 1. Send literal string that includes: // a. Command char // b. Up to four decimal numbers delimited with ',' char // c. Optional comment after ';' char // 2. Send '\r' (CR) char // Answer: // 1. Read till '\r' (CR) char while getting: // a. Up to four decimal numbers delimited with ',' char // INTERRUPT DIRECTIVES // after sending Query of Execute Queue, while waiting to Answer // Abort (Emergency Stop) // 1. Send Ctrl-A char - 0x01 // Break (Pause) // 1. Send Ctrl-B char - 0x02 // if Queue is still running while getting Break directive // it will freeze and wait for Continue or Abort directive // Continue (Resume) // 1. Send Ctrl-C char - 0x03 // Decelerate and Abort (Graceful Stop mostly for Jog) // 1. Send Ctrl-D char - 0x04 // Report // Query // 1. Send Ctrl-R char - 0x12 // Answer // 1. Read one byte defining following data size (always 18) // 2. Read two bytes of signed short Queue Run Position (+1) // 3. Read four bytes of long X coordinate // 4. Read four bytes of long Y coordinate // 5. Read four bytes of long Z coordinate // 6. Read four bytes of long W coordinate /*** PROGRAM INTERFACE ***/ /* SPECIALS */ #define HWML_NO_VALUE 0x80000000L // use -2147483648 as binary dummy #define HWML_MAX_LITERAL_ANSWER_SIZE 48 // min buf size for lit answer #define HWML_DONT_ANSWER(c) ((('a'<=(c))&&((c)<='z'))?((c)&0xdf):(c)) /* FIRMWARE/HARDWARE COMMANDS */ #define HWML_VERSION '?' // I,O,H,L - ID, OS ID, Hi, Lo - read only #define HWML_PORT '!' // N,A,B,R - port num, addr, baud, resolution #define HWML_PIN_STEP '~' // X,Y,Z,W - 0, +/- 2..9 #define HWML_PIN_DIR '^' // X,Y,Z,W - 0, +/- 2..9 #define HWML_PIN_LIM_N '[' // X,Y,Z,W - 0, +/- 1, 10..17 #define HWML_PIN_LIM_P ']' // X,Y,Z,W - 0, +/- 1, 10..17 #define HWML_PIN_INP '{' // A,B,C,D - 0, +/- 1, 10..17 #define HWML_PIN_OUTP '}' // E,F,G,H - 0, +/- 1..9, 14, 16, 17 #define HWML_UNIT_MULT '_' // X,Y,Z,W - revolution distance - info only #define HWML_UNIT_DIV '`' // X,Y,Z,W - steps per revolution - info only #define HWML_RATIO '&' // X,Y,Z,W - Rate scale %, calc man by '_'/'`' #define HWML_INPUTS '<' // A,B,C,D - 0/1 - read only #define HWML_OUTPUTS '>' // E,F,G,H - 0/1 (immediate) /* MOVEMENT COMMANDS */ #define HWML_POSITION 'p' // X,Y,Z,W - abs position now #define HWML_VELOCITY 'v' // F,B,M,A - feed, base, max (rapid), accel #define HWML_WORKMODE 'w' // M,A,T,D - R/L/CW/CCW, pln, a/n/cnt, abs/rel #define HWML_LIMITS 'l' // X,Y,Z,W - out - 0/4 ena/dis, in - 0/1/2/3 #define HWML_Q_STOP 'c' // A,B,C,D - 0/1 - emergency inputs #define HWML_Q_MISC 'b' // E,F,G,H - 0/1 - switch outputs on queue #define HWML_Q_DWELL 'h' // P - dwell (msec) #define HWML_Q_ADD 'q' // X,Y,Z,W - next queue (contour) line/arc #define HWML_Q_ARC 'u' // I,J,K,R - last queued arc center offsets #define HWML_Q_EXEC 'e' // G - queue (contour) exec times, >=1 #define HWML_Q_RANGE 'r' // C - queue (contour) size, in - avail /*** API ***/ /* STARTUP/EXIT */ void *HWML_Open(const char *Connection); // i.e. "COM5: 921600" void HWML_Close(void **pHWMLHandle); /* ONE-SHOT CONVERSATION */ int HWML_TalkBinary(void *HWMLHandle, const char Command, // command char const long QValue1, // value or HWML_NO_VALUE const long QValue2, // value or HWML_NO_VALUE const long QValue3, // value or HWML_NO_VALUE const long QValue4, // value or HWML_NO_VALUE long *pAValue1, // pointer to value or NULL long *pAValue2, // pointer to value or NULL long *pAValue3, // pointer to value or NULL long *pAValue4 // pointer to value or NULL ); int HWML_TalkLiteral(void *HWMLHandle, const char *Query, // command char, nums flwd by ',' char *Answer // if not NULL - nums flwd by ',' ); /* ADVANCED CONVERSATION */ int HWML_IsConnectionOK(void *HWMLHandle); int HWML_WaitForAnswer(void *HWMLHandle, int OrReport // break on rep if 1, ret is 2 ); int HWML_Poll(void *HWMLHandle); // 0 - none, 1 - answ, 2 - rep void HWML_Sleep(unsigned long Milliseconds); int HWML_SendBinary(void *HWMLHandle, const char Command, // command char const long QValue1, // value or HWML_NO_VALUE const long QValue2, // value or HWML_NO_VALUE const long QValue3, // value or HWML_NO_VALUE const long QValue4 // value or HWML_NO_VALUE ); int HWML_ReceiveBinary(void *HWMLHandle, long *pAValue1, // pointer to value or NULL long *pAValue2, // pointer to value or NULL long *pAValue3, // pointer to value or NULL long *pAValue4 // pointer to value or NULL ); int HWML_SendLiteral(void *HWMLHandle, const char *Query // command char, nums flwd by ',' ); int HWML_ReceiveLiteral(void *HWMLHandle, char *Answer // if not NULL - nums flwd by ',' ); int HWML_AbortQueueExecution(void *HWMLHandle); int HWML_PauseQueueExecution(void *HWMLHandle); int HWML_ResumeQueueExecution(void *HWMLHandle); int HWML_AbortQueueExecutionGraceful(void *HWMLHandle); int HWML_ReportQueueExecution(void *HWMLHandle, signed short *pQueuePos, long *pX, long *pY, long *pZ, long *pW ); int HWML_RequestQueueExecutionReport(void *HWMLHandle); int HWML_ReceiveQueueExecutionReport(void *HWMLHandle, signed short *pQueuePos, long *pX, long *pY, long *pZ, long *pW ); /* LPT EMULATION */ // LPT-IO SERIAL INTERFACE // -------------------------------------------------------------------- // | BYTE | BIT | REQUEST | ANSWER | // |============|=====|=========================|=======================| // | Command | 7 | Always 1 | Always 1 | // | | 6 | 1 - CONTROL byte to set | 1 - CONTROL byte info | // | | 5 | 1 - STATUS byte to set | 1 - STATUS byte info | // | | 4 | 1 - DATA byte to set | 1 - DATA byte info | // | | 3 | Always 1 | Always 0 | // | | 2 | 1 - Get CONTROL byte | Always 0 | // | | 1 | 1 - Get STATUS byte | Always 0 | // | | 0 | 1 - Get DATA byte | Always 0 | // |------------|-----|-------------------------------------------------| // | Supplement | 7-0 | Optional DATA byte if Command bit 4 is 1 | // |------------|-----|-------------------------------------------------| // | Supplement | 7-0 | Optional STATUS byte if Command bit 5 is 1 | // |------------|-----|-------------------------------------------------| // | Supplement | 7-0 | Optional CONTROL byte if Command bit 6 is 1 | // -------------------------------------------------------------------- int HWML_PerformLPT(void *HWMLHandle, unsigned char *pDATAToSet, unsigned char *pSTATUSToSet, unsigned char *pCONTROLToSet, unsigned char *pDATAToGet, unsigned char *pSTATUSToGet, unsigned char *pCONTROLToGet); /*** ***/ #ifdef __cplusplus } #endif #endif