C++ OK204-25-USB writing text issue
Posted: Fri Apr 26, 2019 7:04 am
Hello,
I just picked up my first character display and I'm having a few issues displaying characters on it. So first off, using the hello, world sample code it is working mostly fine. I get a weird character at the very end of the string that I didn't enter. attached photo helloworldchar.jpg
The bigger issue I'm having is the C++ code I'm writing and having issues sending text to the display.
So I have three files. A header and source file that contains a bunch of functions that call the different commands listed in the Manual. For instance.
And the third file is just a main method test class to test the Character_Display class I created. I want to make the calls portable to different projects I'm working on.
so when I create an object of the Character_Display class in the constructor is where I create my connection to the USB port and set the attributes.
I have a function that is simply writeToDisplay() that takes in a unsigned char array, and writes it to the display.
however, the text on the display doesn't make sense. check image texterror.jpg
what I'm doing is as follows.
main method
This is obviously an issue with my c++ abilities, as if I create an new message from within the writeToDisplay() function it works just fine. Its something to do with how I'm passing the value to the function. I just can't seem to figure it out.
I just picked up my first character display and I'm having a few issues displaying characters on it. So first off, using the hello, world sample code it is working mostly fine. I get a weird character at the very end of the string that I didn't enter. attached photo helloworldchar.jpg
The bigger issue I'm having is the C++ code I'm writing and having issues sending text to the display.
So I have three files. A header and source file that contains a bunch of functions that call the different commands listed in the Manual. For instance.
Code: Select all
void setAutoScroll (int state = 0); // state 0 = off, 1 = on
void ClearScreen ();
void changeStartupScreen (char data);
void setAutoLineWrap (int state = 0); // state 0 = off, 1 = on
void setCursorPosition (int col = 0, int row = 0);
void goHome ();
void moveCursor (int state, int positions = 0); // state 0 = off, 1 = on, positions = number of positions to move
void underlineCursor (int state); // state 0 = off, 1 = on
void blinkingCursor (int state); // state 0 = off, 1 = on
so when I create an object of the Character_Display class in the constructor is where I create my connection to the USB port and set the attributes.
I have a function that is simply writeToDisplay() that takes in a unsigned char array, and writes it to the display.
Code: Select all
void Character_Display::writeToDisplay (unsigned char mesg[])
{
if (!WriteFile (my_port, &mesg, sizeof (mesg), &bytes_written, NULL)) //Write message
{
std::cout << "Error writing message to display!" << std::endl; //Check for errors in writing, call GetLastError with the int response for more info
}
}
what I'm doing is as follows.
main method
Code: Select all
Character_display cd; // create object
unsigned char message[] = "Test 1";
cd.ClearScreen();
cd.writeToScreen(message);