Exemplo n.º 1
0
int main ( int argc, char **argv) {
  int mySerialPortNumber;
  char p_readBuffer[BUFLEN];
  char p_writeBuffer[BUFLEN]="MEAS?5\r\n";
  int flowControl;
  char p_deviceFile[50];
  
  mySerialPortNumber = 0;
  flowControl=HARDWARE_FLOW_CONTROL;
  strcpy(p_deviceFile,"/dev/ttyS0");
  
  				/* Default values */
  initSerialPort2(mySerialPortNumber);
  setBaudRate2(mySerialPortNumber,9600);
  setNumberOfDataBits2(mySerialPortNumber,8);
  setParity2(mySerialPortNumber,NO_PARITY);
  setNumberOfStopBits2(mySerialPortNumber,1);
/*  if ( strlen(p_deviceFile)>0 ) {
    setDeviceFile2(mySerialPortNumber,p_deviceFile);
  } */

  setFlowControl2(mySerialPortNumber,flowControl);

  #ifdef DEBUG2
  printf( __FILE__ "[%d] +---------------------------------------\n", __LINE__);
  printf( __FILE__ "[%d] serialPortName: %s\n", 
		  __LINE__, getSerialPortName2(mySerialPortNumber));
  printf(__FILE__ "[%d] baudRate = %d\n", 
		   __LINE__, getBaudRate2(mySerialPortNumber));
  printf(__FILE__ "[%d] numberOfDataBits = %d\n", 
		   __LINE__, getNumberOfDataBits2(mySerialPortNumber));
  printf(__FILE__ "[%d] parity (NONE=%d,ODD=%d,EVEN=%d) = %d\n", 
		   __LINE__, NO_PARITY, ODD_PARITY, EVEN_PARITY, 
		   getParity2(mySerialPortNumber));
  printf(__FILE__ "[%d] numberOfStopBits = %d\n", 
		   __LINE__, getNumberOfStopBits2(mySerialPortNumber));
  printf( __FILE__ "[%d] flowControl = %d (NONE=%d,HARD=%d,SOFT=%d,BOTH=%d)\n",
		  __LINE__,flowControl, NO_FLOW_CONTROL, HARDWARE_FLOW_CONTROL, 
		  SOFTWARE_FLOW_CONTROL, COMBINED_FLOW_CONTROL);
  printf( __FILE__ "[%d] +---------------------------------------\n", __LINE__);
  #endif

  if (openSerialPort2(mySerialPortNumber) <= ERROR ) {
    printf("could not open serial port\n");
    return(ERROR);
  }

  writeSerialPort2(mySerialPortNumber, p_writeBuffer);
  sleep(1);

  p_readBuffer[0] = 0;
  readSerialPort2(mySerialPortNumber, p_readBuffer,BUFLEN);
  printf( __FILE__ "[%d] p_readBuffer = >%s< (%d)\n", 
			      __LINE__, p_readBuffer, strlen(p_readBuffer));
  
  closeSerialPort2(mySerialPortNumber);
  return(SUCCESS);
}
Exemplo n.º 2
0
Arquivo: gps.c Projeto: annunal/IDSL
void initGPS()
{
	ttyGPS = openSerialPort2(Configuration.gpsSerial, Configuration.gpsRate);
	if (ttyGPS==0)
	{  printf("GPS does not exist at %s\n",Configuration.gpsSerial);
	   return;
	   }
	//>>> to enable RXM-RAW
	//unsigned char init1[26] = {0xB5, 0x62, 0x9, 0x1, 0x10, 0x0, 0xC8, 0x16, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x97, 0x69, 0x21, 0x0, 0x0, 0x0, 0x2, 0x10, 0x2B, 0x22, 0x0D, 0x0A};
	//>>> to enable RXM-SFRB
	//unsigned char init2[26] = {0xB5, 0x62, 0x9, 0x1, 0x10, 0x0, 0x0C, 0x19, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x83, 0x69, 0x21, 0x0, 0x0, 0x0, 0x2, 0x11, 0x5F, 0xF0, 0x0D, 0x0A};
	
	unsigned char init[] = {0xB5, 0x62, 0x06, 0x01, 0x03, 0x00, 0x02, 0x10, 0x01, 0x1D, 0x66, 0x0D, 0x0A};
	//unsigned char poll[10]={0xB5, 0x62, 0x02, 0x10, 0x00, 0x00, 0x12, 0x38, 0x0D, 0x0A};

	int written=write(ttyGPS->_fileno,init,sizeof(init)/sizeof(unsigned char));
	fflush(ttyGPS);
	printf("written=%i\n",written);
	//tcdrain(ttyGPS);
	//write(ttyGPS->_fileno,init1,26);
	//write(ttyGPS->_fileno,init2,26);
	//sleep(1);
	printf("GPS Initialized\n");
}
Exemplo n.º 3
0
static long dsetInit_devAiAsyncSerial(aiRecord *pai) {
  CONTEXT *p_myContext;
  CALLBACK *p_myCallback;
  int myPortNumber;
  int myPrimaryAddress;
  int myNumberOfDataBits;
  int myParity;
  int myNumberOfStopBits;
  int myBaudRate;
  char p_myCommand[BUFLEN];

  packageInfo();
  dsetLog(3, __FILE__ "[%d] -> %s(%s)\n", __LINE__, __func__, pai->name);

  p_myContext=(CONTEXT *)calloc(1,sizeof(CONTEXT));
  p_myCallback=(CALLBACK *)calloc(1,sizeof(CALLBACK));
  callbackSetUser(pai,p_myCallback);
  callbackSetCallback(myCallback_devAiAsyncSerial,p_myCallback);
  p_myContext->p_callback=p_myCallback;

  pai->dpvt = (void *)p_myContext;


  if (sscanf(pai->inp.value.instio.string, 
	"spn=%d spa=%d br=%d nodb=%d p=%d nosb=%d c=%[^\n]",
	&myPortNumber,
	&myPrimaryAddress,
	&myBaudRate,
	&myNumberOfDataBits,
	&myParity,
	&myNumberOfStopBits,
        p_myCommand)!=7) {
      dsetLog(1, __FILE__ "[%d] Error: Couldn't parse paramters\n", __LINE__);
      dsetLog(1, __FILE__ "[%d] Error: Parameters >%s<\n",
                            __LINE__, pai->inp.value.instio.string);
      sleep(SLEEPTIME_ERROR);
      return(ERROR);
  }

  dsetLog(5,__FILE__ "[%d] portNumber      = %d\n",__LINE__,myPortNumber);
  dsetLog(5,__FILE__ "[%d] baudRate        = %d\n",__LINE__,myBaudRate);
  dsetLog(5,__FILE__ "[%d] parity          = %d\n",__LINE__,myParity);
  dsetLog(5,__FILE__ "[%d] numberOfDataBits= %d\n",__LINE__,myNumberOfDataBits);
  dsetLog(5,__FILE__ "[%d] numberOfStopBits= %d\n",__LINE__,myNumberOfStopBits);
  dsetLog(5,__FILE__ "[%d] serialCommand   = >%s<\n",__LINE__,p_myCommand);

  initSerialPort2(myPortNumber);
  setBaudRate2(myPortNumber,myBaudRate);
  setNumberOfDataBits2(myPortNumber,myNumberOfDataBits);
  setParity2(myPortNumber,myParity);
  setFlowControl2(myPortNumber,COMBINED_FLOW_CONTROL); 
 /*  setFlowControl2(myPortNumber,NO_FLOW_CONTROL); 
  *  Required for this dev */
  setNumberOfStopBits2(myPortNumber,myNumberOfStopBits);

  openSerialPort2(myPortNumber);

  p_myCallback=(CALLBACK *)calloc(1,sizeof(CALLBACK));
  callbackSetCallback(myCallback_devAiAsyncSerial,p_myCallback);
  callbackSetUser(pai,p_myCallback);

  p_myContext=(CONTEXT *)calloc(1,sizeof(CONTEXT));
  p_myContext->portNumber=myPortNumber;
  p_myContext->p_callback=p_myCallback;
  p_myContext->primaryAddress=myPrimaryAddress;
  strncpy(p_myContext->p_command, p_myCommand, BUFLEN);
  pai->dpvt=(void *)p_myContext;

  dsetLog(3, __FILE__ "[%d] <- %s\n", __LINE__, __func__);
  return(SUCCESS);
} 
Exemplo n.º 4
0
static long dsetInit_devMbboAsyncSerial(mbboRecord *pmbbo) {
  CONTEXT *p_myContext;
  CALLBACK *p_myCallback;	
  int mySerialPrimaryAddress;
  int mySerialPortNumber;
  int myParity;
  int myNumberOfDataBits;
  int myNumberOfStopBits;
  int myBaudRate;
  char p_myCommand[BUFLEN];

  packageInfo();	
  dsetLog(3,__FILE__ "[%d] -> %s (%s)\n", __LINE__, __func__, pmbbo->name);

  if(sscanf(pmbbo->out.value.instio.string,
	 "spn=%d spa=%d br=%d nodb=%d p=%d nosb=%d c=%[^\n]",
	&mySerialPortNumber, &mySerialPrimaryAddress, &myBaudRate, 
	&myNumberOfDataBits, &myParity, &myNumberOfStopBits,
	p_myCommand)!=7) {
    dsetLog(1,__FILE__ "[%d] Error: Couldn't parse the parameters correctly!\n",
		    __LINE__ );
    dsetLog(1,__FILE__ "[%d] Params >%s<!\n", 
		    __LINE__, pmbbo->out.value.instio.string );
    sleep(SLEEPTIME_ERROR);
    return(ERROR);
  } 

  initSerialPort2(mySerialPortNumber);
  setBaudRate2(mySerialPortNumber,myBaudRate);
  setNumberOfDataBits2(mySerialPortNumber,myNumberOfDataBits);
  setParity2(mySerialPortNumber,myParity);
/* setFlowControl2(mySerialPortNumber,NO_FLOW_CONTROL); Required for this dev */
  setNumberOfStopBits2(mySerialPortNumber,myNumberOfStopBits);

  if (openSerialPort2(mySerialPortNumber) <= ERROR ) {
    dsetLog(1, __FILE__ "[%d] Error: Couldn't open serial port (%s)\n",
                 __LINE__, getSerialPortName2(mySerialPortNumber));
    sleep(SLEEPTIME_ERROR);
    return(ERROR);
  }


  dsetLog(5,__FILE__ "[%d] serialPortNumber       = %d\n", 
		__LINE__, mySerialPortNumber);
  dsetLog(5,__FILE__ "[%d] serialPrimaryAddress   = %d\n", 
		__LINE__, mySerialPrimaryAddress);
  dsetLog(5,__FILE__ "[%d] baudRate         = %d\n", 
		__LINE__, getBaudRate2(mySerialPortNumber));
  dsetLog(5,__FILE__ "[%d] numberOfDataBits = %d\n",
		__LINE__, getNumberOfDataBits2(mySerialPortNumber));
  dsetLog(5,__FILE__ "[%d] parity           = %d\n", 
		__LINE__, getParity2(mySerialPortNumber));
  dsetLog(5,__FILE__ "[%d] numberOfStopBits = %d\n",
		__LINE__, getNumberOfStopBits2(mySerialPortNumber));

  p_myCallback=(CALLBACK *)calloc(1,sizeof(CALLBACK));
  callbackSetCallback(myCallback_devMbboAsyncSerial,p_myCallback);
  callbackSetUser(pmbbo,p_myCallback);
 
  p_myContext=(CONTEXT *)calloc(1,sizeof(CONTEXT));
  p_myContext->serialPortNumber=mySerialPortNumber;
  p_myContext->p_callback=p_myCallback;
  p_myContext->serialPrimaryAddress=mySerialPrimaryAddress;
  strncpy(p_myContext->p_command, p_myCommand, BUFLEN);
  p_myContext->operatingMode=NORMAL_MODE;

  #ifdef WARMSTART
  p_myContext->operatingMode=WARMSTART_MODE;
  pmbbo->pini=1;
  pmbbo->omsl=menuOmslclosed_loop;
  #endif

  pmbbo->dpvt=(void *)p_myContext;

  dsetLog(3, __FILE__ "[%d] <- %s\n", __LINE__, __func__);

  return(SUCCESS);

} 
Exemplo n.º 5
0
int main ( int argc, char **argv) {
  int mySerialPortNumber;
  int regAddr=-1;
 
  #ifdef DEBUG1 
  printf( __FILE__ "[%d] -> %s\n", __LINE__, __func__);
  #endif

  mySerialPortNumber = SERIAL_PORT_NUMBER;
  
  				/* Default values */
  initSerialPort2(mySerialPortNumber);
  setBaudRate2(mySerialPortNumber,9600);
  setNumberOfDataBits2(mySerialPortNumber,8);
  setParity2(mySerialPortNumber,NO_PARITY);
  setNumberOfStopBits2(mySerialPortNumber,1);
  setFlowControl2(mySerialPortNumber,NO_FLOW_CONTROL);

  #ifdef DEBUG2
  printf( __FILE__ "[%d] +---------------------------------------\n", __LINE__);
  printf( __FILE__ "[%d] serialPortName: %s\n", 
		  __LINE__, getSerialPortName2(mySerialPortNumber));
  printf(__FILE__ "[%d] baudRate = %d\n", 
		   __LINE__, getBaudRate2(mySerialPortNumber));
  printf(__FILE__ "[%d] numberOfDataBits = %d\n", 
		   __LINE__, getNumberOfDataBits2(mySerialPortNumber));
  printf(__FILE__ "[%d] parity (NONE=%d,ODD=%d,EVEN=%d) = %d\n", 
		   __LINE__, NO_PARITY, ODD_PARITY, EVEN_PARITY, 
		   getParity2(mySerialPortNumber));
  printf(__FILE__ "[%d] numberOfStopBits = %d\n", 
		   __LINE__, getNumberOfStopBits2(mySerialPortNumber));
  printf( __FILE__ "[%d] +---------------------------------------\n", __LINE__);
  #endif

  if (openSerialPort2(mySerialPortNumber) <= ERROR ) {
    printf("could not open serial port\n");
    return(ERROR);
  }

  printf("Enter register address [0-55] (test registers are 57(ro) 58(rw)): ");
  scanf("%d", &regAddr);
  do { 
  printf("--- Write ---\n");
  writeReg(regAddr); 
  sleep(1);
  printf("--- Read  ---\n");
  readReg(regAddr);
  }  while(1==1) ;

/*
  for (i=0;i<47;i++) {
    readReg(i);
    sleep(5);
  }
  */



  fflush(stdout);

  
  
  closeSerialPort2(mySerialPortNumber);
  #ifdef DEBUG1 
  printf( __FILE__ "[%d] <- %s\n", __LINE__, __func__);
  #endif
  return(SUCCESS);
}
Exemplo n.º 6
0
/* initialize the epics record and the hardware */
static long dsetInit_devAiAsyncSerial(aiRecord *pai)
{
  CONTEXT *p_myContext;
  CALLBACK *p_myCallback;	
  char p_writeBuffer[BUFLEN];
  char p_readBuffer[BUFLEN];
  int myPrimaryAddress;
  int myPortNumber;
  int myParity;
  int myNumberOfDataBits;
  int myNumberOfStopBits;
  int myBaudRate;
  char p_myCommand[BUFLEN];

  #ifdef DEBUG1
  packageInfo();	
  printf(__FILE__ "[%d] -> %s (%s)\n", __LINE__, __func__, pai->name);
  #endif

				/* Parse the db file paramters		*/
				/* and set the value of key variables	*/
  if(sscanf(pai->inp.value.instio.string,
	 "spn=%d pad=%d br=%d nodb=%d p=%d nosb=%d c=%[^\n]",
	&myPortNumber, &myPrimaryAddress, &myBaudRate, 
	&myNumberOfDataBits, &myParity, &myNumberOfStopBits, p_myCommand)!=7) {
    printf( __FILE__ "[%d] Error: Couldn't parse the parameters correctly!", 
		    __LINE__ );
    printf( __FILE__ "[%d] >%s<!", __LINE__, pai->inp.value.instio.string );
    sleep(SLEEPTIME_ERROR);
    return(ERROR);
  } /* end_of_if */

  initSerialPort2(myPortNumber);
  setBaudRate2(myPortNumber,myBaudRate);
  setNumberOfDataBits2(myPortNumber,myNumberOfDataBits);
  setParity2(myPortNumber,myParity);
  setFlowControl2(myPortNumber,NO_FLOW_CONTROL); /* Required for this dev */
  setNumberOfStopBits2(myPortNumber,myNumberOfStopBits);

  #ifdef DEBUG2
  printf(__FILE__ "[%d] portNumber       = %d\n", 
		__LINE__, myPortNumber);
  printf(__FILE__ "[%d] primaryAddress   = %d\n", 
		__LINE__, myPrimaryAddress);
  printf(__FILE__ "[%d] baudRate         = %d\n", 
		__LINE__, getBaudRate2(myPortNumber));
  printf(__FILE__ "[%d] numberOfDataBits = %d\n",
		__LINE__, getNumberOfDataBits2(myPortNumber));
  printf(__FILE__ "[%d] parity           = %d\n", 
		__LINE__, getParity2(myPortNumber));
  printf(__FILE__ "[%d] numberOfStopBits = %d\n",
		__LINE__, getNumberOfStopBits2(myPortNumber));
  printf(__FILE__ "[%d] p_myCommand      = >%s<\n", 
		 __LINE__, p_myCommand); 
  #endif

  if (lockSerialPort2(myPortNumber,LOCK, pai->name)<=ERROR) {
	printf( __FILE__ "[%d] Error: Couldn't lock serial port (%s)\n",
			__LINE__, getSerialPortName2(myPortNumber));
	sleep(SLEEPTIME_ERROR);
	return(ERROR);
  }
  				/* Disable front panel 			*/
				/* This operation should work if 	*/
				/* communication parameters are ok	*/
  strcpy(p_writeBuffer,"XFRONT");
  strcat(p_writeBuffer,TERMINATOR); 

  openSerialPort2(myPortNumber);
  if (writeSerialPort2(myPortNumber, p_writeBuffer ) <= ERROR) {
	printf( __FILE__ "[%d] Error: Couldn't write on %s\n",
			__LINE__, getSerialPortName2(myPortNumber));
	sleep(SLEEPTIME_ERROR);
	return(ERROR);
  }
  usleep(USLEEPTIME_WRITE);

  memset(p_readBuffer,0,BUFLEN);

  if (readSerialPort2(myPortNumber, p_readBuffer, BUFLEN) <= ERROR) {
	printf( __FILE__ "[%d] Error: Couldn't read on %s\n",
			__LINE__, getSerialPortName2(myPortNumber));
	sleep(SLEEPTIME_ERROR);
	return(ERROR);
  }
  usleep(USLEEPTIME_READ);
  if (lockSerialPort2(myPortNumber,UNLOCK, pai->name)<=ERROR) {
    printf ( __FILE__ "Error");
    sleep(SLEEPTIME_ERROR);
    return(ERROR);
  }


  p_myCallback=(CALLBACK *)calloc(1,sizeof(CALLBACK));
  callbackSetCallback(myCallback_devAiAsyncSerial,p_myCallback);
  callbackSetUser(pai,p_myCallback);
 
  p_myContext=(CONTEXT *)calloc(1,sizeof(CONTEXT));
  p_myContext->portNumber=myPortNumber;
  p_myContext->p_callback=p_myCallback;
  p_myContext->primaryAddress=myPrimaryAddress;
  strncpy(p_myContext->p_command, p_myCommand, BUFLEN);
  pai->dpvt=(void *)p_myContext;

				/* Check acknowledgement		*/
  if (strncmp(p_readBuffer,"OK",2)!=0) {
      printf( __FILE__ "[%d] Error: Couldn't communicate with  %s\n",
		      __LINE__, pai->name);
      printf( __FILE__ "[%d] Check configuration parameters?\n", __LINE__);
      return(ERROR);
  }

  #ifdef DEBUG1
  printf( __FILE__ "[%d] <- %s\n", __LINE__, __func__);
  #endif

  return(SUCCESS);

} /* end init_press_record() */