/* 7188 FarCon -------------------------- RX <--------- TX TX ---------> RX RTS ---------> CTS CTS <--------- RTS GND ---------- GND If in I-7188 use COM1,need set RTS high,or FarCOn will not response. If in I-7188 use COM3/4 --> there are not CTS and RTS,In the FarCon side just short CTS and RTS(pin 7 & 8 on D-Type 9 pin connecter) */ #include #include #include #include"..\lib\7188.h" unsigned char PlcCmd[256]; int PlcCmdLen; int PlcComPort=1; /* use I-7188's COM1 */ int PlcStation=1; /* default station no=1 */ /* command: for example: "410" STOP "411" RUN "423Y0001" set Y1 to high "424Y0001" reset Y1 to low */ int SendPlcCmd(int station,unsigned char *s) /* s: command */ { unsigned char sum; int i; PlcCmdLen=0; sum=2; PlcCmd[PlcCmdLen++]=2; /* STX */ sum+=(PlcCmd[PlcCmdLen++]=hex_to_ascii[(station>>4)&0xF]); sum+=(PlcCmd[PlcCmdLen++]=hex_to_ascii[station&0xF]); while(*s){ sum+=*s; PlcCmd[PlcCmdLen++]=*s++; } PlcCmd[PlcCmdLen++]=hex_to_ascii[sum>>4]; PlcCmd[PlcCmdLen++]=hex_to_ascii[sum&0xF]; PlcCmd[PlcCmdLen++]=3; /* ETX */ for(i=0;i