Torna al Thread

[CODE]// sendPacket.cpp : file di progetto principale. //initialize command data structure to send struct SCIENTIFIC_COMMANDDATA { //always 0x17 unsigned char packetdescriptor; //pitch, roll, thrust, yaw commands. 0..4095 2048=middle unsigned short pitch; unsigned short roll; unsigned short thrust; unsigned short yaw; //flags //Bit 0(0x01): Pitch control through serial interfacae enabled //Bit 1(0x02): Roll control through serial interface enabled //Bit 2(0x04): Thrust control through serial interface enabled //Bit 3(0x08): Yaw control through serial interface enabled //Bit 4(0x10): ACC-Mode on/off //Bit 5(0x20): Height control - on/off (only with ACC) //Bit 6(0x40): overwrite ACC/Height mode control //(0=mode selected by RC 1=mode selected by Bit 4 and 5) //Bit 7(0x17): Trigger Scientific status packet (triggers a response //with the actual scientific state) //Bit 8..15: sendrate of the scientific packet in 5Hz //(0=off;1=5Hz, 20=100Hz, 200=1kHz) //Scientific packet is send for three seconds max. //after the last command_data packet FLAGS flags; //insert a FLAG structure in a SCIENTIFIC_COMMANDDATA }; //send-data methods void sendData_String(array<unsigned char> ^ send_data) { StringComparer^ stringComparer = StringComparer::OrdinalIgnoreCase; // Create a new SerialPort object with default settings. SerialPort^ _serialPort = gcnew SerialPort("COM3"); // Allow the user to set the appropriate properties. _serialPort->BaudRate = 57600 ; _serialPort->Parity = Parity::None; _serialPort->DataBits = 8; _serialPort->StopBits = StopBits::One; _serialPort->Handshake =Handshake::None; //variables array<unsigned char> ^ received_data =gcnew array<unsigned char>(50); //open-send-close port _serialPort->Open(); while(!_kbhit()) { printf("\nsending data...\n"); for(int ii=0;ii<=send_data->Length;ii++) { Thread::Sleep(50); _serialPort->Write(send_data,ii,1); printf("%d", send_data[ii]); Thread::Sleep(50); } printf("\nreceiving data...\n"); for (int ii=0;ii<=received_data->Length; ii++) { _serialPort->Read(received_data,ii,1); printf("%d", received_data[ii]); }; } _serialPort->Close(); } //MAIN int main(array<System::String ^> ^args) { //data to be sent array<unsigned char> ^ send_data = {startString[0], //1 startString[1], //2 startString[2], //3 length_high,//4 length_low,//5 scientific_commanddata.packetdescriptor,//6 scientific_commanddata.pitch&0xFF,//7 scientific_commanddata.pitch>>8,//8 scientific_commanddata.roll&0xFF,//9 scientific_commanddata.roll>>8,//10 scientific_commanddata.thrust&0xFF,//11 scientific_commanddata.thrust>>8,//12 scientific_commanddata.yaw&0xFF,//13 scientific_commanddata.yaw>>8,//14 flags_low,//15 flags_high,//16 crc_high,//17 crc_low};//18 //some string catched from testsoftware array<unsigned char> ^ send_data1 = {72, 0x43, 0x43, 0x00, 0x0B, 0x17, 0xF0, 0x07, 76, 0x07, 0x00, 0x00, 0xF0, 0x07, 0x8C, 0x04, 0x79, 0}; array <unsigned char> ^send_data2 = {0x3E, 0x2A, 0x3E, 0x00, 0x0B, 0x17, 0xF0, 0x07, 0xF0, 0x07, 0x00, 0x00, 0xF0, 0x07, 0x00, 0x04, 0x5C, 0x3F}; array <unsigned char> ^send_data3 = {0x3E, 0x2A, 0x3E, 0x00, 0x0B, 0x17, 0xF0, 0x07, 0xF0, 0x07, 0x00, 0x00, 0xF0, 0x07, 0x80, 0x04, 0xD0, 0xF3}; array <unsigned char> ^send_data4 = {0x3E, 0x2A, 0x3E, 0x00, 0x0B, 0x17, 0x50, 0x09, 0xF0, 0x07, 0x00, 0x00, 0xF0, 0x07, 0x00, 0x04, 0x89, 0xA9}; array<unsigned char> ^ send_data5 = {0x3E, 0x2A, 0x3E, 0x00, 0x0B, 0x80, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x50, 0xFF, 0x79, 0x53}; //launch methods sendData_String(send_data); return 0; }[/CODE]
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5