コード例 #1
0
void T38AI8AO::OnCbnSelchangeBrandrate()
{   bPauseMultiRead=TRUE;
	int sel=m_brandratebombox.GetCurSel();
	if (product_register_value[BAUDRATE]!=sel)
	{
		int ret=write_one(g_tstat_id,BAUDRATE,sel);
		if (ret>0)
		{  
		 if (sel==0)
		{
		Change_BaudRate(9600);
		} 
		else
		{
		Change_BaudRate(19200);
		}
		    
			product_register_value[BAUDRATE]=sel;
			InitialDialog();
		
		}
		else
		{
		  AfxMessageBox(_T("Fail"));
		}
	} 
	 
	bPauseMultiRead=FALSE;
}
コード例 #2
0
void change_com_port_and_net_work_controller_baudrate(int new_baudrate)
{
	TRACE("%d\n",new_baudrate);
	static int now_baudrate=0;
	if(now_baudrate!=new_baudrate)
		now_baudrate=new_baudrate;
	else
		return;
	showing_text=T3000VIEW_SCAN_CHANGE_NET_WORK_BAUDRATE;//for showing 
	int baudrate=19200;
	if(new_baudrate!=19200)
		baudrate=9600;
	bool found=false;
	for(int i=0;i<m_binary_search_product_background_thread.size();i++)
	{
		if(NET_WORK_CONT_PRODUCT_MODEL==m_binary_search_product_background_thread.at(i).product_class_id)
		{
			found=true;

			//Change_BaudRate(m_binary_search_product_background_thread.at(i).baudrate);/////////change to same baudrate,so next step ,read,write
			if(baudrate==9600)
				write_one(m_binary_search_product_background_thread.at(i).id,128,0);
			else
				write_one(m_binary_search_product_background_thread.at(i).id,128,1);
			write_one(m_binary_search_product_background_thread.at(i).id,131,1);/////////save nemo
		}
	}
	Change_BaudRate(baudrate);
	if(found==true)
		Sleep(4000);//////////it 's better for next step
	else
		now_baudrate=0;///////////for no net work controller
	showing_text="";//for showing 
}
コード例 #3
0
void scan_first_time()
{
	int netcontrols;
	
		m_baudrate2=19200;
	Change_BaudRate(19200);
	binarySearchforview();//***************************************scan
	


	/*
	netcontrols=m_binary_search_networkcontroller_background_thread.size();
	if(netcontrols>0)
	{
		int xx=m_binary_search_product_background_thread.size();
		for(int i=0;i<m_binary_search_product_background_thread.size();i++)
		{
			if(m_binary_search_product_background_thread.at(i).baudrate !=default_baudrate &&m_binary_search_product_background_thread.at(i).product_class_id!=NET_WORK_CONT_PRODUCT_MODEL)
			{
				change_com_port_and_net_work_controller_baudrate(m_binary_search_product_background_thread.at(i).baudrate);
				switch(default_baudrate)
				{
				case 9600:write_one(m_binary_search_product_background_thread.at(i).id ,128,0,1);break;
				case 19200:write_one(m_binary_search_product_background_thread.at(i).id ,128,1,1);break;
				}
				m_binary_search_product_background_thread.at(i).baudrate=default_baudrate;
			}
			write_one(m_binary_search_product_background_thread.at(i).id,131,1);
		}
	}
	*/

	if (gCommunicationType==0)
	{
		m_baudrate2=9600;
	Change_BaudRate(9600);
	binarySearchforview();

	}

}
void T3000_Default_MainView::OnCbnKillfocusBaudratecombo()
{
	if (product_register_value[MODBUS_BAUDRATE] == m_brandrate_combox.GetCurSel())	//Add this to judge weather this value need to change.
		return;

	/* Post_Thread_Message(MY_WRITE_ONE,g_tstat_id,MODBUS_BAUDRATE,m_baudRateCombox.GetCurSel(),
	product_register_value[MODBUS_BAUDRATE],this->m_hWnd,IDC_BAUDRATECOMBO,_T("BAUDRATE"));*/

	int ret = write_one(g_tstat_id, MODBUS_BAUDRATE, m_brandrate_combox.GetCurSel());

	int index_brandrate = m_brandrate_combox.GetCurSel();
	int brandrate = 19200;

	if (index_brandrate == 0)
	{
		brandrate = 9600;
	}
	else if (index_brandrate == 1)
	{
		brandrate = 19200;
	}
	else if (index_brandrate == 2)
	{
		brandrate = 38400;
	}
	else if (index_brandrate == 3)
	{
		brandrate = 57600;
	}
	else if (index_brandrate == 4)
	{
		brandrate = 115200;
	}
	if (GetCommunicationType() == 1)
	{
		return;
	}
	CString SqlText;

	SqlText.Format(_T("update ALL_NODE set Bautrate = '%d' where Serial_ID='%d'"), brandrate, get_serialnumber());
	Change_BaudRate(brandrate);


	CppSQLite3DB SqliteDBBuilding;
	CppSQLite3Table table;
	CppSQLite3Query q;
	SqliteDBBuilding.open((UTF8MBSTR)g_strCurBuildingDatabasefilePath);

	SqliteDBBuilding.execDML((UTF8MBSTR)SqlText);
	SqliteDBBuilding.closedb();
	CMainFrame* pFrame = (CMainFrame*)(AfxGetApp()->m_pMainWnd);
	pFrame->ScanTstatInDB();
}
コード例 #5
0
void CNetworkControllView::OnCbnSelchangeBaudrateCombx()
{
	BeginWaitCursor();
	int nSel;
	nSel=m_baudRateCombox.GetCurSel();
	int nRet=-1;
	nRet=write_one(g_tstat_id,12,nSel);
	if(nRet>0)
	{
		if(nSel==0)
		{
			m_baudRateCombox.SetCurSel(0);
			Change_BaudRate(9600);
		}
		if(nRet==1)
		{
			m_baudRateCombox.SetCurSel(1);
			Change_BaudRate(19200);
		}
	}
}
コード例 #6
0
void background_binarysearch_netcontroller()
{
	m_binary_search_networkcontroller_background_thread.clear();
	m_mac_address_list.clear();////////^0^
	net_work_is_exist_or_not=false;////////^

	m_baudrate2=19200;
	Change_BaudRate(19200);
	binarySearchforview_networkcontroller();//***************************************scan
	/*
	int xx=m_binary_search_networkcontroller_background_thread.size();
	for(int i=0;i<m_binary_search_networkcontroller_background_thread.size();i++)
	{
		if(m_binary_search_networkcontroller_background_thread.at(i).baudrate !=default_baudrate &&m_binary_search_networkcontroller_background_thread.at(i).product_class_id==NET_WORK_CONT_PRODUCT_MODEL)
		{

			switch(default_baudrate)
			{
			case 9600:write_one(m_binary_search_networkcontroller_background_thread.at(i).id ,128,0,2);break;
			case 19200:write_one(m_binary_search_networkcontroller_background_thread.at(i).id ,128,1,2);break;

			}

			Sleep(6*1000);
			write_one(m_binary_search_networkcontroller_background_thread.at(i).id,131,2);
			m_binary_search_networkcontroller_background_thread.at(i).baudrate=default_baudrate;
			SetPaneString("Please Wait,network controller is restarting. ");
		}
	}
	*/
	
	if (gCommunicationType==0)
	{
	m_baudrate2=9600;
	Change_BaudRate(9600);
	binarySearchforview_networkcontroller();
	}

}
コード例 #7
0
void keep_back_net_work()
{//keep back the net work,and turn off ,write a2
	int i=0;//for next step 
	vector <binary_search_result> ::iterator iter;//existed picture
	iter=m_binary_search_product_background_thread.begin();
	for(i=0;i<m_binary_search_product_background_thread.size();i++,iter++)
	if(NET_WORK_CONT_PRODUCT_MODEL!=m_binary_search_product_background_thread.at(i).product_class_id)
		m_binary_search_product_background_thread.erase(iter);//////////////delete
	else
	{
		Change_BaudRate(m_binary_search_product_background_thread.at(i).baudrate);
		write_one(m_binary_search_product_background_thread.at(i).id,16,0xa2);//turn to a2 mode
	}
}
コード例 #8
0
	int flash_a_tstat(BYTE m_ID,unsigned int the_max_register_number,unsigned char *register_data_orginal,int baudrate_var,int &which_register_was_interrupt)
	{
		//the return value 1,successful
		//<0 ,have some trouble
		unsigned char *register_data=register_data_orginal;
		unsigned int ii=0;
	//**************************************************inspect the flash that last flash position **
			if(read_one(m_ID,0xee10)<0)//retry times is better
			{
				//read_one from globle_function.h
				//the return value == -1 ,no connecting
				//AfxMessageBox("before write,need to open the com!");
				//close_com();
				//error -1
				return -1;
			}
			{
				//from 0000 register flash
				//from 0000 flash update
				ii=0;
				showing_text="initializing!";
				Sleep(500);
				//********************write register 16 value 0x7f **************
				int temp_baudrate=baudrate_var;//get the input baudrate
				do{
					if(ii<RETRY_TIMES)
						if(-2==Write_One(m_ID,16,0x7f))//From Common.h
						{
							ii++;
							if(ii==RETRY_TIMES && baudrate_var==9600 && temp_baudrate!=19200)
							{
								Change_BaudRate(19200);//From Common.h
								temp_baudrate=19200;
								ii=1;//
							}
							Sleep(6000);
						}
						else
							ii=0;
					else
					{
						return -2;//error -2 Unable to Initialize...
					}
				}while(ii);
				//********************write register 16 value 0x3f **************
				ii=0;
				showing_text+="erasing!";
				do{
					if(ii<RETRY_TIMES)
						if(-2==Write_One(m_ID,16,0x3f))//From common.h
							ii++;
						else
							ii=0;
					else
					{
						return -6;//error -6
					}
				}while(ii);
				//********************write register 16 value 0x1f **************
				ii=0;
				Sleep(3000);
				//must have this ,the Tstat need	
				
			}

			while(ii<=the_max_register_number)
			{
				unsigned char data_to_send[160]={0};// buffer that writefile() will to use
					int itemp=0;
					replace_flag=TRUE;
				    showing_text.Format(_T("initialized!erasing!programming!Programing progress %.1f%%"),100*((float)ii)/the_max_register_number);
					do{
						if(itemp<RETRY_TIMES)
						{   //From common.h
							if(-2==write_multi(m_ID,&register_data[ii],ii,WRITE_MUTLI_NUMBER))
								//to write multiple WRITE_MUTLI_NUMBER bytes
							{
								itemp++;
								//showing_text.Format("initialized!erasing!programming!Writing line %d to %d...",ii,ii+WRITE_MUTLI_NUMBER);
								replace_flag=TRUE;
								showing_text.Format(_T("initialized!erasing!programming!Programing progress %.1f%%"),100*((float)ii)/the_max_register_number);
							}
							else
							{
								itemp=0;
								which_register_was_interrupt=ii;
							}
						}
						else
						{
							return -8;//the com connection is wrong! error -8
						}
					}while(itemp);
					ii+=WRITE_MUTLI_NUMBER;
			}
	//********************write register 16 value 0x01 **************
			ii=0;
			which_register_was_interrupt=-9;
			//********************write register 16 value 01 **************
			do{
				if(ii<RETRY_TIMES)
					if(-2==Write_One(m_ID,16,1))
						ii++;
					else
						ii=0;
				else
				{
					return -8;//error -8
				}
			}while(ii);					
		Change_BaudRate(baudrate_var);//back baudrate
		return 1;
	}