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 http://members.optusnet.com.au/vmautomation/index.htm http://www.vmcontrol.com/english/index.htm http://www.vmcontrol.com/index.htm */ #include <stdlib.h> #include <stdio.h> #include <conio.h> #include <string.h> #include <math.h> #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 20ms OL->Add(new VmScan (DA,1, scan2)); //I/O 1Ums A; D->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 () //==========================================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()=') 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;i<N;i++) c=c^(unsigned char )TT[i]; sprintf(fcs,"%02X",c); } //==========================================void word2bits(double w, double *d){ unsigned int v=(unsigned int)w; for(int i=0;i<16;i++){ d[i]=(v>>i) & 0x01; } } //==========================================unsigned int bits2word(double *d){ unsigned int v=0,b=1; for(int i=0;i<16;i++){ if(d[i]) v=v+b; b=b<<1; } return v; } //==========================================void scan2(){ switch(Step){ case 1: //Read a word; Send: [@][Unit no.:2][Command:2][Beginning Word:4][No. of words:4][FCS:2][*][CR] char rtxt[]="@01RR10000001"; get_fcs(rtxt); sprintf(buf,"%s%s*\r",rtxt,fcs); comm->write((unsigned char *)buf,strlen(buf)); Step=2; break; case 2: //Read a word; Receive: [@][Unit no.:2][Command:2][End Code:2][Data:4][FCS:2][*][CR] // 7 11 I=I+comm->read((unsigned char *)buf+I); if(I>0){ 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); } //==========================================
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload

Controller as small as a credit card? Monitored anywhere with only Internet Explorer?? Methinks that's a pipe dream..
Cameron:-)
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
I've always found the I/O take so much more space that the size of the controller itself is not very important.
Walter.

Internet
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload

Polytechforum.com is a website by engineers for engineers. It is not affiliated with any of manufacturers or vendors discussed here. All logos and trade names are the property of their respective owners.