Example #1
0
// Enviar el estado al PLC
void CSiemensSR::SendEstado(BYTE *ptrDatos)
{
	if (!IsConnected ())
	{
		MSGERROR ("CSiemensSR::SendEstado () No Conectado");
		CAlarma * ptrAlarma = new CAlarma;
		ptrAlarma->AvisarAlarma (6,4,0);
		return; // Michael: XXX ver que hacer 27.11.2001
		// Process(DO_OPEN);
	}
	memcpy (m_SendBuf, ptrDatos, MAXESTADOSENDPLC);
	m_DataLen = MAXESTADOSENDPLC;
	MSGTRACE("CSiemensSR::SendEstado(). Before Process");
	Process (DO_SEND_EOM);
	MSGTRACE("CSiemensSR::SendEstado(). After Process");
	delete ptrDatos;
}
Example #2
0
bool
TestView::SetTest(BMessage *msg)
{
	STRACE(("\nTestView::SetTest\n"));
	if (!msg)
		return false;
	
	MSGTRACE(msg);
	
	// The easy way to update fTest is just copy the whole thing and update
	// the mode and value from the controls. This saves some conditionals when
	// dealing with attribute tests. The fields sent by the menu items (and passed
	// to this function) are the exact same as what is needed by RuleRunner's test code
	// There is one catch, however. The message passed here will NOT have the mode
	// or value, so we need to save them and copy them over
	
	BString str, mode, value;
	
	fTest->FindString("mode",&mode);
	fTest->FindString("value",&value);
	*fTest = *msg;
	
	fTest->what = 0;
	
	if (fTest->FindString("mode",&str) != B_OK)
		fTest->AddString("mode",mode);
	
	if (fTest->FindString("value",&str) != B_OK)
		fTest->AddString("value",value);
	
	
	BString label;
	
	fTest->FindString("name",&str);
	int32 testtype;
	if (str == "Attribute")
	{
		fTest->FindString("typename",&str);
		label = str;
		fTest->FindString("attrname",&str);
		label << " : " << str;
		testtype = TEST_TYPE_STRING;
		
		// Truncate the label because it is likely too long for the button
		be_plain_font->TruncateString(&label,B_TRUNCATE_SMART,
									fTestButton->Bounds().Width() - 10.0);
	}
	else
	{
		label = str;
		testtype = RuleRunner::GetDataTypeForTest(label.String());
	}
	
	fTestButton->SetLabel(label.String());
	
	// Now that the test button has been updated, make sure that the mode currently
	// set is supported by the current test
	int32 modetype = RuleRunner::GetDataTypeForMode(fModeButton->Label());
	if (testtype != modetype && modetype != TEST_TYPE_ANY)
	{
		STRACE(("Modes not compatible, refreshing.\n"));
		// Not compatible, so reset the mode to something compatible
		BMessage modes;
		RuleRunner::GetCompatibleModes(testtype,modes);
		
		BString modestr;
		modes.FindString("modes",0,&modestr);
		SetMode(modestr.String());
	}
	STRACE(("-------------------------\n"));
	
	return true;
}
Example #3
0
void CSiemensSR::Response(RB1 *rb)
{
	WORD response;
	SR_RBH *rb_H;
	static int pp = 0;

	if (rb == NULL)
		return;

	rb_H = (SR_RBH *) rb;
	
	/* check success/failure */
	response = rb_H->rb_response;
	if ((response % 2) == 0 || response == REQ_WAITING)
	{
		/* print out opcode and response */
		MSGERROR3 ("Error in \"%s\"\nrb_response = %s (%d)", 
			GetOpcodeString(rb_H->rb_opcode), GetResponseString(response), 
			response);

		CString strTemp;
		strTemp.Format (IDS_ERRSIEMENSSR, 
			GetOpcodeString(rb_H->rb_opcode),
			GetResponseString(response),
			response);

		CAlarma * ptrAlarma = new CAlarma;
		ptrAlarma->AvisarAlarma (6,2,0,0,0,0,0,0,0,strTemp);

		switch (response)
		{
		case REM_ABORT:
		case ILLEGAL_REQ:
		// Michael 08.07.2008
		case UNKNOWN_REFERENCE:
		// Michael 08.07.2008 fin
			MSGFATAL ("Cerrando comunicacion con el PLC por Error");
			m_fConnected = FALSE;	// Michael 27.11.2001
		}

		// Michael 29.01.2002
		switch (rb_H->rb_opcode)
		{
		case SEND_CONN_REQ:
		case OPEN_REQ:
			// Si ha dado error en la conexión, no va más
			MSGFATAL ("Fatal Siemens Error");
			g_Container.m_fSiemensFatalError = true;
		case RECEIVE_DATA:
			MSGFATAL ("Response () : Anulando receive por error en recepción");
			m_fReceivePend = false; // para que se inicie otro cuando se envíe algo
		}


		return;
	}

	switch (rb_H->rb_opcode) 
	{	
		case OPEN_REQ: 
			/* save reference to the opened connection */
			if (rb_H->rb_response == OK_RESP)
			{
				m_OpenRef = rb->rb.open.open_reference;
				Process(DO_CONNECT);
			}
			return;
		case SEND_CONN_REQ: 
			m_fConnected = TRUE;
			m_fConnecting = FALSE;
			Process(DO_SEND_EOM); // PC es activo - iniciar send al CP
			return;
		case SEND_EOM_DATA: 
			MSGTRACE ("CSiemensSR::Response (): rb_opcode = SEND_EOM_DATA");
			// Michael 29.01.2002 Solo si no hay recieve pendiente
			if (!m_fReceivePend)
				Process(DO_RECEIVE);	
		
			return;
		case RECEIVE_DATA:
			MSGTRACE ("CSiemensSR::Response (): rb_opcode = RECEIVE_DATA");
			VerMensajeRecibido ();
			Process(DO_RECEIVE); // Preparar siguiente lectura
			MSGAVISO ("CSiemensSR::Response (): Siguiente Recepcion pedido");

			return; 
		case CLOSE_REQ: 
			m_OpenRef = 0;
			m_fConnected = FALSE;
			// Michael 22.11.2001 SendMessage(m_hWnd, WM_DESTROY, 0, 0);
			return;
	}

}
Example #4
0
TestView::TestView(const BRect &frame,const char *name, BMessage *test,
					const int32 &resize,const int32 &flags)
 :	BView(frame,name,resize,flags),
 	fTest(NULL)
{
	SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));

	// Find the longest name in all the tests
	RuleRunner::GetTestTypes(fTestTypes);
	int32 i = 0;
	BString teststr, widesttest, widestmode;
	while (fTestTypes.FindString("tests",i,&teststr) == B_OK)
	{
		i++;
		if (teststr.CountChars() > widesttest.CountChars())
			widesttest = teststr;
	}
	
	// This will hopefully accomodate some of the attribute strings
	teststr = "Netpositive Password";
	if (teststr.CountChars() > widesttest.CountChars())
		widesttest = teststr;
	
	fTestButton = new BButton(BRect(0,0,1,1),"testbutton",widesttest.String(),
								new BMessage(M_SHOW_TEST_MENU));
	fTestButton->ResizeToPreferred();
	AddChild(fTestButton);
	
	BRect rect = fTestButton->Frame();
	rect.OffsetBy(rect.Width() + 10.0,0.0);
	
	// Find the longest name in all the modes
	BMessage modes;
	RuleRunner::GetModes(modes);
	i = 0;
	while (modes.FindString("modes",i,&teststr) == B_OK)
	{
		i++;
		if (teststr.CountChars() > widestmode.CountChars())
			widestmode = teststr;
	}
	
	fModeButton = new BButton(rect,"modebutton",widestmode.String(),
								new BMessage(M_SHOW_MODE_MENU));
	fModeButton->ResizeToPreferred();
	AddChild(fModeButton);
	
	rect = fModeButton->Frame();
	rect.OffsetBy(rect.Width() + 5,0);
	rect.right = rect.left + StringWidth("application/x-vnd.dw-foo") + 5;
	fValueBox = new AutoTextControl(rect,"valuebox",NULL,NULL,
									new BMessage(M_VALUE_CHANGED),
									B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP);
	AddChild(fValueBox);
	fValueBox->SetDivider(0);
	if (fValueBox->Bounds().Height() < fModeButton->Bounds().Height())
		fValueBox->MoveBy(0.0,(fModeButton->Bounds().Height() - fValueBox->Bounds().Height()) / 2.0);
	

	SetupTestMenu();
		
	bool usedefaults = false;
	if (test)
	{
		STRACE(("\nTestView::TestView: test parameter\n"));
		MSGTRACE(test);
		
		fTest = new BMessage(*test);
		BString str;
		
		if (!SetTest(fTest))
			usedefaults = true;
		
		if (fTest->FindString("mode",&str) == B_OK)
			SetMode(str.String());
		else
		{
			fTest->FindString("name",&str);
			modes.MakeEmpty();
			RuleRunner::GetCompatibleModes(str.String(),modes);
			modes.FindString("modes",0,&str);
			SetMode(str.String());
		}
		
		if (fTest->FindString("value",&str) == B_OK)
			fValueBox->SetText(str.String());
	}
	else
		usedefaults = true;
	
	if (usedefaults)
	{
		if (!fTest)
			fTest = new BMessage;
		
		BString str;
		fTestTypes.FindString("tests",0,&str);
		
		BMessage newtest;
		newtest.AddString("name",str);
		
		modes.MakeEmpty();
		RuleRunner::GetCompatibleModes(str.String(),modes);
		modes.FindString("modes",0,&str);
		
		newtest.AddString("mode",str);
		newtest.AddString("value","");
		
		SetTest(&newtest);
		SetMode(str.String());
	}
}