www.pudn.com > MOXA--DOS.rar > C104P.H
// declare comm fuction according to moxa card #if !defined(__MODEMC_H) #include#endif #if !defined(__FILEC_H) #include #endif #define SENDDATAOK 0 #define OK 1 #define NOT 0 #define HAVEDATA 1 #define NODATA 0 #define SC_SENDANSWER 's' #define SC_RECANSWER 'r' #define SC_NOTREADY 'n' #define SC_RECOK 'o' #define SC_RECNOT 'k' #define MC_REQDATA 'R' #define MC_SENDDATA 'S' #define MC_RECNOT 'K' #define MC_RECOK 'O' #define DATAHEAD '!' #define CLEARDATA ' ' #define DelayBSend 1 #define RPortTryTime 1000 //must be!! #define WaitCommandAnswerTime 80 //old 50 //#define WaitLastAnswerTime 50 #define WaitLastAnswerTime 100 #define WaitDataHeadTime 50 //type C104P C168P C102 //#ifdef (MultiPortCardMOXA) /* #if defined(MultiPortCardMOXA) #if defined(__TINY__)||defined(__SMALL__) #elif defined(__MEDIUM__) #error MultiPortCard Type Not Yet defined! #elif defined(__LARGE__) #elif defined(__HUGE__)||(__COMPACT__) #endif #else // #error MultiPortCard Not Yet defined! #endif */ #define B50 0x00 #define B75 0x01 #define B110 0x02 #define B134 0x03 #define B150 0x04 #define B300 0x05 #define B600 0x06 #define B1200 0x07 #define B1800 0x08 #define B2400 0x09 #define B4800 0x0A #define B7200 0x0B #define B9600 0x0C #define B19200 0x0D #define B38400 0x0E #define B57600 0x0F #define B115200 0x10 #define B230400 0x11 #define B460800 0x12 #define B921600 0x13 /* MODE setting */ #define BIT_5 0x00 /* Word length define */ #define BIT_6 0x01 #define BIT_7 0x02 #define BIT_8 0x03 #define STOP_1 0x00 /* Stop bits define */ #define STOP_2 0x04 #define P_EVEN 0x18 /* Parity define */ #define P_ODD 0x08 #define P_SPC 0x38 #define P_MRK 0x28 #define P_NONE 0x00 /* MODEM CONTROL setting */ #define C_DTR 0x01 #define C_RTS 0x02 /* MODEM LINE STATUS */ #define S_CTS 0x01 #define S_DSR 0x02 #define S_RI 0x04 #define S_CD 0x08 #if !defined C104P_C //#error no use extern unsigned char no_data; extern int Recs_Error; extern int Resc_Error; //extern union VR vr; #ifdef __cplusplus extern "C" { #endif extern void cdecl port_init(const int port); //initital port extern void cdecl lattice_init(const int port); extern void cdecl waijian_init(const int port); extern void cdecl port_init_low(const int port,const int baud, char parity,char databit, char stopbit); extern void cdecl port_init_tp(const int port); extern void cdecl port_init_tp_panyu(int port); extern void cdecl port_init_nanhaidd(int port); extern void cdecl port_init_cgtp(int port); extern unsigned char cdecl r_status(const int port); extern void cdecl sport(const int,const char); extern void cdecl sport2(const int port, const unsigned char ch); extern void cdecl send_string(const int,char*); extern void cdecl SendString(const int port,char *str, const int num); extern void cdecl send_string2(const int port, char *str, const int num); extern void cdecl SendStringEcho(const int port,char *str,const int num); extern void cdecl SendStringEcho3(const int port,char *str, const int num); extern unsigned char cdecl rport(const int); extern unsigned char cdecl rports(const int port); extern unsigned char cdecl rport2(const int port,unsigned char *chget); extern int cdecl rportWy(const int port, char *charin); extern char * cdecl rec_string(const int,const int); extern char * cdecl RecStringEcho(const int port,const int bytes); /* Error time.Resc_Error =1 */ extern char * cdecl RecStringEcho3(const int port,const int bytes); /* Error time.Resc_Error =1 */ extern char cdecl McRecString2(const int port,unsigned char *str, const int bytes); /* Error time.Resc_Error =1 */ extern char cdecl McRecString3(const int port,unsigned char *str, const int bytes); /* Error time.Resc_Error =1 */ extern void cdecl MakeVerify(unsigned char *str, const int bytes); extern int cdecl Verify(unsigned char *str, const int bytes); extern int cdecl Verify1(unsigned char *str, const int bytes); extern void cdecl MakeVerify1(unsigned char *str, const int bytes); extern void cdecl rport3(const int port,unsigned char *chget); extern void cdecl port_init_pywj(const int WjPortS,const int WjPortX); extern void cdecl Fqport_init(const int port); extern int cdecl sio_reset(void); extern int cdecl sio_getports(int *port_no_array, int array_size); extern int cdecl sio_loopback(int port, char *buf, int len); extern int cdecl sio_ioctl(int port, int baud, int mode); extern int cdecl sio_getch(int port); extern int cdecl sio_linput(int port, char *buf, int len, int term); extern int cdecl sio_read(int port, char *buf, int len); extern int cdecl sio_putch(int port, int term); extern int cdecl sio_putb(int port, char *buf, int len); extern int cdecl sio_write(int port, char *buf, int len); extern int cdecl sio_flush(int port, int func); extern long cdecl sio_iqueue(int port); extern long cdecl sio_ifree(int port); extern long cdecl sio_oqueue(int port); extern long cdecl sio_ofree(int port); extern int cdecl sio_lstatus(int port); extern int cdecl sio_lctrl(int port, int mode); extern int cdecl sio_term_irq(int port, void (interrupt far *func)(), char code); extern int cdecl sio_cnt_irq(int port, void (interrupt far *func)(), int count); extern int cdecl sio_modem_irq(int port, void (interrupt far *func)()); extern int cdecl sio_break_irq(int port, void (interrupt far *func)()); extern int cdecl sio_break(int port, int time); extern int cdecl sio_brk_cnt(int port); extern int cdecl sio_flowctrl(int port, int mode); extern int cdecl sio_Tx_hold(int port); extern int cdecl sio_disableTx(int port); extern int cdecl sio_enableTx(int port); extern int cdecl sio_close(int port); extern int cdecl sio_open(int port); extern long cdecl sio_getbaud(int port); extern int cdecl sio_getmode(int port); extern int cdecl sio_getflow(int port); extern int cdecl sio_timeout(int time_tic); extern int cdecl sio_linput_t(int port, char *buf, int len, int term); extern int cdecl sio_putb_t(int port, char *buf, int len); extern int cdecl sio_overflow(int port); extern int cdecl sio_overlap(int port, int mode); extern int cdecl sio_cardno(int drvname); extern int cdecl sio_id(int drvname, int card); extern int cdecl sio_bank(int drvname, int card); extern int cdecl sio_linked(int drvname, int card); extern int cdecl sio_view(int port, char *ibuf, int len); extern int cdecl sio_disableIRQ(int port, int intrr_type); extern int cdecl sio_enableIRQ(int port, int intrr_type); extern int cdecl sio_DTR(int port, int mode); extern int cdecl sio_RTS(int port, int mode); extern int cdecl sio_baud(int port, long speed); extern int cdecl sio_ignore_errdata(int port, int mode); extern int cdecl sio_data_status(int port); extern int cdecl sio_putb_x(int port, char *buf, int len, int delay); extern int cdecl sio_disableRx(int port); extern int cdecl sio_enableRx(int port); extern int cdecl sio_getACs(int drvname, int card, int *serial_no_array, int array_size); extern int cdecl sio_ACstate(int drvname, int serial); extern long cdecl sio_ACdiag(int drvname, int serial); #ifdef __cplusplus } #endif #else unsigned char no_data = 0; int Recs_Error; int Resc_Error; //union VR vr; #ifdef __cplusplus extern "C" { #endif //fuction copy from headc.h" int cdecl sio_reset(void); int cdecl sio_getports(int *port_no_array, int array_size); int cdecl sio_loopback(int port, char *buf, int len); int cdecl sio_ioctl(int port, int baud, int mode); int cdecl sio_getch(int port); int cdecl sio_linput(int port, char *buf, int len, int term); int cdecl sio_read(int port, char *buf, int len); int cdecl sio_putch(int port, int term); int cdecl sio_putb(int port, char *buf, int len); int cdecl sio_write(int port, char *buf, int len); int cdecl sio_flush(int port, int func); long cdecl sio_iqueue(int port); long cdecl sio_ifree(int port); long cdecl sio_oqueue(int port); long cdecl sio_ofree(int port); int cdecl sio_lstatus(int port); int cdecl sio_lctrl(int port, int mode); int cdecl sio_term_irq(int port, void (interrupt far *func)(), char code); int cdecl sio_cnt_irq(int port, void (interrupt far *func)(), int count); int cdecl sio_modem_irq(int port, void (interrupt far *func)()); int cdecl sio_break_irq(int port, void (interrupt far *func)()); int cdecl sio_break(int port, int time); int cdecl sio_brk_cnt(int port); int cdecl sio_flowctrl(int port, int mode); int cdecl sio_Tx_hold(int port); int cdecl sio_disableTx(int port); int cdecl sio_enableTx(int port); int cdecl sio_close(int port); int cdecl sio_open(int port); long cdecl sio_getbaud(int port); int cdecl sio_getmode(int port); int cdecl sio_getflow(int port); int cdecl sio_timeout(int time_tic); int cdecl sio_linput_t(int port, char *buf, int len, int term); int cdecl sio_putb_t(int port, char *buf, int len); int cdecl sio_overflow(int port); int cdecl sio_overlap(int port, int mode); int cdecl sio_cardno(int drvname); int cdecl sio_id(int drvname, int card); int cdecl sio_bank(int drvname, int card); int cdecl sio_linked(int drvname, int card); int cdecl sio_view(int port, char *ibuf, int len); int cdecl sio_disableIRQ(int port, int intrr_type); int cdecl sio_enableIRQ(int port, int intrr_type); int cdecl sio_DTR(int port, int mode); int cdecl sio_RTS(int port, int mode); int cdecl sio_baud(int port, long speed); int cdecl sio_ignore_errdata(int port, int mode); int cdecl sio_data_status(int port); int cdecl sio_putb_x(int port, char *buf, int len, int delay); int cdecl sio_disableRx(int port); int cdecl sio_enableRx(int port); int cdecl sio_getACs(int drvname, int card, int *serial_no_array, int array_size); int cdecl sio_ACstate(int drvname, int serial); long cdecl sio_ACdiag(int drvname, int serial); //end of copy. //by xf in shenzhen 98/09/15. void cdecl port_init(const int port); //initital port void cdecl lattice_init(const int port); void cdecl waijian_init(const int port); void cdecl port_init_low(const int port,const int baud, char parity,char databit, char stopbit); void cdecl port_init_tp(const int port); void cdecl port_init_tp_panyu(int port); void cdecl port_init_nanhaidd(int port); void cdecl port_init_cgtp(int port); unsigned char cdecl r_status(const int port); void cdecl sport(const int,const char); void cdecl sport2(const int port, const unsigned char ch); void cdecl send_string(const int,char*); void cdecl SendString(const int port,char *str, const int num); void cdecl send_string2(const int port, char *str, const int num); void cdecl SendStringEcho(const int port,char *str,const int num); void cdecl SendStringEcho3(const int port,char *str, const int num); unsigned char cdecl rport(const int); unsigned char cdecl rports(const int port); unsigned char cdecl rport2(const int port,unsigned char *chget); int cdecl rportWy(const int port, char *charin); char * cdecl rec_string(const int,const int); char * cdecl RecStringEcho(const int port,const int bytes); char * cdecl RecStringEcho3(const int port,const int bytes); char cdecl McRecString2(const int port,unsigned char *str, const int bytes); char cdecl McRecString3(const int port,unsigned char *str, const int bytes); void cdecl MakeVerify(unsigned char *str, const int bytes); int cdecl Verify(unsigned char *str, const int bytes); int cdecl Verify1(unsigned char *str, const int bytes); void cdecl MakeVerify1(unsigned char *str, const int bytes); void cdecl rport3(const int port,unsigned char *chget); void cdecl port_init_pywj(const int WjPortS,const int WjPortX); void cdecl Fqport_init(const int port); #ifdef __cplusplus } #endif #undef C104P_C #endif #if defined( Uses_DCommunication ) && !defined( __DCommunication ) #define __DCommunication #define MAXBUFFER 211 class DCommunication { private: int tail, head; public: int status, count, time_out, port, sendlen; char ret; unsigned char getdata, block[MAXBUFFER]; DCommunication(); ~DCommunication(); DCommunication(int inputPort,int inputSenlen,unsigned char far inputBlack[],int inputTime_out); void get(int order,int port,int senlen,unsigned char far black[]); int isSendSuccess(); DCommunication& subCom3(DCommunication&); DCommunication& receiveCommand(DCommunication&); }; int DCommunication::isSendSuccess(){ return status;} DCommunication& DCommunication::subCom3(DCommunication&) { MakeVerify1((char *)block, sendlen); do{ if((time_out++>250)||(kbhit())) { status = 0; return *this; } ret = rport2(port,&getdata); }while(ret==NODATA); if(getdata== MC_REQDATA) { sport2(port, SC_SENDANSWER); SendStringEcho3(port,(char *)block,sendlen); //wait answer for(count=0;count