Exemplo n.º 1
0
RoboFocuser::RoboFocuser(void) {
	
	Ptr = this;
	char Message[160];

	this->Busy = false;
	if (!CheckIfComPortExists(ROBOFOCUSER_COM_PORT_NAME)) {
		sprintf_s(Message, sizeof(Message), "*** Warning - Serial Port for RoboFocuser: %s does not exist (RoboFocuser::RoboFocuser)\n",
			ROBOFOCUSER_COM_PORT_NAME);
		Form1::StatusPrint(Message);
		return;
	}
	this->ComPortName = gcnew String(ROBOFOCUSER_COM_PORT_NAME);
	this->ComPortPtr = gcnew SerialPort(ComPortName);
	this->ComPortPtr->Open();
	this->ComPortOpen = this->ComPortPtr->IsOpen;
	this->ErrMessageCount = 0;

	if (! this->ComPortOpen) {
		Form1::StatusPrint("*** Warning - Can't open RoboFocuser COM port (RoboFocuser)\n");
		return;
	}

	return;
}
Exemplo n.º 2
0
bool irtiny::CIRDriver::initPort()
{
    buffer_.clear();

    if (thread_.joinable())
    {
        finishEvent_.setEvent();
        thread_.join();
    }

    Settings settings;
    settings.load();

    SerialPort serialPort = SerialPort(settings.port());
    if (!serialPort)
        return false;

    DCB dcb = { 0 };

    // The device is powered by RTS
    // and running at fixed baud rate.

    dcb.DCBlength = sizeof(dcb);
    dcb.BaudRate = CBR_115200;
    dcb.fBinary = TRUE;
    dcb.fRtsControl = RTS_CONTROL_ENABLE;
    dcb.ByteSize = 8;
    dcb.Parity = NOPARITY;
    dcb.StopBits = ONESTOPBIT;

    if (!SetCommState(serialPort.get(), &dcb))
        return false;

    PurgeComm(serialPort.get(), PURGE_RXABORT | PURGE_RXCLEAR);
    ClearCommError(serialPort.get(), nullptr, nullptr);

    serialPort_ = std::move(serialPort);
    thread_ = std::thread([=]() { threadProc(); });

    return true;
}
Exemplo n.º 3
0
void Solver::toArduinoInterf(void)
{
	string answer;
	String^ portName;
	int baudRate = 9600;
	portName = "COM4";
	// arduino settings
	SerialPort^ arduino;
	arduino = gcnew SerialPort(portName, baudRate);
	// open port
	try
	{
		arduino->Open();

		int i;
		for (i = 0; i < solutionLength1; i++)
		{
			// Get move
			answer = Cube::NameOfMove(TranslateMove(solutionMoves1[i], solutionPowers1[i], 0));
			// Parse to a,b,c,...r
			arduino->WriteLine(arduinoParser(answer));
			// Wait for arduino to return 1
			while (arduino->ReadLine() != "1") {}
		}
		for (i = 0; i < solutionLength2; i++)
		{
			answer = Cube::NameOfMove(TranslateMove(solutionMoves2[i], solutionPowers2[i], 1));
			arduino->WriteLine(arduinoParser(answer));
			while (arduino->ReadLine() != "1") {}
		}
		// close port to arduino
		arduino->Close();
	}
	catch (IO::IOException^ e)
	{
		Console::WriteLine(e->GetType()->Name + ": Port is not ready");
	}
	catch (ArgumentException^ e)
Exemplo n.º 4
0
// Receiving header information
char _header[6];

// Reception state machine control and storage variables
unsigned char _recPhase;
unsigned char _recPos;
unsigned char _recCommand;
unsigned char _recLen;
unsigned char _recStation;
unsigned char _recSender;
unsigned char _recCS;
unsigned char _recCalcCS;


#if defined(__linux__)
SerialPort _dev = SerialPort(MY_RS485_HWSERIAL);
#elif defined(MY_RS485_HWSERIAL)
HardwareSerial& _dev = MY_RS485_HWSERIAL;
#else
AltSoftSerial _dev;
#endif

unsigned char _nodeId;
char _data[MY_RS485_MAX_MESSAGE_LENGTH];
uint8_t _packet_len;
unsigned char _packet_from;
bool _packet_received;

// Packet wrapping characters, defined in standard ASCII table
#define SOH 1
#define STX 2