Omron PLC Communication

/* DOS Controller / Omron PLC Add a controller with size as small as a credit card to your system so as to make your system to be IP Enabled, monitored and controlled any where and any time with only Internet Explorer

More C++, C# and VB source code on the following web sites

formatting link
formatting link
formatting link
*/ #include #include #include #include #include #include "..\include\vm.h" //============================================================================== VmDataArray *A;double *D; VmNetwork *net; VmSerialPort *comm; void scan1(void); void scan2(void); //=========================================== char

*Name[]={"di0","di1","di2","di3","di4","di5","di6","di7","di8","di9","di10","di11","di12","di13","di14","di15", "do0","do1","do2","do3","do4","do5","do6","do7","do8","do9","do10","do11","do12","do13","do14","do15", "Speed"}; unsigned int w_in=0,w_out=0; int TimeOutErr=0; //=========================================== void create(VmDataArray *DA, VmObjectList *OL){ DA->Add(Name,sizeof(Name)/2); OL->Add(net =new VmNetwork(DA,10,NULL,NULL,NULL)); OL->Add(comm=new VmSerialPort(DA, 1, // 1,2.... 9600, // 1200,2400,4800,9600,14400,19200,38400,56000,57600,115200 2, // 0:no,1:odd,2:even 7, // Number of bits/byte, 7,8 1 // 1,2 )); OL->Add(new VmSpeed (DA, "Speed")); OL->Add(new VmScan (DA,2, scan1)); //Display 2=110ms OL->Add(new VmScan (DA,1, scan2)); //I/O 1=55ms A=DA; D=DA->D; } //=========================================== void first(){ vm_cursor_off(); printf("IP Address is %s\n\r", net->IPAddress); printf("Press 'Esc' key to exit.\n\n\r"); } void loop (){} void last (){vm_cursor_on();} //=========================================== void scan1(){ gotoxy(1,7);printf("\rDI Word: %4X", w_in); gotoxy(1,8);printf("\rDO Word: %4X", w_out); gotoxy(1,9);printf("\rTimeout Error: %d", TimeOutErr); gotoxy(1,11);printf("\rController Speed:%10.0f Loops/Second",(*A)["Speed"]); gotoxy(1,15);printf("\rReceived: %-10.0f Send: %-10.0f NetRate: %-5.0f Links: %-2d ", (double)net->PacketReceived,(double)net->PacketSend,(double)net->ReceiveRate,net->Links); if(kbhit() && getch()==27) bLoop=0; } //=========================================== char buf[1024]; int I=0; char fcs[5]; int TimeOut=0; int Step=1; //=========================================== void get_fcs(char *TT){ int N=strlen(TT); unsigned char c=0; for(int i=0;ii) & 0x01; } } //=========================================== unsigned int bits2word(double *d){ unsigned int v=0,b=1; for(int i=0;i0){ if(buf[I-1]=='\r'){ buf[11]=0; w_in=strtol(buf+7,NULL,16); word2bits(w_in, D); I=0; TimeOut=0; TimeOutErr=0; Step=3; break; } } TimeOut++; if(TimeOut>20){ I=0; TimeOut=0; TimeOutErr=1; Step=3; } break; case 3: //Write a word; Send: [@][Unit no.:2][Command:2][Beginning Word:4][Data:4][FCS:2][*][CR] w_out=bits2word(D+16); char wtxt[100]; sprintf(wtxt,"@01RW1000%04X",w_out); get_fcs(wtxt); sprintf(buf,"%s%s*\r",wtxt,fcs); comm->write((unsigned char *)buf,strlen(buf)); Step=4; break; case 4: //Write a word; Receive: [@][Unit no.:2][Command:2][Response Code:2][FCS:2][*][CR] I=I+comm->read((unsigned char *)buf+I); if(I>0){ if(buf[I-1]=='\r'){ I=0; TimeOut=0; TimeOutErr=0; Step=1; break; } } TimeOut++; if(TimeOut>20){ I=0; TimeOut=0; TimeOutErr=1; Step=1; } break; } } //=========================================== int main(int argc, char *argv[]){ return vm_controller(argc, argv); } //===========================================
Reply to
vmautomation
Loading thread data ...

Controller as small as a credit card? Monitored anywhere with only Internet Explorer?? Methinks that's a pipe dream..

Cameron:-)

Reply to
Cameron Dorrough

I've always found the I/O take so much more space that the size of the controller itself is not very important.

Walter.

Reply to
Walter Driedger

PolyTech Forum website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.