/*===========================================================================

FUNCTION DIAG_DTR_ENABLE

DESCRIPTION
  Invoked when Diag initializes. This registers a callback with SIO that is
  intended to report when there are DTR changes.

PARAMETERS
  None
  
RETURN VALUE
  None
  
===========================================================================*/
void diag_dtr_enable( diagcomm_io_conn_type * conn )
{
  sio_ioctl_param_type ioctl_param;

  ASSERT( conn != NULL);
  ASSERT( conn->io_type == DIAGCOMM_IO_TYPE_SIO );
  
  /* Register DTR callback for SMD and SIO ports */
    ioctl_param.enable_dte_ready_event_ext.cb_func = diag_dtr_changed_cb;
     
    //Set up call back data - since we are interested in knowing SIO stream_id when 
    //call back comes we are passing port info to SIO for MPSS  
    ioctl_param.enable_dte_ready_event_ext.cb_data = (void *)conn;
  
    if ( conn->channel_type == DIAGCOMM_IO_CTRL )
    {
      // Set DTR using sio_control_ioctl for control channel
      sio_control_ioctl ( conn->handle.sio_handle,
                  (uint32)SIO_IOCTL_ENABLE_DTR_EVENT_EXT,
                  (void*)&ioctl_param );
    }
    else if ( conn->channel_type == DIAGCOMM_IO_DATA )
    {
    // Set DTR using sio_ioctl for data channel
      sio_ioctl ( conn->handle.sio_handle,
                  (uint32)SIO_IOCTL_ENABLE_DTR_EVENT_EXT,
                  (void*)&ioctl_param );
    }

 } /* diag_dtr_enable */
/*===========================================================================

FUNCTION DIAG_DTR_CHANGED_CB

DESCRIPTION
  Invoked when DTR changes. This is intended to flip a variable that causes
  Diag to vote/not vote for sleep based on connectivity status.

PARAMETERS
  cb_data - Diag I/O connection handle
  
RETURN VALUE
  None
  
===========================================================================*/
void diag_dtr_changed_cb( void * cb_data )
{
  sio_ioctl_param_type param;
  boolean dte_ready_asserted;
      
  diagcomm_io_conn_type * conn = (diagcomm_io_conn_type *)cb_data; 

  ASSERT( conn != NULL );
  ASSERT( conn->io_type == DIAGCOMM_IO_TYPE_SIO );

  param.dte_ready_asserted = &dte_ready_asserted;
  
  if( conn->port_type == DIAGCOMM_PORT_SIO )
  {
    if( conn->channel_type == DIAGCOMM_IO_CTRL )
    {
	  sio_control_ioctl( conn->handle.sio_handle, SIO_IOCTL_DTE_READY_ASSERTED, &param );
      diagcomm_sio_ctrl_conn_changed( conn, dte_ready_asserted );
    }
    else if( conn->channel_type == DIAGCOMM_IO_DATA )
    {
	  sio_ioctl( conn->handle.sio_handle, SIO_IOCTL_DTE_READY_ASSERTED, &param );
      diagcomm_sio_conn_changed( conn, dte_ready_asserted );
    }
  }
  else if( conn->port_type == DIAGCOMM_PORT_SMD )
  {
  }

  {
    if( conn->channel_type == DIAGCOMM_IO_CTRL )
    {
      sio_control_ioctl( conn->handle.sio_handle, SIO_IOCTL_DTE_READY_ASSERTED, &param );
    }
    else if( conn->channel_type == DIAGCOMM_IO_DATA )
    {
      sio_ioctl( conn->handle.sio_handle, SIO_IOCTL_DTE_READY_ASSERTED, &param );
    }

	diagcomm_smd_conn_changed( conn, dte_ready_asserted );
  }
  
  MSG_3(MSG_SSID_DIAG, MSG_LEGACY_HIGH,"diag_dtr_changed_cb: port=%d, channel=%d, \
        status=%d", conn->port_type, conn->channel_type, conn->channel_connected);

}  /* diag_dtr_changed_cb */
예제 #3
0
파일: SerialPort.cpp 프로젝트: Raxtion/CT74
//---------------------------------------------------------------------------
bool __fastcall CSerialPort::Open(int nPort,int nBaudRate,int nMode)
{
        m_nPortNo=nPort;
  if(sio_open(nPort)!=SIO_OK)
    return false;

  //if(sio_ioctl(nPort,B9600,BIT_8|STOP_1|P_NONE)!=SIO_OK)
        if( sio_ioctl(nPort,nBaudRate,nMode) != SIO_OK )
                return false;

  //sio_SetReadTimeouts(nPort,MAXDWORD,2000);

	return true;
}
예제 #4
0
 /******************* Start Scan ***************/
 void CMainFrame:: OnStartscan()
 {
	 if(SIO_OK!=sio_open(Port))
		{
			MessageBox("串口打开错误");
			return;
		}
   else
		{
			sio_ioctl(Port,BaudRate,DataBits | StopBits | Parity);
			sio_cnt_irq(Port,CntIrq,1);
		}

   Scan_num=0;
   OnBtnSend(num);
   //OnBtnSend('1');
 }
예제 #5
0
//初始化端口
BOOL CComm_Thread::Init_ComPort()
{
    COApp* pApp=(COApp*)AfxGetApp();
    unsigned int x_Baud[]= {B300,B600,B1200,B2400,B4800,B9600,B19200,B38400,B57600};

    if(CommLink)
        return false;

    if(sio_open(pApp->x_Port)!=0)
        return false;

    sio_ioctl(pApp->x_Port,x_Baud[pApp->x_Order],P_NONE|BIT_8|STOP_1);
    sio_SetReadTimeouts(pApp->x_Port,200,200);
    sio_flush(pApp->x_Port,2);

    return true;
}
예제 #6
0
파일: Gyro.cpp 프로젝트: WangRobo/S2BOT
/***************************************************************
【函数功能】: 打开串口
【输    入】: port:串口号(默认0)。【构造函数时也可指定串口号】
【输    出】: 执行结果:0正确,-1错误。
【说    明】: 正确用法有3种:<1> CGyro *p = new CGyro(n);  p->open();
					<2> CGyro *p = new CGyro(n); p->open(n);
					<3> CGyro *p = new CGyro;   p->open(n);
***************************************************************/
int CGyro::Open(int port)
{
	if(m_bPortOpened)
		return 1;
	// 读取配置
	string iniFile = string(INI_FILE);
	//if (mrpt::system::fileExists(iniFile) == false)	// INI 文件找不到
	//{
	//	cout << "!Gyro惯导:start():找不到ini文件!" << iniFile << endl;
	//	return -1;	
	//}					// ini文件在主窗口init时检查一次即可,不存在则退出
	mrpt::utils::CConfigFile INI_Cfg(iniFile);
	m_iPort = INI_Cfg.read_int("Gyro", "COM_Port", 0);

	// 如果形参有传入,则以传入值为主,并修改ini文件
	if (port > 0)
	{
		INI_Cfg.write("Gyro", "COM_Port", port);	// 用传入形参更新配置文件数据
		m_iPort = port;
	}
	else
	{
		if (m_iPort <= 0)
		{
			cout<<"[!!!] Gyro: 必须指定一个大于0的串口号!"<<endl;
			return -1;
		}
	}
	// 打开串口
	if(sio_open(m_iPort) != SIO_OK)
	{
		cout<<"[!!!] Gyro: 打开串口错误!"<<endl;
		return -1;
	}
	sio_ioctl(m_iPort, B115200, P_NONE | BIT_8 | STOP_1 );
	sio_cnt_irq(m_iPort,RecvCall, 1);

	m_bPortOpened = true;
	cout<<"[+] Gyro: Started!"<<endl;

	return 0;
}
예제 #7
0
파일: Sensor.cpp 프로젝트: WangRobo/S2BOT
/***************************************************************
【函数功能】: 打开串口
【输    入】: port:串口号(默认0)。【构造函数时也可指定串口号】
【输    出】: 执行结果:0正确,-1错误。
【说    明】: 正确用法有3种:<1> CSensor *p = new CSensor(n);  p->open();
					<2> CSensor *p = new CSensor(n); p->open(n);
					<3> CSensor *p = new CSensor;   p->open(n);
***************************************************************/
int CSensor::Open(int port)
{
	if(m_bPortOpened)
		return -1;
	// 读取配置
	
	string iniFile = string(INI_FILE);
	//if (mrpt::system::fileExists(iniFile) == false)	// INI 文件找不到
	//{
	//	cout << "!Sensor传感:start():找不到ini文件!" << iniFile << endl;
	//	return -1;	
	//}						// ini文件在主窗口init时检查一次即可,不存在则退出
	mrpt::utils::CConfigFile INI_Cfg(iniFile);
	m_iPort = INI_Cfg.read_int("Sensor", "COM_Port", 0);
	// 读取传感器位置及配置
	std::vector<double> aux; // Auxiliar vector
	std::stringstream sname;
	for (int i=0; i<NUM_OF_USENSOR; i++)
	{
		sname.str("");
		sname.clear();
		sname<<"pose"<<i;
		INI_Cfg.read_vector("Sensor", sname.str(), aux, aux, false);
		m_pUS[i].pose = TPose3D( aux[0], aux[1], aux[2], 
			DEG2RAD( (double)aux[3]), DEG2RAD( (double)aux[4]), DEG2RAD( (double)aux[5]) );
		m_pUS[i].stopZone = (double)aux[6];
		m_pUS[i].id = i;
		m_pUS[i].distance = 2.0;	// 初始值设为2m
		m_pUS[i].bValid = true;		// 初始化都有效
	}
	m_timestamp_US = mrpt::system::now();
	// 如果形参有传入,则以传入值为主,并修改ini文件
	if (port > 0)
	{
		INI_Cfg.write("Sensor", "COM_Port", port);	// 用传入形参更新配置文件数据
		m_iPort = port;
	}
	else
	{
		if (m_iPort <= 0)
		{
			cout<<"[!!!] Sensor: 必须指定一个大于0的串口号!"<<endl;
			return -1;
		}
	}
	// 打开串口
	if(sio_open(m_iPort) != SIO_OK)
	{
		cout<<"[!!!] Sensor: 打开串口错误!"<<endl;
		return -1;
	}
	sio_ioctl(m_iPort, B115200, P_NONE | BIT_8 | STOP_1 );
	sio_cnt_irq(m_iPort,RecvCall, 1);
	// 创建发送线程
	m_bSendThreadStopFlag = false;
	//m_hSendThreadHandle = CreateThread(NULL,NULL,
	//				(LPTHREAD_START_ROUTINE)SendThread,this,NULL,NULL);
	m_hSendThreadHandle = (HANDLE)_beginthread(SendThread, 0, this);
	////////////////////////////////
	m_bPortOpened = true;
	cout<<"[+] Sensor: Started !"<<endl;
	return 0;
}