//Example code for communicating with SOM1 int idComDev; //ID of comm device struct tagDCB dcb; //structure of comm device info int err; //returned error code if unable to write to comm port; int StringLength; //Length of data to be sent (always=2); bool Relay1,Relay2,Relay3,Relay4; //Status of Relays 1=Operated; int Deviceaddress; //Address of SOM1 as selected by DIP switch on the SOM1 char SentString[5]; //Data srtring char temp_str[20]; //String used to set up comm ports int PortNumber; //Number of comm port (ie 1 for comm1, 2 for comm2 etc); char temp_str2[20]; //String used for setting up comm port number // Open Comm Port strcpy(temp_str,"COM"); itoa(PortNumber,temp_str2,10); strcat(temp_str,temp_str2); idComDev = OpenComm(temp_str, 1024, 128); // Set port to required number and buffers if (idComDev < 0) { //Error handling code } strcat(temp_str,":2400,n,8,1"); //set comm port to 2400 baud, with no parity, 8 data bits, and 1 stop bit //Build Comm Port structure err = BuildCommDCB(temp_str, &dcb); if (err < 0) { //Error handling code CloseComm(idComDev); } err = SetCommState(&dcb); if (err < 0) { CommPortOpen=FALSE; CloseComm(idComDev); } //Send data to SOM1 StringLength=2; SentString[0]=i; SentString[1]=(Relay1*128)+(Relay2*64)+(Relay3*32)+(Relay4*16); SentString[2]=NULL; err=WriteComm(idComDev, &SentString,StringLength); // if (err <0) { err=GetCommError( idComDev,NULL); } //Close Comm Port if (CommPortOpen) CloseComm(idComDev);