예제 #1
0
// main
int main(int argc, char* argv[]){

  ComPortHandle comPort;
  int go = TRUE; 
  char* dev;
  char a;

  a='\0';

  dev=&a;
 
  if(argc<2){//No port specified at commandline so search for attached devices

    dev=scandev();
    if(strcmp(dev,"")!=0){
  
      //printf("Attempting to open port...%s\n",dev);
      comPort = OpenComPort(dev);

    }
    else{

      printf("Failed to find attached device.\n");
      return FALSE;

    }

  }
  else{//Open port specified at commandline

    printf("Attempting to open port...%s\n",argv[1]);
    comPort = OpenComPort(argv[1]);

  }

  if(comPort > 0){  

    //printf("Connected. \n\n");
    /*
    while(go){//continue until user chooses to exit
      unsigned int command;
      command = 0xc1;
      usleep(500000);//short sleep between commands
      go=CommandDialog(comPort,command);

    }*/
    unsigned int command;
    command = 0xd2;
    CommandDialog(comPort,command);
//    printf("EXITING\n"); 
    CloseComPort(comPort);

  }

  return 0;

}
예제 #2
0
파일: rs485.c 프로젝트: HITliuyu/NES15_HEVC
/****************************************************************************
* DESCRIPTION: Initializes the RS485 hardware and variables, and starts in
*              receive mode.
* RETURN:      none
* ALGORITHM:   none
* NOTES:       none
*****************************************************************************/
void RS485_Initialize(
    void)
{
    /* baud rate */
    OpenComPort(RS485_Port);
    /* FIXME: change to numeric parameters */
    InitComPort("38400", '8', 'N', '1');

    return;
}
예제 #3
0
	foreach (QString com, AvailableComPorts()) {
		HANDLE handle = OpenComPort(com.toLocal8Bit().data());
		if (handle != INVALID_HANDLE_VALUE) {
			if (IsControlUnit(handle)) {
				::CloseHandle(handle);
				return true;
			}
			else
				return false;
		}
	}
예제 #4
0
파일: zlg_cmd.c 프로젝트: bostar/gateway
void serialport_init(void)
{
        int ret = -1;

        ret = OpenComPort(n_com_port, 115200, 8, "1", 'N');
        if (ret < 0) {
                fprintf(stderr, "Error: Opening Com Port %d\n", n_com_port);
                return;
        }else{
                printf("Open Com Port %d Success, Now begin work\n", n_com_port);
        }
}
예제 #5
0
/* ----------------------------------Main----------------------------------- */
int main(int argc, char* argv[]){

  ComPortHandle comPort;
  int go = TRUE;
  char* dev;
  char a;

  a='\0';

  dev=&a;

  if(argc<2) {
    //No port specified at commandline so search for attached devices
    dev=scandev();
    if(strcmp(dev,"")!=0) {
      //printf("Attempting to open port...%s\n",dev);
      comPort = OpenComPort(dev);

    }
    else {
      printf("Failed to find attached device.\n");
      return FALSE;
    }
  }
  else {
    //Open port specified at commandline
    printf("Attempting to open port...%s\n",argv[1]);
    comPort = OpenComPort(argv[1]);
  }

  if(comPort > 0) {
    unsigned int command;
    command = 0xd2;
    CommandDialog(comPort,command);
    CloseComPort(comPort);
  }

  return 0;
}
////////////////////////////////////////////////////////////////////////////////////////
// Open a connection
int CSTATSerialBluetooth::Connect(const char *pAddress)
{
	// already connected
	if (hComPort)
		return ITS_OK;

	if (OpenComPort(pAddress))
	{
		SetError("Connected to port %s Speed %d Bytes %d Parity %d Stop %d",
			pAddress, STATBT_BAUDRATE, STATBT_BYTESIZE, STATBT_PARITY, STATBT_STOPBITS);
		return ITS_OK;
	}

	return E_CONNECTIONFAILED;
}
예제 #7
0
MRESULT EXPENTRY ComSelectDlgProc( HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2)
{

   APIRET RetCode;

   switch(msg)
   {
      //*********************************
      case WM_INITDLG:
         RetCode = WmInitComSelect(  hwnd);
         return (MRESULT)1;


      //*********************************
      case WM_COMMAND:
         switch( SHORT1FROMMP( mp1 ) )     /* Extract the command value    */
         {
            case DID_OK:
               RetCode = OpenComPort(  hwnd);
               if (RetCode != 0)
                  break;

            case DID_CANCEL: 
               WinDismissDlg( hwnd, TRUE ); 
               return (MRESULT)FALSE;

           default:
               break;
         }
         break;


      //*********************************
      default:
         return(WinDefDlgProc(hwnd, msg, mp1, mp2));
   }
   return (MRESULT)0;
}
/*******************************************************************************
    extern message is called by a calling application
*******************************************************************************/
int  APIENTRY UpsStatus(HAB hab, ULONG msg, MPARAM mp1, PUPSSTATUS pups)
	{
		int	retcode = ERROR_BAD_COMMAND;
		int	x;
		switch(msg)
			{
				case cmd_init:
					memset(&upst, 0, sizeof(UPSSTATUS));
					upst.size = sizeof(UPSSTATUS);
					upst.strucid = STRUCTURE_ID;
					if(0 != (retcode = CloseComPort())) break;		//stops any poll, and inits the various flags
					if(pups)
						{
							upst.msgfile = pups->msgfile;
							if(upst.msgfile) sprintmsg(infostr, upst.msgfile, "CONNECT1");
							pups->infostr = infostr;
						}
					if(0 != (retcode = OpenComPort((char*)mp1))) break;
					threadid = _beginthread(MessageThread, NULL, 0x4000, NULL);
					DosSleep(1);
					if(0 != (retcode = waitformessage(hab, 0, NULL))) break;
					if(0 != (retcode = SendUPSMsg(UPS_Inf, NULL))) break;
					if(0 != (retcode = waitformessage(hab, 0, NULL))) break;
					if(0 != (retcode = SendUPSMsg(UPS_Rate, NULL))) break;
					retcode = waitformessage(hab, 0, pups);
					break;
				case cmd_info:
					if(0 != (retcode = waitformessage(hab, 0, NULL))) break;
					if(upst.msgfile) sprintmsg(infostr, upst.msgfile, "MEGATEC1",
							upspr.name, upspr.model, upspr.version,
							Mix_to_d(upspr.voltage), Mix_to_d(upspr.current), Mix_to_d(upspr.frequency),
							Mix_to_d(upspr.battery));
					break;
				case cmd_quiet:
					StopPoll = TRUE;
					if(0 != (retcode = waitformessage(hab, 0, NULL))) break;
					if(_flagtest(upst.upsstatus, stat_buzzer) ^ (!mp1))
						{
							if(0 != (retcode = SendUPSMsg(UPS_Quiet, NULL))) break;
							retcode = waitformessage(hab, 0, pups);
							break;
						}
					else retcode = NO_ERROR;
					break;
				case cmd_test:
					StopPoll = TRUE;
					if(0 != (retcode = waitformessage(hab, 0, NULL))) break;
					if(((int)mp1) == -1) retcode = SendUPSMsg(UPS_TestL, NULL);
					retcode = SendUPSMsg(UPS_Test, mp1);
					if(0 != retcode) break;
					StopPoll = FALSE;
					retcode = waitformessage(hab, 0, pups);
					break;
				case cmd_abort:
					StopPoll = TRUE;
					if(0 != (retcode = waitformessage(hab, 0, NULL))) break;
					if(_flagtest(upst.upsstatus, stat_testing)) retcode = SendUPSMsg(UPS_CancTst, NULL);
					if(0 != (retcode = waitformessage(hab, 0, NULL))) break;
					if(_flagtest(upst.upsstatus, stat_shutting)) retcode = SendUPSMsg(UPS_Cancel, NULL);
					if(0 != retcode) break;
					StopPoll = FALSE;
					retcode = waitformessage(hab, 0, pups);
					break;
				case cmd_shutdown:
					StopPoll = TRUE;
					if(0 != (retcode = waitformessage(hab, 0, NULL))) break;
					if(0 != (retcode = SendUPSMsg(UPS_Shut, mp1))) break;
					StopPoll = FALSE;
					retcode = waitformessage(hab, 0, pups);
					break;
				case cmd_exit:
					retcode = CloseComPort();
					return retcode;
				case cmd_poll:
					retcode = waitformessage(hab, 0, pups);
					pups->infostr = infostr;
					break;
				default:
					retcode = waitformessage(hab, 0, NULL);
					break;
			}
		StopPoll = FALSE;
		return retcode;
	}
예제 #9
0
int main()
{
	fd_set rfds;
	int retval, i, j;
	struct timeval tv;
	unsigned char ch;
	char sim_iccid[MAX_COMMAND_LEN], 
				  tmp[MAX_COMMAND_LEN];

	if(OpenComPort(DEVICE_NAME, 115200, 8, "1", 'N') == -1)
		return 1; /* open device failed */

	while(1){
		command_len = strlen(command);
		if(command_len > 0){
			if(write(fd, command, command_len) < 0){
				fprintf(stderr, "Failed to write to serial port.\r\n");
				fprintf(stderr, "Read SimICCID Failed!\n");
				tcsetattr (fd, TCSANOW, &termios_old);
				close(fd);
				return 2;
			}  
		}

		FD_ZERO(&rfds);
		FD_SET(fd, &rfds);

		tv.tv_sec = 0;
		tv.tv_usec = 20000;

		retval = select(fd+1, &rfds, NULL, NULL, &tv);
		if(retval <= 0){
			fprintf(stderr, "Select error...\r\n");
			fprintf(stderr, "Read SimICCID Failed!\n");
			tcsetattr (fd, TCSANOW, &termios_old);
			close(fd);
			return 2;
		}

		if(FD_ISSET(fd, &rfds)){
			i = 0;
			while((retval = read(fd, &ch, 1)) == 1)
			{
				fprintf(stderr, "%c", ch);
				tmp[i++] = ch;
			}
			tmp[i] = '\0';
			//printf("#%s#\n", tmp);
		}

		for(i = 0, j = 0; i < MAX_COMMAND_LEN; i++){

			if((ch = tmp[i]) == '\0' || (ch == 'O' && tmp[i+1] == 'K'))
				break;
			if((ch >= '0' && ch <= '9') ||
					(ch >= 'a' && ch <= 'f')){
				sim_iccid[j++] = ch;
			}
		}

		if(!j){
			usleep(500000);
			continue;
		}else{
			sim_iccid[j] = '\0';
			fprintf(stdout, "Read SimICCID[%s(%d)] successful!\n", sim_iccid, strlen(sim_iccid));

			VDRDeployParaTable *table = new VDRDeployParaTable();
			table->SetStringValue(VDR_DEPLOY_PARA_VDR_SIM_ICCID, sim_iccid);
			table->Commit();
			delete table;
			break;
		}
	}

	tcsetattr (fd, TCSANOW, &termios_old);
	close(fd);

	return 0;
}