-1

i need a little help with my coding.. see the coding below is used if we were to write a string and send through a com port.. what if we were to generate random strings and send it through a com port.. what do i actually have to change in the "this->serialPort1->WriteLine(message);" ? tried several codes from google.. none of them are working

private: System::Void button4_Click(System::Object^  sender, System::EventArgs^  e) {

            //add sender name
             String^ name = this->serialPort1->PortName;

             // grab text and store in send buffer
             String^ message = this->textBox2->Text;

             // write to serial
             if(this->serialPort1->IsOpen)

            //this->_serialPort->WriteLine(String::Format("<{0}>: {1}",name,message));
                this->serialPort1->WriteLine(message);
             else
                this->textBox2->Text="Port Not Opened";


     }

1 Answers1

0

//Sorry for the bad format. Must learn how to use it correctly.
void createRandom(std::string & randString, const int len)
{

    static const std::string theCharacters =  "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";

    for (int i = 0; i < len; ++i) 
    {
        //generate a random number which not bigger that max size of the available characters, then add it to the string.
        randString += theCharacters[rand() % (sizeof(theCharacters) - 1)];
    }
}
createRandom(message);
this->serialPort1->WriteLine(message);
Maarten Bamelis
  • 2,243
  • 19
  • 32